京东联盟
折淘客
This commit is contained in:
parent
338411e6ee
commit
d3e3119c14
12
index.go
12
index.go
@ -2,6 +2,8 @@ package third_platform_sdk
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
jd_union "repository.lenntc.com/lenntc/third-platform-sdk/platform/jd-union"
|
||||
"repository.lenntc.com/lenntc/third-platform-sdk/platform/zhetaoke"
|
||||
"repository.lenntc.com/lenntc/third-platform-sdk/platform/zjdg"
|
||||
|
||||
"repository.lenntc.com/lenntc/third-platform-sdk/platform/fliggy"
|
||||
@ -135,3 +137,13 @@ func NewMeituanApi(log logx.Logger, conf meituan.AuthConfig) meituan.MeituanApi
|
||||
func NewZjdgApi(log logx.Logger, conf zjdg.AuthConfig) zjdg.ZjdgApi {
|
||||
return zjdg.NewApiClient(log, conf)
|
||||
}
|
||||
|
||||
// NewJdUnion 京东联盟
|
||||
func NewJdUnion(log logx.Logger, conf jd_union.AuthConfig) jd_union.JdUnionApi {
|
||||
return jd_union.NewApiClient(log, conf)
|
||||
}
|
||||
|
||||
// NewZheTaoKe 折淘客
|
||||
func NewZheTaoKe(log logx.Logger, conf zhetaoke.AuthConfig) zhetaoke.ZheTaoKeApi {
|
||||
return zhetaoke.NewApiClient(log, conf)
|
||||
}
|
||||
|
||||
@ -27,8 +27,8 @@ func TestApiClient(t *testing.T) {
|
||||
func (a *apiClientSuite) SetupSuite() {
|
||||
log := logx.WithContext(context.Background())
|
||||
apiClient := NewApiClient(log, AuthConfig{
|
||||
AppKey: "",
|
||||
AppSecret: "",
|
||||
AppKey: "34632005",
|
||||
AppSecret: "b0e6b6654825e6124f743b2528be95d7",
|
||||
})
|
||||
a.api = apiClient
|
||||
}
|
||||
@ -55,7 +55,7 @@ func (a *apiClientSuite) Test_Sign() {
|
||||
func (a *apiClientSuite) Test_KbItemPromotionShareCreate() {
|
||||
req := &request.AlibabaAlscUnionKbItemPromotionShareCreateRequest{
|
||||
Pid: pointer.String("alsc_23378482_4796002_21291126"),
|
||||
ItemId: pointer.String("10645"),
|
||||
ItemId: pointer.String("10144"),
|
||||
Sid: pointer.String("10001zdt100004"),
|
||||
}
|
||||
resp, err := a.api.KbItemPromotionShareCreate(req)
|
||||
@ -70,7 +70,7 @@ func (a *apiClientSuite) Test_ElemePromotionOfficialActivityGet() {
|
||||
req := &request.AlibabaAlscUnionElemePromotionOfficialactivityGetRequest{
|
||||
QueryRequest: &domain.AlibabaAlscUnionElemePromotionOfficialactivityGetActivityRequest{
|
||||
Pid: pointer.String("alsc_23378482_4796002_15513017"),
|
||||
ActivityId: pointer.String("10645"),
|
||||
ActivityId: pointer.String("10144"),
|
||||
Sid: pointer.String("10001zdt100004"),
|
||||
},
|
||||
}
|
||||
|
||||
171
platform/jd-union/api.go
Normal file
171
platform/jd-union/api.go
Normal file
@ -0,0 +1,171 @@
|
||||
package jd_union
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/spf13/cast"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"repository.lenntc.com/lenntc/third-platform-sdk/client"
|
||||
"repository.lenntc.com/lenntc/third-platform-sdk/util"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// JdUnionApi 京东联盟平台
|
||||
type JdUnionApi interface {
|
||||
// Sign 签名
|
||||
Sign(data map[string]interface{}) string
|
||||
// QueryOrderList 查询订单列表
|
||||
QueryOrderList(req QueryOrderListRequest) (*QueryOrderListResponse, error)
|
||||
// PromotionLink 转链
|
||||
PromotionLink(PromotionLinkRequest) (*PromotionLinkResponse, error)
|
||||
}
|
||||
|
||||
type jdUnionApiImpl struct {
|
||||
log logx.Logger
|
||||
client *Client
|
||||
params map[string]any
|
||||
}
|
||||
|
||||
func newJdUnionApiImpl(log logx.Logger, client *Client) JdUnionApi {
|
||||
return &jdUnionApiImpl{
|
||||
log: log,
|
||||
client: client,
|
||||
params: map[string]any{
|
||||
"method": "",
|
||||
"access_token": "",
|
||||
"app_key": client.authConfig.AppKey,
|
||||
"sign_method": SignMethod,
|
||||
"timestamp": time.Now().Format(time.DateTime),
|
||||
"360buy_param_json": "",
|
||||
"v": Version,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (t *jdUnionApiImpl) Sign(data map[string]any) string {
|
||||
// key排序
|
||||
arr := sort.StringSlice{}
|
||||
for k := range data {
|
||||
if k == "sign" {
|
||||
continue
|
||||
}
|
||||
arr = append(arr, k)
|
||||
}
|
||||
arr.Sort()
|
||||
// 参数拼接
|
||||
var build strings.Builder
|
||||
build.WriteString(t.client.authConfig.AppSecret)
|
||||
for _, k := range arr {
|
||||
build.WriteString(fmt.Sprintf("%s%v", k, data[k]))
|
||||
}
|
||||
build.WriteString(t.client.authConfig.AppSecret)
|
||||
return strings.ToUpper(util.Md5String(build.String()))
|
||||
}
|
||||
|
||||
func (t *jdUnionApiImpl) QueryOrderList(req QueryOrderListRequest) (*QueryOrderListResponse, error) {
|
||||
params := make(map[string]any)
|
||||
if req.OrderId != "" {
|
||||
params["orderId"] = req.OrderId
|
||||
} else {
|
||||
params["pageIndex"] = req.PageIndex
|
||||
params["pageSize"] = req.PageSize
|
||||
params["type"] = req.Type
|
||||
params["startTime"] = req.StartTime
|
||||
params["endTime"] = req.EndTime
|
||||
}
|
||||
requestPrams := map[string]any{
|
||||
"orderReq": params,
|
||||
}
|
||||
paramsJson, _ := json.Marshal(requestPrams)
|
||||
|
||||
SystemParams := t.params
|
||||
SystemParams["method"] = QueryOrderListMethod
|
||||
SystemParams["360buy_param_json"] = string(paramsJson)
|
||||
SystemParams["sign"] = t.Sign(SystemParams)
|
||||
|
||||
//values := url.Values{}
|
||||
//for key, value := range SystemParams {
|
||||
// values.Set(key, cast.ToString(value))
|
||||
//}
|
||||
//fmt.Println(fmt.Sprintf("%s?%s", BaseUrl, values.Encode()))
|
||||
|
||||
requestUrl := BaseUrl
|
||||
request := &client.HttpRequest{Headers: t.client.headers, QueryArgs: SystemParams}
|
||||
response := new(JdUnionOpenOrderRowQueryResponse)
|
||||
if err := t.client.HttpPost(requestUrl, request, &client.HttpResponse{Result: response}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if response == nil {
|
||||
return nil, nil
|
||||
}
|
||||
if response.ErrorResponse != nil {
|
||||
return nil, fmt.Errorf("京东联盟请求订单接口响应错误,Code[%s],请求ID[%s],错误信息:%s", response.ErrorResponse.Code, response.ErrorResponse.RequestId, response.ErrorResponse.ZhDesc)
|
||||
}
|
||||
if response.JdUnionOpenOrderRowQueryResponse == nil {
|
||||
return nil, nil
|
||||
}
|
||||
if cast.ToInt64(response.JdUnionOpenOrderRowQueryResponse.Code) != 0 {
|
||||
return nil, nil
|
||||
}
|
||||
resp := new(QueryOrderListResponse)
|
||||
err := json.Unmarshal([]byte(response.JdUnionOpenOrderRowQueryResponse.QueryResult), resp)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("京东联盟请求订单接口解析QueryResult失败,错误信息:%s", err.Error())
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// 转链
|
||||
func (t *jdUnionApiImpl) PromotionLink(req PromotionLinkRequest) (*PromotionLinkResponse, error) {
|
||||
params := map[string]any{
|
||||
"materialId": req.MaterialId,
|
||||
"positionId": req.PositionId,
|
||||
"siteId": req.SiteId,
|
||||
}
|
||||
if req.PositionId > 0 {
|
||||
params["positionId"] = req.PositionId
|
||||
}
|
||||
requestPrams := map[string]any{
|
||||
"promotionCodeReq": params,
|
||||
}
|
||||
paramsJson, _ := json.Marshal(requestPrams)
|
||||
|
||||
SystemParams := t.params
|
||||
SystemParams["method"] = PromotionLinkMethod
|
||||
SystemParams["360buy_param_json"] = string(paramsJson)
|
||||
SystemParams["sign"] = t.Sign(SystemParams)
|
||||
|
||||
//values := url.Values{}
|
||||
//for key, value := range SystemParams {
|
||||
// values.Set(key, cast.ToString(value))
|
||||
//}
|
||||
//fmt.Println(fmt.Sprintf("%s?%s", BaseUrl, values.Encode()))
|
||||
|
||||
requestUrl := BaseUrl
|
||||
request := &client.HttpRequest{Headers: t.client.headers, QueryArgs: SystemParams}
|
||||
response := new(JdUnionOpenPromotionCommonGetResponse)
|
||||
if err := t.client.HttpPost(requestUrl, request, &client.HttpResponse{Result: response}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if response == nil {
|
||||
return nil, nil
|
||||
}
|
||||
if response.ErrorResponse != nil {
|
||||
return nil, fmt.Errorf("京东联盟请求转链接口响应错误,Code[%s],请求ID[%s],错误信息:%s", response.ErrorResponse.Code, response.ErrorResponse.RequestId, response.ErrorResponse.ZhDesc)
|
||||
}
|
||||
if response.JdUnionOpenPromotionCommonGetResponse == nil {
|
||||
return nil, nil
|
||||
}
|
||||
if cast.ToInt64(response.JdUnionOpenPromotionCommonGetResponse.Code) != 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
resp := new(PromotionLinkResponse)
|
||||
err := json.Unmarshal([]byte(response.JdUnionOpenPromotionCommonGetResponse.GetResult), resp)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("京东联盟请求转链接口解析GetResult失败,错误信息:%s", err.Error())
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
70
platform/jd-union/api_test.go
Normal file
70
platform/jd-union/api_test.go
Normal file
@ -0,0 +1,70 @@
|
||||
package jd_union
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
// api-单元测试
|
||||
type apiClientSuite struct {
|
||||
suite.Suite
|
||||
api JdUnionApi
|
||||
}
|
||||
|
||||
func TestApiClient(t *testing.T) {
|
||||
suite.Run(t, new(apiClientSuite))
|
||||
}
|
||||
|
||||
func (a *apiClientSuite) SetupSuite() {
|
||||
log := logx.WithContext(context.Background())
|
||||
apiClient := NewApiClient(log, AuthConfig{
|
||||
AppKey: "",
|
||||
AppSecret: "",
|
||||
})
|
||||
a.api = apiClient
|
||||
}
|
||||
|
||||
func (a *apiClientSuite) Test_QueryOrderList() {
|
||||
data := QueryOrderListRequest{
|
||||
PageIndex: 1,
|
||||
PageSize: 20,
|
||||
Type: 1, //订单时间查询类型(1:下单时间,2:完成时间(购买用户确认收货时间),3:更新时间
|
||||
StartTime: "2025-05-14 17:00:00",
|
||||
EndTime: "2025-05-14 18:00:00",
|
||||
}
|
||||
resp, err := a.api.QueryOrderList(data)
|
||||
if err != nil {
|
||||
a.T().Errorf("=====[Test_QueryOrderList] err: %v", err)
|
||||
}
|
||||
if resp != nil {
|
||||
a.T().Logf("=====[Test_QueryOrderList] resp: %+v, err: %v", resp, err)
|
||||
if len(resp.Data) > 0 {
|
||||
for _, v := range resp.Data {
|
||||
va, _ := json.Marshal(v)
|
||||
fmt.Println(string(va))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (a *apiClientSuite) Test_PromotionLink() {
|
||||
data := PromotionLinkRequest{
|
||||
MaterialId: "https://u.jd.com/rDPUXnL",
|
||||
SiteId: "",
|
||||
PositionId: 100030093812,
|
||||
}
|
||||
resp, err := a.api.PromotionLink(data)
|
||||
if err != nil {
|
||||
a.T().Errorf("=====[Test_PromotionLink] err: %v", err)
|
||||
}
|
||||
a.T().Logf("=====[Test_PromotionLink] resp: %+v, err: %v", resp, err)
|
||||
if resp != nil {
|
||||
va, _ := json.Marshal(resp.Data)
|
||||
fmt.Println(string(va))
|
||||
}
|
||||
}
|
||||
37
platform/jd-union/client.go
Normal file
37
platform/jd-union/client.go
Normal file
@ -0,0 +1,37 @@
|
||||
package jd_union
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
|
||||
"repository.lenntc.com/lenntc/third-platform-sdk/client"
|
||||
)
|
||||
|
||||
// AuthConfig api鉴权参数
|
||||
type AuthConfig struct {
|
||||
AppKey string
|
||||
AppSecret string
|
||||
}
|
||||
|
||||
// 连接第三方平台的client
|
||||
type Client struct {
|
||||
log logx.Logger
|
||||
authConfig AuthConfig
|
||||
client.HttpClient
|
||||
headers map[string]string
|
||||
}
|
||||
|
||||
func NewApiClient(log logx.Logger, conf AuthConfig) JdUnionApi {
|
||||
clt := newClient(log, conf)
|
||||
return newJdUnionApiImpl(log, clt)
|
||||
}
|
||||
|
||||
func newClient(log logx.Logger, conf AuthConfig) *Client {
|
||||
return &Client{
|
||||
log: log,
|
||||
authConfig: conf,
|
||||
HttpClient: client.NewHttpClient(log),
|
||||
headers: map[string]string{
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}
|
||||
}
|
||||
12
platform/jd-union/consts.go
Normal file
12
platform/jd-union/consts.go
Normal file
@ -0,0 +1,12 @@
|
||||
package jd_union
|
||||
|
||||
const (
|
||||
Version = "1.0"
|
||||
Format = "json"
|
||||
JsonParamKey = "360buy_param_json"
|
||||
SignMethod = "md5"
|
||||
|
||||
BaseUrl = "https://api.jd.com/routerjson"
|
||||
QueryOrderListMethod = "jd.union.open.order.row.query"
|
||||
PromotionLinkMethod = "jd.union.open.promotion.common.get"
|
||||
)
|
||||
121
platform/jd-union/types.go
Normal file
121
platform/jd-union/types.go
Normal file
@ -0,0 +1,121 @@
|
||||
package jd_union
|
||||
|
||||
type QueryOrderListRequest struct {
|
||||
OrderId string `json:"orderId"` //订单号,当orderId不为空时,其他参数非必填
|
||||
PageIndex int64 `json:"pageIndex"` //页码
|
||||
PageSize int64 `json:"pageSize"` //每页包含条数,上限为200
|
||||
Type int64 `json:"type"` //订单时间查询类型(1:下单时间,2:完成时间(购买用户确认收货时间),3:更新时间
|
||||
StartTime string `json:"startTime"` //开始时间 格式yyyy-MM-dd HH:mm:ss,与endTime间隔不超过1小时
|
||||
EndTime string `json:"endTime"` //结束时间 格式yyyy-MM-dd HH:mm:ss,与startTime间隔不超过1小时
|
||||
}
|
||||
type QueryOrderListResponse struct {
|
||||
Code int64 `json:"code"`
|
||||
Data []*QueryOrderListItem `json:"data"`
|
||||
HasMore bool `json:"hasMore"`
|
||||
Message string `json:"message"`
|
||||
RequestId string `json:"requestId"`
|
||||
}
|
||||
type QueryOrderListItem struct {
|
||||
Id string `json:"id"` //标记唯一订单行:订单+sku维度的唯一标识
|
||||
OrderId int64 `json:"orderId"` //订单号
|
||||
ParentId int64 `json:"parentId"` //主单的订单号:如一个订单拆成多个子订单时,原订单号会作为主单号,拆分的订单号为子单号存储在orderid中。若未发生拆单,该字段为0
|
||||
OrderTime string `json:"orderTime"` //下单时间,格式yyyy-MM-dd HH:mm:ss
|
||||
FinishTime string `json:"finishTime"` //完成时间(购买用户确认收货时间),格式yyyy-MM-dd HH:mm:ss
|
||||
ModifyTime string `json:"modifyTime"` //更新时间,格式yyyy-MM-dd HH:mm:ss
|
||||
OrderEmt int64 `json:"orderEmt"` //下单设备 1.pc 2.无线
|
||||
Plus int64 `json:"plus"` //下单用户是否为PLUS会员 0:否,1:是
|
||||
UnionId int64 `json:"unionId"` //推客ID
|
||||
SkuId int64 `json:"skuId"` //商品ID
|
||||
SkuName string `json:"skuName"` //商品名称
|
||||
SkuNum int64 `json:"skuNum"` //商品数量
|
||||
SkuReturnNum int64 `json:"skuReturnNum"` //商品已退货数量
|
||||
SkuFrozenNum int64 `json:"skuFrozenNum"` //商品售后中数量
|
||||
Price float64 `json:"price"` //商品单价
|
||||
CommissionRate float64 `json:"commissionRate"` //佣金比例(投放的广告主计划比例)
|
||||
SubSideRate float64 `json:"subSideRate"` //分成比例(单位:%)
|
||||
SubsidyRate float64 `json:"subsidyRate"` //补贴比例(单位:%)
|
||||
FinalRate float64 `json:"finalRate"` //最终分佣比例(单位:%)=分成比例+补贴比例
|
||||
EstimateCosPrice float64 `json:"estimateCosPrice"` //预估计佣金额
|
||||
EstimateFee float64 `json:"estimateFee"` //推客的预估佣金
|
||||
ActualCosPrice float64 `json:"actualCosPrice"` //实际计算佣金的金额
|
||||
ActualFee float64 `json:"actualFee"` //推客分得的实际佣金
|
||||
ValidCode int64 `json:"validCode"` //sku维度的有效码/状态((-1:未知,2.无效-拆单,3.无效-取消,4.无效-京东帮帮主订单,5.无效-账号异常,6.无效-赠品类目不返佣,7.无效-校园订单,8.无效-企业订单,9.无效-团购订单,11.无效-乡村推广员下单,13. 违规订单-其他,14.无效-来源与备案网址不符,15.待付款,16.已付款,17.已完成(购买用户确认收货),19.无效-佣金比例为0,20.无效-此复购订单对应的首购订单无效,21.无效-云店订单,22.无效-PLUS会员佣金比例为0,23.无效-支付有礼,24.已付定金,25. 违规订单-流量劫持,26. 违规订单-流量异常,27. 违规订单-违反京东平台规则,28. 违规订单-多笔交易异常,29.无效-跨屏跨店,30.无效-累计件数超出类目上限,31.无效-黑名单sku,33.超市卡充值订单,34.无效-推卡订单无效)
|
||||
PositionId int64 `json:"positionId"` //推广位ID
|
||||
SiteId int64 `json:"siteId"` //应用id(网站id、appid、社交媒体id、流量媒体id)
|
||||
Pid string `json:"pid"` //格式:子推客ID_子站长应用ID_子推客推广位ID
|
||||
SubUnionId string `json:"subUnionId"` //子渠道标识,在转链时可自定义传入,格式要求:字母、数字或下划线,最多支持80个字符(需要联系运营开放白名单才能拿到数据)
|
||||
PayMonth int64 `json:"payMonth"` //预估结算时间,订单完成后才会返回,格式:yyyyMMdd,默认:0
|
||||
//BalanceExt string `json:"balanceExt"` //下面的数据暂时用不到
|
||||
//CategoryInfo struct {
|
||||
// Cid1 int64 `json:"cid1"`
|
||||
// Cid2 int64 `json:"cid2"`
|
||||
// Cid3 int64 `json:"cid3"`
|
||||
//} `json:"categoryInfo"`
|
||||
//ChannelId int64 `json:"channelId"`
|
||||
//Cid1 int64 `json:"cid1"`
|
||||
//Cid2 int64 `json:"cid2"`
|
||||
//Cid3 int64 `json:"cid3"`
|
||||
//CpActId int64 `json:"cpActId"`
|
||||
//ExpressStatus int64 `json:"expressStatus"`
|
||||
//Ext1 string `json:"ext1"`
|
||||
//GiftCouponKey string `json:"giftCouponKey"`
|
||||
//GiftCouponOcsAmount int64 `json:"giftCouponOcsAmount"`
|
||||
//GoodsInfo struct {
|
||||
// MainSkuId int64 `json:"mainSkuId"`
|
||||
// ProductId int64 `json:"productId"`
|
||||
// ShopId int64 `json:"shopId"`
|
||||
//} `json:"goodsInfo"`
|
||||
//ItemId string `json:"itemId"`
|
||||
//OrderTag string `json:"orderTag"`
|
||||
//PopId int64 `json:"popId"`
|
||||
//ProPriceAmount int64 `json:"proPriceAmount"`
|
||||
//Rid int64 `json:"rid"`
|
||||
//SkuTag string `json:"skuTag"`
|
||||
//TraceType int64 `json:"traceType"`
|
||||
//UnionAlias string `json:"unionAlias"`
|
||||
//UnionRole int64 `json:"unionRole"`
|
||||
//UnionTag string `json:"unionTag"`
|
||||
}
|
||||
type JdUnionOpenOrderRowQueryResponse struct {
|
||||
JdUnionOpenOrderRowQueryResponse *JdUnionOpenOrderRowQuery `json:"jd_union_open_order_row_query_responce"`
|
||||
ErrorResponse *ErrorResponse `json:"error_response"`
|
||||
}
|
||||
type JdUnionOpenOrderRowQuery struct {
|
||||
Code string `json:"code"`
|
||||
QueryResult string `json:"queryResult"`
|
||||
}
|
||||
type ErrorResponse struct {
|
||||
Code string `json:"code"`
|
||||
ZhDesc string `json:"zh_desc"`
|
||||
EnDesc string `json:"en_desc"`
|
||||
RequestId string `json:"request_id"`
|
||||
}
|
||||
|
||||
// 转链
|
||||
type PromotionLinkRequest struct {
|
||||
MaterialId string `json:"materialId"` //推广物料url,例如活动链接、商品链接等;支持仅传入skuid
|
||||
SiteId string `json:"siteId"` //网站ID/媒体ID
|
||||
PositionId int64 `json:"positionId"` //自定义推广位id,自定义的数字,自己在本地跟用户做好关联,订单中会透出自定义的数字
|
||||
SubUnionId string `json:"subUnionId"` //子渠道标识 暂时没用 需要申请权限
|
||||
ChainType int64 `json:"chainType"` // 转链类型,1:长链, 2 :短链 ,3: 长链+短链,默认短链,短链有效期60天
|
||||
}
|
||||
|
||||
type PromotionLinkResponse struct {
|
||||
Code int64 `json:"code"` //200为成功,其他失败
|
||||
Data *PromotionLink `json:"data"`
|
||||
Message string `json:"message"`
|
||||
RequestId string `json:"request_id"`
|
||||
}
|
||||
type PromotionLink struct {
|
||||
ShortURL string `json:"shortUrl"` //短链
|
||||
ClickURL string `json:"clickUrl"` //长链接
|
||||
JCommand string `json:"jCommand"` //口令
|
||||
}
|
||||
type JdUnionOpenPromotionCommonGetResponse struct {
|
||||
JdUnionOpenPromotionCommonGetResponse *JdUnionOpenPromotionCommonGet `json:"jd_union_open_promotion_common_get_responce"`
|
||||
ErrorResponse *ErrorResponse `json:"error_response"`
|
||||
}
|
||||
type JdUnionOpenPromotionCommonGet struct {
|
||||
Code string `json:"code"`
|
||||
GetResult string `json:"getResult"`
|
||||
}
|
||||
63
platform/zhetaoke/api.go
Normal file
63
platform/zhetaoke/api.go
Normal file
@ -0,0 +1,63 @@
|
||||
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
|
||||
}
|
||||
48
platform/zhetaoke/api_test.go
Normal file
48
platform/zhetaoke/api_test.go
Normal file
@ -0,0 +1,48 @@
|
||||
package zhetaoke
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
// api-单元测试
|
||||
type apiClientSuite struct {
|
||||
suite.Suite
|
||||
api ZheTaoKeApi
|
||||
}
|
||||
|
||||
func TestApiClient(t *testing.T) {
|
||||
suite.Run(t, new(apiClientSuite))
|
||||
}
|
||||
|
||||
func (a *apiClientSuite) SetupSuite() {
|
||||
log := logx.WithContext(context.Background())
|
||||
apiClient := NewApiClient(log, AuthConfig{
|
||||
AppKey: "",
|
||||
UnionId: "",
|
||||
})
|
||||
a.api = apiClient
|
||||
}
|
||||
|
||||
func (a *apiClientSuite) Test_PromotionLink() {
|
||||
data := PromotionLinkRequest{
|
||||
MaterialId: "https://u.jd.com/rDPUXnL", //推广物料url,例如活动链接、商品链接等;支持仅传入skuid
|
||||
PositionId: 100343888999, //自定义推广位id,自定义的数字,自己在本地跟用户做好关联,订单中会透出自定义的数字
|
||||
ChainType: 3, // 转链类型,1:长链, 2 :短链 ,3: 长链+短链,默认短链,短链有效期60天
|
||||
}
|
||||
resp, err := a.api.PromotionLink(data)
|
||||
if err != nil {
|
||||
a.T().Errorf("=====[Test_PromotionLink] err: %v", err)
|
||||
}
|
||||
a.T().Logf("=====[Test_PromotionLink] resp: %+v, err: %v", resp, err)
|
||||
if resp != nil {
|
||||
va, _ := json.Marshal(resp.Data)
|
||||
fmt.Println(string(va))
|
||||
}
|
||||
|
||||
}
|
||||
37
platform/zhetaoke/client.go
Normal file
37
platform/zhetaoke/client.go
Normal file
@ -0,0 +1,37 @@
|
||||
package zhetaoke
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
|
||||
"repository.lenntc.com/lenntc/third-platform-sdk/client"
|
||||
)
|
||||
|
||||
// AuthConfig api鉴权参数
|
||||
type AuthConfig struct {
|
||||
UnionId string
|
||||
AppKey string
|
||||
}
|
||||
|
||||
// 连接第三方平台的client
|
||||
type Client struct {
|
||||
log logx.Logger
|
||||
authConfig AuthConfig
|
||||
client.HttpClient
|
||||
headers map[string]string
|
||||
}
|
||||
|
||||
func NewApiClient(log logx.Logger, conf AuthConfig) ZheTaoKeApi {
|
||||
clt := newClient(log, conf)
|
||||
return newZheTaoKeApiImpl(log, clt)
|
||||
}
|
||||
|
||||
func newClient(log logx.Logger, conf AuthConfig) *Client {
|
||||
return &Client{
|
||||
log: log,
|
||||
authConfig: conf,
|
||||
HttpClient: client.NewHttpClient(log),
|
||||
headers: map[string]string{
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}
|
||||
}
|
||||
5
platform/zhetaoke/consts.go
Normal file
5
platform/zhetaoke/consts.go
Normal file
@ -0,0 +1,5 @@
|
||||
package zhetaoke
|
||||
|
||||
const (
|
||||
PromotionLinkUrl = "http://api.zhetaoke.com:20000/api/open_jing_union_open_promotion_byunionid_get.ashx"
|
||||
)
|
||||
30
platform/zhetaoke/types.go
Normal file
30
platform/zhetaoke/types.go
Normal file
@ -0,0 +1,30 @@
|
||||
package zhetaoke
|
||||
|
||||
type PromotionLinkRequest struct {
|
||||
MaterialId string `json:"materialId"` //推广物料url,例如活动链接、商品链接等;支持仅传入skuid
|
||||
PositionId int64 `json:"positionId"` //自定义推广位id,自定义的数字,自己在本地跟用户做好关联,订单中会透出自定义的数字
|
||||
SubUnionId string `json:"subUnionId"` //子渠道标识 暂时没用 需要申请权限
|
||||
ChainType int64 `json:"chainType"` // 转链类型,1:长链, 2 :短链 ,3: 长链+短链,默认短链,短链有效期60天
|
||||
}
|
||||
|
||||
type PromotionLinkResponse struct {
|
||||
Code int64 `json:"code"` //200为成功,其他失败
|
||||
Data *PromotionLink `json:"data"`
|
||||
Message string `json:"message"`
|
||||
RequestId string `json:"request_id"`
|
||||
}
|
||||
type PromotionLink struct {
|
||||
ShortURL string `json:"shortUrl"` //短链
|
||||
ClickURL string `json:"clickUrl"` //长链接
|
||||
JCommand string `json:"jCommand"` //口令
|
||||
}
|
||||
type JdUnionOpenPromotionByunionidGetResponse struct {
|
||||
JdUnionOpenPromotionByunionidGetResponse *JdUnionOpenPromotionByunionidGet `json:"jd_union_open_promotion_byunionid_get_response"`
|
||||
Status int64 `json:"status"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
type JdUnionOpenPromotionByunionidGet struct {
|
||||
Code string `json:"code"`
|
||||
Result string `json:"result"`
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user