meituan-union平台api对接

This commit is contained in:
wukesheng 2024-05-01 17:14:00 +08:00
parent 1e5037d017
commit ccfc4e154b
2 changed files with 5 additions and 3 deletions

View File

@ -31,10 +31,11 @@ func newMeituanCsrApiImpl(log logx.Logger, client *Client) MeituanCsrApi {
} }
func (a *meituanCsrApiImpl) GetLink(params PromotionLinkRequest) (*PromotionLinkResponse, error) { func (a *meituanCsrApiImpl) GetLink(params PromotionLinkRequest) (*PromotionLinkResponse, error) {
url := a.Url(context.Background(), GetLinkUrl)
queryArgs := util.StructToMap(params) queryArgs := util.StructToMap(params)
req := &client.HttpRequest{Headers: a.client.Headers, QueryArgs: queryArgs} req := &client.HttpRequest{Headers: a.client.Headers, QueryArgs: queryArgs}
response := new(PromotionLinkResponse) response := new(PromotionLinkResponse)
if err := a.client.HttpGet(GetLinkUrl, req, &client.HttpResponse{Result: response}); err != nil { if err := a.client.HttpGet(url, req, &client.HttpResponse{Result: response}); err != nil {
return nil, err return nil, err
} }
return response, nil return response, nil
@ -58,6 +59,6 @@ func (a *meituanCsrApiImpl) sign(params map[string]any) string {
func (a *meituanCsrApiImpl) generateAccessToken(ts int64) string { func (a *meituanCsrApiImpl) generateAccessToken(ts int64) string {
//Access_token生成规则 //Access_token生成规则
//将媒体utmSource与时间戳拼接起来然后使用AES加密生成。例如utmSource为1000时间戳1555510603则access_token为AesEncode(10001555510603)每个token有效期为1小时 //将媒体utmSource与时间戳拼接起来然后使用AES加密生成。例如utmSource为1000时间戳1555510603则access_token为AesEncode(10001555510603)每个token有效期为1小时
encodeStr, _ := a.client.authConfig.aes.Encode(fmt.Sprintf("%s%d", a.client.authConfig.UtmSource, ts)) encodeStr, _ := a.client.aes.Encode(fmt.Sprintf("%s%d", a.client.authConfig.UtmSource, ts))
return encodeStr return encodeStr
} }

View File

@ -10,7 +10,6 @@ import (
type AuthConfig struct { type AuthConfig struct {
AppKey string AppKey string
UtmSource string UtmSource string
aes *AES
} }
// 连接第三方平台的client // 连接第三方平台的client
@ -18,6 +17,7 @@ type Client struct {
client.ThirdClient client.ThirdClient
log logx.Logger log logx.Logger
authConfig AuthConfig authConfig AuthConfig
aes *AES
Headers map[string]string Headers map[string]string
} }
@ -26,6 +26,7 @@ func newClient(log logx.Logger, conf AuthConfig) *Client {
ThirdClient: client.NewThirdClient(log), ThirdClient: client.NewThirdClient(log),
log: log, log: log,
authConfig: conf, authConfig: conf,
aes: NewAes(conf.AppKey),
} }
} }