third-platform-sdk/platform/zhetaoke/api.go
yanfan d3e3119c14 京东联盟
折淘客
2025-05-15 17:59:51 +08:00

64 lines
1.8 KiB
Go

package zhetaoke
import (
"encoding/json"
"fmt"
"github.com/zeromicro/go-zero/core/logx"
"repository.lenntc.com/lenntc/third-platform-sdk/client"
)
// ZheTaoKeApi 折淘客
type ZheTaoKeApi interface {
// PromotionLink 转链
PromotionLink(PromotionLinkRequest) (*PromotionLinkResponse, error)
}
type zheTaoKeApiImpl struct {
log logx.Logger
client *Client
}
func newZheTaoKeApiImpl(log logx.Logger, client *Client) ZheTaoKeApi {
return &zheTaoKeApiImpl{
log: log,
client: client,
}
}
// 转链
func (z *zheTaoKeApiImpl) PromotionLink(req PromotionLinkRequest) (*PromotionLinkResponse, error) {
params := map[string]any{
"appkey": z.client.authConfig.AppKey,
"unionId": z.client.authConfig.UnionId,
"materialId": req.MaterialId,
"chainType": req.ChainType,
}
if req.PositionId > 0 {
params["positionId"] = req.PositionId
}
request := &client.HttpRequest{Headers: z.client.headers, QueryArgs: params}
response := new(JdUnionOpenPromotionByunionidGetResponse)
if err := z.client.HttpPost(PromotionLinkUrl, request, &client.HttpResponse{Result: response}); err != nil {
return nil, err
}
if response == nil {
return nil, nil
}
if response.Content != "" {
return nil, fmt.Errorf("折淘客-京东联盟 转链接口失败:[%d]%s", response.Status, response.Content)
}
if response.JdUnionOpenPromotionByunionidGetResponse == nil {
return nil, nil
}
if response.JdUnionOpenPromotionByunionidGetResponse.Result == "" {
return nil, nil
}
resp := new(PromotionLinkResponse)
err := json.Unmarshal([]byte(response.JdUnionOpenPromotionByunionidGetResponse.Result), &resp)
if err != nil {
return nil, fmt.Errorf("折淘客-京东联盟 转链接口响应结果解析失败,错误信息:%s", err.Error())
}
return resp, nil
}