同程:生成链接
This commit is contained in:
parent
b3b0b5a629
commit
6bb4957ffe
@ -5,6 +5,7 @@ import (
|
||||
"crypto/md5"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@ -18,6 +19,8 @@ import (
|
||||
type TongChengApi interface {
|
||||
// GetExternalChannelConfig 获取渠道配置信息
|
||||
GetExternalChannelConfig(ctx context.Context, req GetExternalChannelConfigRequest, env string) (*ExternalChannelConfigResponse, error)
|
||||
// GenerateUrl 生成链接
|
||||
GenerateUrl(ctx context.Context, req GenerateUrlRequest) (string, error)
|
||||
// QueryOrderList 查询订单列表
|
||||
QueryOrderList(ctx context.Context, req QueryOrderListRequest, env string) (*ExternalOrderData, error)
|
||||
}
|
||||
@ -67,6 +70,36 @@ func (t *tongChengApiImpl) GetExternalChannelConfig(ctx context.Context, req Get
|
||||
return response.Data, nil
|
||||
}
|
||||
|
||||
// GenerateUrl 生成链接
|
||||
func (t *tongChengApiImpl) GenerateUrl(ctx context.Context, req GenerateUrlRequest) (string, error) {
|
||||
if len(req.ActivityUrl) == 0 {
|
||||
return "", errors.New("url参数不能为空")
|
||||
}
|
||||
u, err := url.Parse(req.ActivityUrl)
|
||||
if err != nil {
|
||||
return "", errors.New("activityUrl不是一个url")
|
||||
}
|
||||
urlParams := u.Query()
|
||||
src := urlParams.Get("src")
|
||||
src, err = url.QueryUnescape(src)
|
||||
if err != nil {
|
||||
return "", errors.New("src参数解析失败")
|
||||
}
|
||||
srcUrl, err := url.Parse(src)
|
||||
if err != nil {
|
||||
return "", errors.New("activityUrl格式不符合要求,src参数不是一个url")
|
||||
}
|
||||
srcParams := srcUrl.Query()
|
||||
srcParams.Add("outUserid", req.Uid)
|
||||
srcParams.Add("outToken", t.client.authConfig.Token)
|
||||
srcUrl.RawQuery = srcParams.Encode()
|
||||
newSrc := url.QueryEscape(srcUrl.String())
|
||||
urlParams.Set("src", newSrc)
|
||||
urlParams.Add("isRefresh", "refresh")
|
||||
u.RawQuery = urlParams.Encode()
|
||||
return u.String(), nil
|
||||
}
|
||||
|
||||
// QueryOrderList 查询订单列表
|
||||
func (t *tongChengApiImpl) QueryOrderList(ctx context.Context, req QueryOrderListRequest, env string) (*ExternalOrderData, error) {
|
||||
var url string
|
||||
|
||||
@ -28,10 +28,10 @@ func (a *apiClientSuite) SetupSuite() {
|
||||
}
|
||||
|
||||
func (a *apiClientSuite) Test_GenerateLink() {
|
||||
req := GenerateLinkRequest{
|
||||
req := GetExternalChannelConfigRequest{
|
||||
Trackid: "elong_hotel",
|
||||
}
|
||||
result, err := a.api.GenerateLink(context.Background(), req, "huidu")
|
||||
result, err := a.api.GetExternalChannelConfig(context.Background(), req, "huidu")
|
||||
if !a.NoError(err) {
|
||||
a.T().Errorf("========[Test_GenerateLink] response error:%s", err)
|
||||
return
|
||||
@ -44,6 +44,19 @@ func (a *apiClientSuite) Test_GenerateLink() {
|
||||
a.T().Logf("=====[Test_GenerateLink] result: %s", string(resultByte))
|
||||
}
|
||||
|
||||
func (a *apiClientSuite) Test_GenerateUrl() {
|
||||
req := GenerateUrlRequest{
|
||||
ActivityUrl: "/page/home/webview/webview?src=https%3A%2F%2Fmp.elong.com%2Ftenthousandaura%2F%3Factivitycode%3D5fd89a11-7b58-4f5c-8dc9-c360936d4207%26of%3D99810010",
|
||||
Uid: "11111111111111111",
|
||||
}
|
||||
result, err := a.api.GenerateUrl(context.Background(), req)
|
||||
if !a.NoError(err) {
|
||||
a.T().Errorf("========[Test_GenerateUrl] response error:%s", err)
|
||||
return
|
||||
}
|
||||
a.T().Logf("=====[Test_GenerateUrl] result: %s", string(result))
|
||||
}
|
||||
|
||||
func (a *apiClientSuite) Test_QueryOrderList() {
|
||||
req := QueryOrderListRequest{
|
||||
AppId: "",
|
||||
|
||||
@ -46,6 +46,12 @@ type OtherActivityUrl struct {
|
||||
ActivityUrl string `json:"activityUrl"` // 渠道方合作页地址
|
||||
}
|
||||
|
||||
// GenerateUrlReq 生成链接的请求
|
||||
type GenerateUrlRequest struct {
|
||||
ActivityUrl string `json:"activityUrl"` // 活动url
|
||||
Uid string `json:"uid"` // 用户id
|
||||
}
|
||||
|
||||
// 获取外部订单请求
|
||||
type QueryOrderListRequest struct {
|
||||
AppId string `json:"appId"` // 必传,分配token查询接口提供的appId(getExternalChannelConfig接口返回的appId)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user