守兔演出链接生成

This commit is contained in:
yanfan 2024-11-21 16:11:10 +08:00
parent 982f6981d4
commit 532e0b68f2
3 changed files with 38 additions and 2 deletions

View File

@ -15,6 +15,8 @@ import (
type ShouTuShowApi interface { type ShouTuShowApi interface {
// GenerateLink 生成推广链接 // GenerateLink 生成推广链接
GenerateLink(ctx context.Context, req GenerateLinkRequest) (*GenerateLinkResponse, error) GenerateLink(ctx context.Context, req GenerateLinkRequest) (*GenerateLinkResponse, error)
// GenerateWechatUrl 生成微信小程序链接
GenerateWechatUrl(ctx context.Context, req GenerateLinkRequest) (*GenerateLinkResponse, error)
} }
type ShouTuShowApiImpl struct { 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) { func (a *ShouTuShowApiImpl) GenerateLink(ctx context.Context, req GenerateLinkRequest) (*GenerateLinkResponse, error) {
if req.ActivityUrl == "" || req.Sid == "" { if req.ActivityUrl == "" || req.Sid == "" {
return nil, errors.New("请求参数activityUrl或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)) newUrl := strings.ReplaceAll(req.ActivityUrl, "subChannelId=", fmt.Sprintf("subChannelId=%s", req.Sid))
return &GenerateLinkResponse{ return &GenerateLinkResponse{

View File

@ -29,8 +29,10 @@ func (a *apiClientSuite) SetupSuite() {
func (a *apiClientSuite) Test_GenerateLink() { func (a *apiClientSuite) Test_GenerateLink() {
req := GenerateLinkRequest{ req := GenerateLinkRequest{
ActivityUrl: "pages/index/index?distributorId=VCiCWwU2&subChannelId=", ActivityUrl: "https://cms.zhongdiantui.com/#/pages/toMiniProgram/toMiniProgram",
Sid: "f3a8c1", Sid: "f3a8c1",
LinkCode: "aaakfhkahfkadk",
ActId: "1111",
} }
result, err := a.api.GenerateLink(context.Background(), req) result, err := a.api.GenerateLink(context.Background(), req)
if !a.NoError(err) { if !a.NoError(err) {
@ -44,3 +46,21 @@ func (a *apiClientSuite) Test_GenerateLink() {
} }
a.T().Logf("=====[Test_GenerateLink] result: %s", string(resultByte)) 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))
}

View File

@ -3,6 +3,8 @@ package shoutu_show
type GenerateLinkRequest struct { type GenerateLinkRequest struct {
ActivityUrl string `json:"activityUrl"` // 渠道方合作页地址 ActivityUrl string `json:"activityUrl"` // 渠道方合作页地址
Sid string `json:"sid"` // 必传 自定义参数 Sid string `json:"sid"` // 必传 自定义参数
LinkCode string `json:"linkCode"` // 链接code
ActId string `json:"actId"` // 活动id
} }
// GenerateLinkResponse 生成推广链接响应 // GenerateLinkResponse 生成推广链接响应