中捷乐淘-淘宝一分购
This commit is contained in:
parent
98580f4b7b
commit
02924de3f8
43
platform/zjdg/api.go
Normal file
43
platform/zjdg/api.go
Normal 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
42
platform/zjdg/api_test.go
Normal 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
35
platform/zjdg/client.go
Normal 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
5
platform/zjdg/consts.go
Normal 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
14
platform/zjdg/types.go
Normal 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"`
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user