third-platform-sdk/platform/eleme-union/api_test.go
yanfan 4c4478dc84 取消api test秘钥信息
添加有票票渠道
2024-11-11 14:18:00 +08:00

109 lines
4.2 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package eleme_union
import (
"context"
"encoding/json"
"testing"
"time"
"github.com/stretchr/testify/suite"
"github.com/zeromicro/go-zero/core/logx"
"repository.lenntc.com/lenntc/third-platform-sdk/sdk/topsdk/defaultability/domain"
"repository.lenntc.com/lenntc/third-platform-sdk/sdk/topsdk/defaultability/request"
"repository.lenntc.com/lenntc/third-platform-sdk/util/pointer"
)
// api-单元测试
type apiClientSuite struct {
suite.Suite
api ElemeUnionApi
}
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_Sign() {
data := map[string]interface{}{
"method": "test",
}
publicParam := PublicParam{
Method: "taobao.item.seller.get", // 必传 API接口名称具体参见各平台API接口文档taobao.item.seller.get
AppKey: "34632005", // 必传 TOP分配给应用的AppKey。例12345678
Session: "", // 可选 用户授权成功后平台颁发给应用的授权session详细介绍请点击这里。当此API文档的标签上注明“需要授权”则此参数必传“不需要授权”则此参数不需要传。
Timestamp: time.Now().Format("2006-01-02 15:04:05"), // 必传 时间戳格式为yyyy-MM-dd HH:mm:ss时区为GMT+8例如2016-01-01 12:00:00。淘宝API服务端允许客户端请求最大时间误差为10分钟。
V: "2.0", // 必传 API协议版本可选值2.0
SignMethod: "md5", // 必传 签名的摘要算法可选值为hmacmd5hmac-sha256。
Format: "json", // 否 返回内容响应格式。不传默认为xml格式可选值xmljson。
Simplify: false, // 否 是否采用精简JSON返回格式仅当format=json时有效可选值falsetrue不传为false。
}
sign := a.api.Sign(publicParam, data)
a.T().Logf("=====[TestSign] sign: %s", sign)
}
func (a *apiClientSuite) Test_KbItemPromotionShareCreate() {
req := &request.AlibabaAlscUnionKbItemPromotionShareCreateRequest{
Pid: pointer.String("alsc_23378482_4796002_21291126"),
ItemId: pointer.String("10645"),
Sid: pointer.String("10001zdt100004"),
}
resp, err := a.api.KbItemPromotionShareCreate(req)
if err != nil {
a.T().Errorf("=====[Test_ElemePromotionOfficialActivityGet] err: %v", err)
return
}
a.T().Logf("=====[Test_ElemePromotionOfficialActivityGet] resp: %+v", resp)
}
func (a *apiClientSuite) Test_ElemePromotionOfficialActivityGet() {
req := &request.AlibabaAlscUnionElemePromotionOfficialactivityGetRequest{
QueryRequest: &domain.AlibabaAlscUnionElemePromotionOfficialactivityGetActivityRequest{
Pid: pointer.String("alsc_23378482_4796002_15513017"),
ActivityId: pointer.String("10645"),
Sid: pointer.String("10001zdt100004"),
},
}
resp, err := a.api.ElemePromotionOfficialActivityGet(req)
if err != nil {
a.T().Errorf("=====[Test_ElemePromotionOfficialActivityGet] err: %v", err)
return
}
str, err := json.Marshal(resp)
a.T().Logf("=====[Test_ElemePromotionOfficialActivityGet] resp: %s", str)
}
func (a *apiClientSuite) Test_KbcpxPositiveOrderGet() {
req := &request.AlibabaAlscUnionKbcpxPositiveOrderGetRequest{
DateType: pointer.Int64(1),
//Pid: pointer.String("alsc_23378482_4796002_15513017"),
BizUnit: pointer.Int64(2),
PageSize: pointer.Int64(20),
PageNumber: pointer.Int64(1),
StartDate: pointer.String("2024-05-16 00:00:00"),
EndDate: pointer.String("2024-05-17 00:00:00"),
//OrderId: pointer.String("8036650073745353114"),
}
resp, err := a.api.KbcpxPositiveOrderGet(req)
if err != nil {
a.T().Errorf("=====[Test_GetOrders] err: %v", err)
return
}
respStr, err := json.Marshal(resp)
if err != nil {
a.T().Errorf("=====[Test_GetOrders] err: %v", err)
return
}
a.T().Logf("=====[Test_GetOrders] resp: %+v", string(respStr))
}