From 532e0b68f2e5fd8c8a921e0770c7b2d05d2db475 Mon Sep 17 00:00:00 2001 From: yanfan <1406317364@qq.com> Date: Thu, 21 Nov 2024 16:11:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=88=E5=85=94=E6=BC=94=E5=87=BA=E9=93=BE?= =?UTF-8?q?=E6=8E=A5=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platform/shoutu-show/api.go | 16 +++++++++++++++- platform/shoutu-show/api_test.go | 22 +++++++++++++++++++++- platform/shoutu-show/types.go | 2 ++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/platform/shoutu-show/api.go b/platform/shoutu-show/api.go index a60f6b1..1d937d1 100644 --- a/platform/shoutu-show/api.go +++ b/platform/shoutu-show/api.go @@ -15,6 +15,8 @@ import ( type ShouTuShowApi interface { // GenerateLink 生成推广链接 GenerateLink(ctx context.Context, req GenerateLinkRequest) (*GenerateLinkResponse, error) + // GenerateWechatUrl 生成微信小程序链接 + GenerateWechatUrl(ctx context.Context, req GenerateLinkRequest) (*GenerateLinkResponse, error) } type ShouTuShowApiImpl struct { @@ -29,11 +31,23 @@ func newShouTuShowApiImpl(log logx.Logger, client *Client) ShouTuShowApi { } } +// 守兔演出不支持H5取链,生成的H5url为小程序中间页URL func (a *ShouTuShowApiImpl) GenerateLink(ctx context.Context, req GenerateLinkRequest) (*GenerateLinkResponse, error) { if req.ActivityUrl == "" || req.Sid == "" { return nil, errors.New("请求参数activityUrl或sid不能为空") } - //测试联调地址 https://pre-show.shouto.cn/?distributorId=8&subChannelId= + + activityUrl := fmt.Sprintf("%s?linkCode=%s&actId=%s", req.ActivityUrl, req.LinkCode, req.ActId) + return &GenerateLinkResponse{ + H5: activityUrl, + }, nil +} + +// 小程序链接 +func (a *ShouTuShowApiImpl) GenerateWechatUrl(ctx context.Context, req GenerateLinkRequest) (*GenerateLinkResponse, error) { + if req.ActivityUrl == "" || req.Sid == "" { + return nil, errors.New("请求参数activityUrl或sid不能为空") + } //直接替换 newUrl := strings.ReplaceAll(req.ActivityUrl, "subChannelId=", fmt.Sprintf("subChannelId=%s", req.Sid)) return &GenerateLinkResponse{ diff --git a/platform/shoutu-show/api_test.go b/platform/shoutu-show/api_test.go index ed9f0d1..2920cd5 100644 --- a/platform/shoutu-show/api_test.go +++ b/platform/shoutu-show/api_test.go @@ -29,8 +29,10 @@ func (a *apiClientSuite) SetupSuite() { func (a *apiClientSuite) Test_GenerateLink() { req := GenerateLinkRequest{ - ActivityUrl: "pages/index/index?distributorId=VCiCWwU2&subChannelId=", + ActivityUrl: "https://cms.zhongdiantui.com/#/pages/toMiniProgram/toMiniProgram", Sid: "f3a8c1", + LinkCode: "aaakfhkahfkadk", + ActId: "1111", } result, err := a.api.GenerateLink(context.Background(), req) if !a.NoError(err) { @@ -44,3 +46,21 @@ func (a *apiClientSuite) Test_GenerateLink() { } a.T().Logf("=====[Test_GenerateLink] result: %s", string(resultByte)) } + +func (a *apiClientSuite) Test_GenerateWechatUrl() { + req := GenerateLinkRequest{ + ActivityUrl: "pages/index/index?distributorId=VCiCWwU2&subChannelId=", + Sid: "f3a8c1", + } + result, err := a.api.GenerateWechatUrl(context.Background(), 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)) +} diff --git a/platform/shoutu-show/types.go b/platform/shoutu-show/types.go index 781221b..66ba25c 100644 --- a/platform/shoutu-show/types.go +++ b/platform/shoutu-show/types.go @@ -3,6 +3,8 @@ package shoutu_show type GenerateLinkRequest struct { ActivityUrl string `json:"activityUrl"` // 渠道方合作页地址 Sid string `json:"sid"` // 必传 自定义参数 + LinkCode string `json:"linkCode"` // 链接code + ActId string `json:"actId"` // 活动id } // GenerateLinkResponse 生成推广链接响应