t3联盟api对接, 返回数据错误判断
This commit is contained in:
parent
eb35ad6883
commit
dfa2bd43c2
@ -1,6 +1,8 @@
|
|||||||
package eleme_union
|
package eleme_union
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
|
||||||
"gitee.com/chengdu-lenntc/third-platform-sdk/sdk/topsdk/defaultability/domain"
|
"gitee.com/chengdu-lenntc/third-platform-sdk/sdk/topsdk/defaultability/domain"
|
||||||
@ -56,7 +58,7 @@ func (a *elemeUnionApiImpl) KbItemPromotionShareCreate(req *request.AlibabaAlscU
|
|||||||
if !resp.ResultSuccess || resp.BizErrorCode != "" {
|
if !resp.ResultSuccess || resp.BizErrorCode != "" {
|
||||||
a.log.WithFields(logx.LogField{Key: "data", Value: map[string]any{"req": req, "resp": resp}}).
|
a.log.WithFields(logx.LogField{Key: "data", Value: map[string]any{"req": req, "resp": resp}}).
|
||||||
Errorf("[elemeUnionApiImpl][GetLink] response result error: %s", resp.BizErrorDesc)
|
Errorf("[elemeUnionApiImpl][GetLink] response result error: %s", resp.BizErrorDesc)
|
||||||
return nil, err
|
return nil, errors.New(resp.BizErrorDesc)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &resp.Result, nil
|
return &resp.Result, nil
|
||||||
@ -73,7 +75,7 @@ func (a *elemeUnionApiImpl) ElemePromotionOfficialActivityGet(req *request.Aliba
|
|||||||
if resp.ResultCode != 0 {
|
if resp.ResultCode != 0 {
|
||||||
a.log.WithFields(logx.LogField{Key: "data", Value: map[string]any{"req": req, "resp": resp}}).
|
a.log.WithFields(logx.LogField{Key: "data", Value: map[string]any{"req": req, "resp": resp}}).
|
||||||
Errorf("[elemeUnionApiImpl][ElemePromotionOfficialActivityGet] response result error: %s", resp.Message)
|
Errorf("[elemeUnionApiImpl][ElemePromotionOfficialActivityGet] response result error: %s", resp.Message)
|
||||||
return nil, err
|
return nil, errors.New(resp.Message)
|
||||||
}
|
}
|
||||||
return &resp.Data, nil
|
return &resp.Data, nil
|
||||||
}
|
}
|
||||||
@ -89,7 +91,7 @@ func (a *elemeUnionApiImpl) AlibabaAlscUnionMediaZoneAdd(req *request.AlibabaAls
|
|||||||
if !resp.ResultSuccess || resp.BizErrorCode != 0 {
|
if !resp.ResultSuccess || resp.BizErrorCode != 0 {
|
||||||
a.log.WithFields(logx.LogField{Key: "data", Value: map[string]any{"req": req, "resp": resp}}).
|
a.log.WithFields(logx.LogField{Key: "data", Value: map[string]any{"req": req, "resp": resp}}).
|
||||||
Errorf("[elemeUnionApiImpl][AlibabaAlscUnionMediaZoneAdd] response result error: %s", resp.BizErrorDesc)
|
Errorf("[elemeUnionApiImpl][AlibabaAlscUnionMediaZoneAdd] response result error: %s", resp.BizErrorDesc)
|
||||||
return nil, err
|
return nil, errors.New(resp.BizErrorDesc)
|
||||||
}
|
}
|
||||||
return &resp.Result, nil
|
return &resp.Result, nil
|
||||||
}
|
}
|
||||||
@ -105,7 +107,7 @@ func (a *elemeUnionApiImpl) AlibabaAlscUnionMediaZoneGet(req *request.AlibabaAls
|
|||||||
if !resp.ResultSuccess || resp.BizErrorCode != 0 {
|
if !resp.ResultSuccess || resp.BizErrorCode != 0 {
|
||||||
a.log.WithFields(logx.LogField{Key: "data", Value: map[string]any{"req": req, "resp": resp}}).
|
a.log.WithFields(logx.LogField{Key: "data", Value: map[string]any{"req": req, "resp": resp}}).
|
||||||
Errorf("[elemeUnionApiImpl][AlibabaAlscUnionMediaZoneGet] response result error: %s", resp.BizErrorDesc)
|
Errorf("[elemeUnionApiImpl][AlibabaAlscUnionMediaZoneGet] response result error: %s", resp.BizErrorDesc)
|
||||||
return nil, err
|
return nil, errors.New(resp.BizErrorDesc)
|
||||||
}
|
}
|
||||||
var result []*domain.AlibabaAlscUnionMediaZoneGetZoneInfoDTO
|
var result []*domain.AlibabaAlscUnionMediaZoneGetZoneInfoDTO
|
||||||
for _, item := range resp.Result {
|
for _, item := range resp.Result {
|
||||||
@ -126,7 +128,7 @@ func (a *elemeUnionApiImpl) KbcpxPositiveOrderGet(req *request.AlibabaAlscUnionK
|
|||||||
if !resp.ResultSuccess || resp.BizErrorCode != 0 {
|
if !resp.ResultSuccess || resp.BizErrorCode != 0 {
|
||||||
a.log.WithFields(logx.LogField{Key: "data", Value: map[string]any{"req": req, "resp": resp}}).
|
a.log.WithFields(logx.LogField{Key: "data", Value: map[string]any{"req": req, "resp": resp}}).
|
||||||
Errorf("[elemeUnionApiImpl][KbcpxPositiveOrderGet] response result error: %s", resp.BizErrorDesc)
|
Errorf("[elemeUnionApiImpl][KbcpxPositiveOrderGet] response result error: %s", resp.BizErrorDesc)
|
||||||
return nil, err
|
return nil, errors.New(resp.BizErrorDesc)
|
||||||
}
|
}
|
||||||
var result []*domain.AlibabaAlscUnionKbcpxPositiveOrderGetOrderDetailReportDTO
|
var result []*domain.AlibabaAlscUnionKbcpxPositiveOrderGetOrderDetailReportDTO
|
||||||
for _, item := range resp.Result {
|
for _, item := range resp.Result {
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package t3_union
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -22,13 +23,13 @@ type T3UnionApi interface {
|
|||||||
// Sign 签名
|
// Sign 签名
|
||||||
Sign(methodType string, url string, data map[string]interface{}) string
|
Sign(methodType string, url string, data map[string]interface{}) string
|
||||||
// GenerateLink 生成短链
|
// GenerateLink 生成短链
|
||||||
GenerateLink(ctx context.Context, req GenerateLinkRequest) (*GenerateLinkResponse, error)
|
GenerateLink(ctx context.Context, req GenerateLinkRequest) (*GenerateLinkData, error)
|
||||||
// GenerateCode 生成二维码
|
// GenerateCode 生成二维码
|
||||||
GenerateCode(ctx context.Context, req GenerateCodeRequest) (*GenerateCodeResponse, error)
|
GenerateCode(ctx context.Context, req GenerateCodeRequest) (*GenerateCodeData, error)
|
||||||
// GeneratePoster 生成推广海报
|
// GeneratePoster 生成推广海报
|
||||||
GeneratePoster(ctx context.Context, req GeneratePosterRequest) (*GeneratePosterResponse, error)
|
GeneratePoster(ctx context.Context, req GeneratePosterRequest) (*GeneratePosterData, error)
|
||||||
// QueryOrderList 查询订单列表
|
// QueryOrderList 查询订单列表
|
||||||
QueryOrderList(ctx context.Context, req QueryOrderListRequest) (*QueryOrderListResponse, error)
|
QueryOrderList(ctx context.Context, req QueryOrderListRequest) (*QueryOrderData, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type t3UnionApiImpl struct {
|
type t3UnionApiImpl struct {
|
||||||
@ -43,7 +44,7 @@ func newT3UnionApiImpl(log logx.Logger, client *Client) T3UnionApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *t3UnionApiImpl) buildHeader(methodType string, url string, data map[string]any) map[string]string {
|
func (a *t3UnionApiImpl) buildHeader(methodType string, uri string, data map[string]any) map[string]string {
|
||||||
// 随机数
|
// 随机数
|
||||||
tn := time.Now()
|
tn := time.Now()
|
||||||
src := rand.NewSource(tn.Unix())
|
src := rand.NewSource(tn.Unix())
|
||||||
@ -57,13 +58,13 @@ func (a *t3UnionApiImpl) buildHeader(methodType string, url string, data map[str
|
|||||||
XT3SignatureMethod: "MD5", // 固定值传 "MD5"
|
XT3SignatureMethod: "MD5", // 固定值传 "MD5"
|
||||||
}
|
}
|
||||||
|
|
||||||
headers[XT3Signature] = a.getSign(methodType, url, headers, data) // 在获得签名后赋值
|
headers[XT3Signature] = a.getSign(methodType, uri, headers, data) // 在获得签名后赋值
|
||||||
headers[XT3SignatureHeaders] = "x-t3-nonce,x-t3-timestamp,x-t3-version,x-t3-key,x-t3-signature-method" // 固定传值
|
headers[XT3SignatureHeaders] = "x-t3-nonce,x-t3-timestamp,x-t3-version,x-t3-key,x-t3-signature-method" // 固定传值
|
||||||
|
|
||||||
return headers
|
return headers
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *t3UnionApiImpl) getSign(methodType string, url string, headers map[string]string, data map[string]any) string {
|
func (a *t3UnionApiImpl) getSign(methodType string, uri string, headers map[string]string, data map[string]any) string {
|
||||||
// key排序
|
// key排序
|
||||||
arr := sort.StringSlice{}
|
arr := sort.StringSlice{}
|
||||||
for k := range headers {
|
for k := range headers {
|
||||||
@ -74,7 +75,7 @@ func (a *t3UnionApiImpl) getSign(methodType string, url string, headers map[stri
|
|||||||
arr.Sort()
|
arr.Sort()
|
||||||
// 参数拼接
|
// 参数拼接
|
||||||
var build strings.Builder
|
var build strings.Builder
|
||||||
build.WriteString(fmt.Sprintf("%s%s", methodType, url))
|
build.WriteString(fmt.Sprintf("%s%s", methodType, uri))
|
||||||
for _, k := range arr {
|
for _, k := range arr {
|
||||||
build.WriteString(fmt.Sprintf("%s:%v", k, headers[k]))
|
build.WriteString(fmt.Sprintf("%s:%v", k, headers[k]))
|
||||||
}
|
}
|
||||||
@ -86,8 +87,8 @@ func (a *t3UnionApiImpl) getSign(methodType string, url string, headers map[stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sign 签名
|
// Sign 签名
|
||||||
func (a *t3UnionApiImpl) Sign(methodType string, url string, dataMap map[string]any) string {
|
func (a *t3UnionApiImpl) Sign(methodType string, uri string, dataMap map[string]any) string {
|
||||||
headers := a.buildHeader(methodType, url, dataMap)
|
headers := a.buildHeader(methodType, uri, dataMap)
|
||||||
if sign, ok := headers[XT3Signature]; ok {
|
if sign, ok := headers[XT3Signature]; ok {
|
||||||
return sign
|
return sign
|
||||||
}
|
}
|
||||||
@ -95,7 +96,7 @@ func (a *t3UnionApiImpl) Sign(methodType string, url string, dataMap map[string]
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GenerateLink 生成短链
|
// GenerateLink 生成短链
|
||||||
func (a *t3UnionApiImpl) GenerateLink(ctx context.Context, req GenerateLinkRequest) (*GenerateLinkResponse, error) {
|
func (a *t3UnionApiImpl) GenerateLink(ctx context.Context, req GenerateLinkRequest) (*GenerateLinkData, error) {
|
||||||
args := util.StructToMap(req)
|
args := util.StructToMap(req)
|
||||||
headers := a.buildHeader(http.MethodPost, GetLinkUri, args)
|
headers := a.buildHeader(http.MethodPost, GetLinkUri, args)
|
||||||
for k, v := range a.client.headers {
|
for k, v := range a.client.headers {
|
||||||
@ -106,11 +107,16 @@ func (a *t3UnionApiImpl) GenerateLink(ctx context.Context, req GenerateLinkReque
|
|||||||
if err := a.client.HttpPost(GetLinkUrl, request, &client.HttpResponse{Result: response}); err != nil {
|
if err := a.client.HttpPost(GetLinkUrl, request, &client.HttpResponse{Result: response}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return response, nil
|
if !response.Success || response.ErrCode != 0 {
|
||||||
|
a.log.WithFields(logx.LogField{Key: "data", Value: map[string]any{"req": req, "resp": response}}).
|
||||||
|
Errorf("[t3UnionApiImpl][GenerateLink] response result error: %s", response.Msg)
|
||||||
|
return nil, errors.New(response.Msg)
|
||||||
|
}
|
||||||
|
return response.Data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateCode 生成二维码
|
// GenerateCode 生成二维码
|
||||||
func (a *t3UnionApiImpl) GenerateCode(ctx context.Context, req GenerateCodeRequest) (*GenerateCodeResponse, error) {
|
func (a *t3UnionApiImpl) GenerateCode(ctx context.Context, req GenerateCodeRequest) (*GenerateCodeData, error) {
|
||||||
args := util.StructToMap(req)
|
args := util.StructToMap(req)
|
||||||
headers := a.buildHeader(http.MethodPost, GetMiniCodeUri, args)
|
headers := a.buildHeader(http.MethodPost, GetMiniCodeUri, args)
|
||||||
for k, v := range a.client.headers {
|
for k, v := range a.client.headers {
|
||||||
@ -121,11 +127,16 @@ func (a *t3UnionApiImpl) GenerateCode(ctx context.Context, req GenerateCodeReque
|
|||||||
if err := a.client.HttpPost(GetMiniCodeUrl, request, &client.HttpResponse{Result: response}); err != nil {
|
if err := a.client.HttpPost(GetMiniCodeUrl, request, &client.HttpResponse{Result: response}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return response, nil
|
if !response.Success || response.ErrCode != 0 {
|
||||||
|
a.log.WithFields(logx.LogField{Key: "data", Value: map[string]any{"req": req, "resp": response}}).
|
||||||
|
Errorf("[t3UnionApiImpl][GenerateLink] response result error: %s", response.Msg)
|
||||||
|
return nil, errors.New(response.Msg)
|
||||||
|
}
|
||||||
|
return response.Data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GeneratePoster 生成推广海报
|
// GeneratePoster 生成推广海报
|
||||||
func (a *t3UnionApiImpl) GeneratePoster(ctx context.Context, req GeneratePosterRequest) (*GeneratePosterResponse, error) {
|
func (a *t3UnionApiImpl) GeneratePoster(ctx context.Context, req GeneratePosterRequest) (*GeneratePosterData, error) {
|
||||||
args := util.StructToMap(req)
|
args := util.StructToMap(req)
|
||||||
headers := a.buildHeader(http.MethodPost, GetPosterUri, args)
|
headers := a.buildHeader(http.MethodPost, GetPosterUri, args)
|
||||||
for k, v := range a.client.headers {
|
for k, v := range a.client.headers {
|
||||||
@ -136,11 +147,16 @@ func (a *t3UnionApiImpl) GeneratePoster(ctx context.Context, req GeneratePosterR
|
|||||||
if err := a.client.HttpPost(GetPosterUrl, request, &client.HttpResponse{Result: response}); err != nil {
|
if err := a.client.HttpPost(GetPosterUrl, request, &client.HttpResponse{Result: response}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return response, nil
|
if !response.Success || response.ErrCode != 0 {
|
||||||
|
a.log.WithFields(logx.LogField{Key: "data", Value: map[string]any{"req": req, "resp": response}}).
|
||||||
|
Errorf("[t3UnionApiImpl][GenerateLink] response result error: %s", response.Msg)
|
||||||
|
return nil, errors.New(response.Msg)
|
||||||
|
}
|
||||||
|
return response.Data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryOrderList 查询订单列表
|
// QueryOrderList 查询订单列表
|
||||||
func (a *t3UnionApiImpl) QueryOrderList(ctx context.Context, req QueryOrderListRequest) (*QueryOrderListResponse, error) {
|
func (a *t3UnionApiImpl) QueryOrderList(ctx context.Context, req QueryOrderListRequest) (*QueryOrderData, error) {
|
||||||
args := util.StructToMap(req)
|
args := util.StructToMap(req)
|
||||||
headers := a.buildHeader(http.MethodPost, GetOrderListUri, args)
|
headers := a.buildHeader(http.MethodPost, GetOrderListUri, args)
|
||||||
for k, v := range a.client.headers {
|
for k, v := range a.client.headers {
|
||||||
@ -151,5 +167,10 @@ func (a *t3UnionApiImpl) QueryOrderList(ctx context.Context, req QueryOrderListR
|
|||||||
if err := a.client.HttpPost(GetOrderListUrl, request, &client.HttpResponse{Result: response}); err != nil {
|
if err := a.client.HttpPost(GetOrderListUrl, request, &client.HttpResponse{Result: response}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return response, nil
|
if !response.Success || response.ErrCode != 0 {
|
||||||
|
a.log.WithFields(logx.LogField{Key: "data", Value: map[string]any{"req": req, "resp": response}}).
|
||||||
|
Errorf("[t3UnionApiImpl][GenerateLink] response result error: %s", response.Msg)
|
||||||
|
return nil, errors.New(response.Msg)
|
||||||
|
}
|
||||||
|
return response.Data, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user