2025-02-24 16:51:08 +08:00
|
|
|
|
package zjdg
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
2025-02-24 17:54:14 +08:00
|
|
|
|
"context"
|
2025-02-24 18:13:25 +08:00
|
|
|
|
"errors"
|
2025-02-24 16:51:08 +08:00
|
|
|
|
"fmt"
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
2025-02-24 18:13:25 +08:00
|
|
|
|
"net/url"
|
2025-02-24 16:51:08 +08:00
|
|
|
|
"repository.lenntc.com/lenntc/third-platform-sdk/client"
|
|
|
|
|
|
"repository.lenntc.com/lenntc/third-platform-sdk/util"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// ZjdgApi 中捷乐淘-淘宝一分购
|
|
|
|
|
|
type ZjdgApi interface {
|
|
|
|
|
|
// ZoneAdd 获取推广编号-创建
|
2025-02-24 17:54:14 +08:00
|
|
|
|
ZoneAdd(ctx context.Context, req ZoneAddRequest) (*ZoneAddResponse, error)
|
|
|
|
|
|
// GenerateH5Url 生成H5链接
|
|
|
|
|
|
GenerateH5Url(ctx context.Context, req GenerateH5UrlRequest) (string, error)
|
2025-02-24 16:51:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
type zjdgApiImpl struct {
|
|
|
|
|
|
log logx.Logger
|
|
|
|
|
|
client *Client
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func newZjdgApiImpl(log logx.Logger, client *Client) ZjdgApi {
|
|
|
|
|
|
return &zjdgApiImpl{
|
|
|
|
|
|
log: log,
|
|
|
|
|
|
client: client,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ZoneAdd 获取推广编号
|
2025-02-24 17:54:14 +08:00
|
|
|
|
func (a *zjdgApiImpl) ZoneAdd(ctx context.Context, req ZoneAddRequest) (*ZoneAddResponse, error) {
|
2025-02-24 16:51:08 +08:00
|
|
|
|
// 响应示例 {"code":0,"message":"获取成功","data":"1963667","token_id":""}
|
|
|
|
|
|
zoneAddUrl := fmt.Sprintf("%s%s", ZoneAddUrl, a.client.authConfig.UserId)
|
|
|
|
|
|
args := util.StructToMap(req)
|
|
|
|
|
|
request := &client.HttpRequest{Headers: a.client.headers, QueryArgs: args}
|
|
|
|
|
|
response := new(ZoneAddOriginResponse)
|
|
|
|
|
|
if err := a.client.HttpGet(zoneAddUrl, request, &client.HttpResponse{Result: response}); err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
if response.Code != 0 {
|
|
|
|
|
|
return nil, fmt.Errorf("获取推广编号失败,返回Code=%d", response.Code)
|
|
|
|
|
|
}
|
|
|
|
|
|
return &ZoneAddResponse{
|
|
|
|
|
|
AdZoneId: response.Data,
|
|
|
|
|
|
}, nil
|
|
|
|
|
|
}
|
2025-02-24 17:54:14 +08:00
|
|
|
|
|
|
|
|
|
|
func (a *zjdgApiImpl) GenerateH5Url(ctx context.Context, req GenerateH5UrlRequest) (string, error) {
|
2025-02-24 18:13:25 +08:00
|
|
|
|
u, err := url.Parse(req.ActivityUrl)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return "", errors.New("activityUrl不是一个url")
|
|
|
|
|
|
}
|
|
|
|
|
|
urlParams := u.Query()
|
|
|
|
|
|
for key, item := range urlParams {
|
|
|
|
|
|
if key == "adzoneid" {
|
|
|
|
|
|
urlParams.Set("adzoneid", req.Sid)
|
|
|
|
|
|
} else if key == "userid" {
|
|
|
|
|
|
urlParams.Set("userid", a.client.authConfig.UserId)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if len(item) > 0 {
|
|
|
|
|
|
urlParams.Set(key, item[0])
|
|
|
|
|
|
} else {
|
|
|
|
|
|
urlParams.Set(key, "")
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
fmt.Println(fmt.Sprintf("key=%s,val=%s,len=%d", key, item, len(item)))
|
|
|
|
|
|
}
|
|
|
|
|
|
u.RawQuery = urlParams.Encode()
|
|
|
|
|
|
|
|
|
|
|
|
return u.String(), nil
|
2025-02-24 17:54:14 +08:00
|
|
|
|
}
|