Compare commits

..

2 Commits

Author SHA1 Message Date
yanfan
e186c08583 中捷乐淘-淘宝一分购 2025-02-24 16:53:56 +08:00
yanfan
02924de3f8 中捷乐淘-淘宝一分购 2025-02-24 16:51:08 +08:00
6 changed files with 148 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package third_platform_sdk
import (
"github.com/zeromicro/go-zero/core/logx"
"repository.lenntc.com/lenntc/third-platform-sdk/platform/zjdg"
"repository.lenntc.com/lenntc/third-platform-sdk/platform/fliggy"
"repository.lenntc.com/lenntc/third-platform-sdk/platform/meituan"
@ -44,6 +45,8 @@ const (
PlatformYouPiaoPiao = "youpiaopiao"
// PlatformMeituan 美团联盟
PlatformMeituan = "meituan"
// PlatformZdjg 中捷乐淘-淘宝一分购
PlatformZdjg = "zjdg"
)
// PlatformNameMap 平台名称
@ -60,6 +63,7 @@ var PlatformNameMap = map[string]string{
PlatformShoutuShow: "守兔演出",
PlatformYouPiaoPiao: "有票票",
PlatformMeituan: "美团联盟",
PlatformZdjg: "中捷乐淘-淘宝一分购",
}
// GetPlatformName 获取平台名称
@ -126,3 +130,8 @@ func NewYouPiaoPiao(log logx.Logger, conf youpiaopiao.AuthConfig) youpiaopiao.Yo
func NewMeituanApi(log logx.Logger, conf meituan.AuthConfig) meituan.MeituanApi {
return meituan.NewApiClient(log, conf)
}
// NewZjdgApi 中捷乐淘-淘宝一分购
func NewZjdgApi(log logx.Logger, conf zjdg.AuthConfig) zjdg.ZjdgApi {
return zjdg.NewApiClient(log, conf)
}

43
platform/zjdg/api.go Normal file
View File

@ -0,0 +1,43 @@
package zjdg
import (
"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(req *ZoneAddRequest) (*ZoneAddResponse, 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(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
}

42
platform/zjdg/api_test.go Normal file
View File

@ -0,0 +1,42 @@
package zjdg
import (
"context"
"encoding/json"
"github.com/stretchr/testify/suite"
"github.com/zeromicro/go-zero/core/logx"
"testing"
)
// api-单元测试
type apiClientSuite struct {
suite.Suite
api ZjdgApi
}
func TestApiClient(t *testing.T) {
suite.Run(t, new(apiClientSuite))
}
func (a *apiClientSuite) SetupSuite() {
log := logx.WithContext(context.Background())
apiClient := NewApiClient(log, AuthConfig{
UserId: "", //
})
a.api = apiClient
}
func (a *apiClientSuite) Test_ZoneAdd() {
req := ZoneAddRequest{}
result, err := a.api.ZoneAdd(&req)
if !a.NoError(err) {
a.T().Errorf("========[Test_GenerateLink] response error:%s", err)
return
}
resultByte, err := json.Marshal(result)
if err != nil {
a.T().Errorf("========[Test_GenerateLink] json_marshal error:%s", err)
return
}
a.T().Logf("=====[Test_GenerateLink] result: %s", string(resultByte))
}

35
platform/zjdg/client.go Normal file
View File

@ -0,0 +1,35 @@
package zjdg
import (
"github.com/zeromicro/go-zero/core/logx"
"repository.lenntc.com/lenntc/third-platform-sdk/client"
)
// AuthConfig api鉴权参数
type AuthConfig struct {
UserId string //推广用户编号
}
// 连接第三方平台的client
type Client struct {
log logx.Logger
authConfig AuthConfig
client.HttpClient
headers map[string]string
}
func NewApiClient(log logx.Logger, conf AuthConfig) ZjdgApi {
clt := newClient(log, conf)
return newZjdgApiImpl(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/zjdg/consts.go Normal file
View File

@ -0,0 +1,5 @@
package zjdg
const (
ZoneAddUrl = "https://p.zjdg.cn/cpa/api/ugApi.ashx?method=getadzone_nologin&userid="
)

14
platform/zjdg/types.go Normal file
View File

@ -0,0 +1,14 @@
package zjdg
type ZoneAddRequest struct {
}
type ZoneAddResponse struct {
AdZoneId string `json:"ad_zone_id"` //推广编号
}
type ZoneAddOriginResponse struct {
Code int `json:"code"`
Message string `json:"message"`
Data string `json:"data"`
TokenId string `json:"token_id"`
}