52 lines
1.6 KiB
Go
52 lines
1.6 KiB
Go
package zjdg
|
||
|
||
import (
|
||
"context"
|
||
"fmt"
|
||
"github.com/zeromicro/go-zero/core/logx"
|
||
"repository.lenntc.com/lenntc/third-platform-sdk/client"
|
||
"repository.lenntc.com/lenntc/third-platform-sdk/util"
|
||
)
|
||
|
||
// ZjdgApi 中捷乐淘-淘宝一分购
|
||
type ZjdgApi interface {
|
||
// ZoneAdd 获取推广编号-创建
|
||
ZoneAdd(ctx context.Context, req ZoneAddRequest) (*ZoneAddResponse, error)
|
||
// GenerateH5Url 生成H5链接
|
||
GenerateH5Url(ctx context.Context, req GenerateH5UrlRequest) (string, error)
|
||
}
|
||
type zjdgApiImpl struct {
|
||
log logx.Logger
|
||
client *Client
|
||
}
|
||
|
||
func newZjdgApiImpl(log logx.Logger, client *Client) ZjdgApi {
|
||
return &zjdgApiImpl{
|
||
log: log,
|
||
client: client,
|
||
}
|
||
}
|
||
|
||
// ZoneAdd 获取推广编号
|
||
func (a *zjdgApiImpl) ZoneAdd(ctx context.Context, req ZoneAddRequest) (*ZoneAddResponse, error) {
|
||
// 响应示例 {"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
|
||
}
|
||
|
||
func (a *zjdgApiImpl) GenerateH5Url(ctx context.Context, req GenerateH5UrlRequest) (string, error) {
|
||
promotionUrl := fmt.Sprintf(PromotionUrl, req.Sid, a.client.authConfig.UserId)
|
||
return promotionUrl, nil
|
||
}
|