同程酒店:添加生成h5链接api
This commit is contained in:
parent
8f03a210f5
commit
90bad61d0a
@ -9,6 +9,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"github.com/zywaited/xcopy"
|
||||||
|
|
||||||
"repository.lenntc.com/lenntc/third-platform-sdk/client"
|
"repository.lenntc.com/lenntc/third-platform-sdk/client"
|
||||||
"repository.lenntc.com/lenntc/third-platform-sdk/util"
|
"repository.lenntc.com/lenntc/third-platform-sdk/util"
|
||||||
@ -19,8 +20,10 @@ import (
|
|||||||
type ElongHotelApi interface {
|
type ElongHotelApi interface {
|
||||||
// GetExternalChannelConfig 获取渠道配置信息
|
// GetExternalChannelConfig 获取渠道配置信息
|
||||||
GetExternalChannelConfig(ctx context.Context, req GetExternalChannelConfigRequest, env string) (*ExternalChannelConfigResponse, error)
|
GetExternalChannelConfig(ctx context.Context, req GetExternalChannelConfigRequest, env string) (*ExternalChannelConfigResponse, error)
|
||||||
// GenerateUrl 生成链接
|
// GenerateWechatUrl 生成微信小程序链接
|
||||||
GenerateUrl(ctx context.Context, req GenerateUrlRequest) (string, error)
|
GenerateWechatUrl(ctx context.Context, req GenerateWechatUrlRequest) (string, error)
|
||||||
|
// GenerateH5Url 生成H5链接
|
||||||
|
GenerateH5Url(ctx context.Context, req GenerateH5UrlRequest) (string, error)
|
||||||
// QueryOrderList 查询订单列表
|
// QueryOrderList 查询订单列表
|
||||||
QueryOrderList(ctx context.Context, req QueryOrderListRequest, env string) (*ExternalOrderData, error)
|
QueryOrderList(ctx context.Context, req QueryOrderListRequest, env string) (*ExternalOrderData, error)
|
||||||
}
|
}
|
||||||
@ -37,9 +40,9 @@ func newElongHotelApiImpl(log logx.Logger, client *Client) ElongHotelApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateLink 生成短链
|
// GetExternalChannelConfig 生成短链
|
||||||
func (t *elongHotelApiImpl) GetExternalChannelConfig(ctx context.Context, req GetExternalChannelConfigRequest, env string) (*ExternalChannelConfigResponse, error) {
|
func (t *elongHotelApiImpl) GetExternalChannelConfig(ctx context.Context, req GetExternalChannelConfigRequest, env string) (*ExternalChannelConfigResponse, error) {
|
||||||
var url string
|
var apiUrl string
|
||||||
token := t.client.authConfig.Token
|
token := t.client.authConfig.Token
|
||||||
tn := time.Now()
|
tn := time.Now()
|
||||||
actionTime := tn.Unix()
|
actionTime := tn.Unix()
|
||||||
@ -55,11 +58,11 @@ func (t *elongHotelApiImpl) GetExternalChannelConfig(ctx context.Context, req Ge
|
|||||||
request := &client.HttpRequest{Headers: t.client.headers, QueryArgs: args}
|
request := &client.HttpRequest{Headers: t.client.headers, QueryArgs: args}
|
||||||
response := new(GetExternalChannelConfigResponse)
|
response := new(GetExternalChannelConfigResponse)
|
||||||
if env == EnvHuidu {
|
if env == EnvHuidu {
|
||||||
url = HDApiDomain + GetLinkUri
|
apiUrl = HDApiDomain + GetLinkUri
|
||||||
} else {
|
} else {
|
||||||
url = ApiDomain + GetLinkUri
|
apiUrl = ApiDomain + GetLinkUri
|
||||||
}
|
}
|
||||||
if err := t.client.HttpGet(url, request, &client.HttpResponse{Result: response}); err != nil {
|
if err := t.client.HttpGet(apiUrl, request, &client.HttpResponse{Result: response}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if response.Code != 200 {
|
if response.Code != 200 {
|
||||||
@ -70,8 +73,8 @@ func (t *elongHotelApiImpl) GetExternalChannelConfig(ctx context.Context, req Ge
|
|||||||
return response.Data, nil
|
return response.Data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateUrl 生成链接
|
// GenerateWechatUrl 生成微信小程序链接
|
||||||
func (t *elongHotelApiImpl) GenerateUrl(ctx context.Context, req GenerateUrlRequest) (string, error) {
|
func (t *elongHotelApiImpl) GenerateWechatUrl(ctx context.Context, req GenerateWechatUrlRequest) (string, error) {
|
||||||
if len(req.ActivityUrl) == 0 {
|
if len(req.ActivityUrl) == 0 {
|
||||||
return "", errors.New("url参数不能为空")
|
return "", errors.New("url参数不能为空")
|
||||||
}
|
}
|
||||||
@ -95,23 +98,45 @@ func (t *elongHotelApiImpl) GenerateUrl(ctx context.Context, req GenerateUrlRequ
|
|||||||
srcUrl.RawQuery = srcParams.Encode()
|
srcUrl.RawQuery = srcParams.Encode()
|
||||||
newSrc := url.QueryEscape(srcUrl.String())
|
newSrc := url.QueryEscape(srcUrl.String())
|
||||||
urlParams.Set("src", newSrc)
|
urlParams.Set("src", newSrc)
|
||||||
urlParams.Add("isRefresh", "refresh")
|
urlSrc := fmt.Sprintf("src=%s", newSrc)
|
||||||
|
urlParams.Del("src")
|
||||||
|
u.RawQuery = fmt.Sprintf("%s&%s", urlSrc, urlParams.Encode())
|
||||||
|
return u.String(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenerateH5Url 生成H5链接
|
||||||
|
func (t *elongHotelApiImpl) GenerateH5Url(ctx context.Context, req GenerateH5UrlRequest) (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()
|
||||||
|
urlParams.Set("linkCode", req.LinkCode)
|
||||||
|
urlParams.Set("actId", req.ActId)
|
||||||
u.RawQuery = urlParams.Encode()
|
u.RawQuery = urlParams.Encode()
|
||||||
return u.String(), nil
|
return u.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryOrderList 查询订单列表
|
// QueryOrderList 查询订单列表
|
||||||
func (t *elongHotelApiImpl) QueryOrderList(ctx context.Context, req QueryOrderListRequest, env string) (*ExternalOrderData, error) {
|
func (t *elongHotelApiImpl) QueryOrderList(ctx context.Context, req QueryOrderListRequest, env string) (*ExternalOrderData, error) {
|
||||||
var url string
|
var apiUrl string
|
||||||
args := util.StructToMap(req)
|
var apiReq *QueryOrderListReq
|
||||||
|
if err := xcopy.Copy(&apiReq, req); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
apiReq.AppId = t.client.authConfig.AppId
|
||||||
|
args := util.StructToMap(apiReq)
|
||||||
request := &client.HttpRequest{Headers: t.client.headers, QueryArgs: args}
|
request := &client.HttpRequest{Headers: t.client.headers, QueryArgs: args}
|
||||||
response := new(GetExternalOrderResp)
|
response := new(GetExternalOrderResp)
|
||||||
if env == EnvHuidu {
|
if env == EnvHuidu {
|
||||||
url = HDApiDomain + GetOrderListUri
|
apiUrl = HDApiDomain + GetOrderListUri
|
||||||
} else {
|
} else {
|
||||||
url = ApiDomain + GetOrderListUri
|
apiUrl = ApiDomain + GetOrderListUri
|
||||||
}
|
}
|
||||||
if err := t.client.HttpGet(url, request, &client.HttpResponse{Result: response}); err != nil {
|
if err := t.client.HttpGet(apiUrl, request, &client.HttpResponse{Result: response}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if response.Code != 200 {
|
if response.Code != 200 {
|
||||||
|
|||||||
@ -44,12 +44,13 @@ 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_GenerateUrl() {
|
func (a *apiClientSuite) Test_GenerateWechtUrl() {
|
||||||
req := GenerateUrlRequest{
|
req := GenerateWechatUrlRequest{
|
||||||
ActivityUrl: "/page/home/webview/webview?src=https%3A%2F%2Fmp.elong.com%2Ftenthousandaura%2F%3Factivitycode%3D5fd89a11-7b58-4f5c-8dc9-c360936d4207%26of%3D99810010",
|
//ActivityUrl: "/page/home/webview/webview?src=https%3A%2F%2Fmp.elong.com%2Ftenthousandaura%2F%3Factivitycode%3D5fd89a11-7b58-4f5c-8dc9-c360936d4207%26of%3D99810010",
|
||||||
|
ActivityUrl: "/page/home/webview/webview?src=https%3A%2F%2Fmp.elong.com%2Ftenthousandaura%2F%3Factivitycode%3D73086812-aaae-48ba-b14a-f087a6b61a92%26isSocket%3DHotelActivityId_9043%26of%3D5027785&isRefresh=refresh&isSocket=HotelActivityId_9043",
|
||||||
Uid: "11111111111111111",
|
Uid: "11111111111111111",
|
||||||
}
|
}
|
||||||
result, err := a.api.GenerateUrl(context.Background(), req)
|
result, err := a.api.GenerateWechatUrl(context.Background(), req)
|
||||||
if !a.NoError(err) {
|
if !a.NoError(err) {
|
||||||
a.T().Errorf("========[Test_GenerateUrl] response error:%s", err)
|
a.T().Errorf("========[Test_GenerateUrl] response error:%s", err)
|
||||||
return
|
return
|
||||||
@ -57,9 +58,22 @@ func (a *apiClientSuite) Test_GenerateUrl() {
|
|||||||
a.T().Logf("=====[Test_GenerateUrl] result: %s", string(result))
|
a.T().Logf("=====[Test_GenerateUrl] result: %s", string(result))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *apiClientSuite) Test_GenerateH5Url() {
|
||||||
|
req := GenerateH5UrlRequest{
|
||||||
|
ActivityUrl: "http://www.baidu.com/page/miniprogram?src=asfsfsiwef",
|
||||||
|
LinkCode: "ffaefe3r3434334trq34",
|
||||||
|
ActId: "100006",
|
||||||
|
}
|
||||||
|
result, err := a.api.GenerateH5Url(context.Background(), req)
|
||||||
|
if !a.NoError(err) {
|
||||||
|
a.T().Errorf("========[Test_GenerateH5Url] response error:%s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
a.T().Logf("=====[Test_GenerateH5Url] result: %s", string(result))
|
||||||
|
}
|
||||||
|
|
||||||
func (a *apiClientSuite) Test_QueryOrderList() {
|
func (a *apiClientSuite) Test_QueryOrderList() {
|
||||||
req := QueryOrderListRequest{
|
req := QueryOrderListRequest{
|
||||||
AppId: "",
|
|
||||||
Trackid: "",
|
Trackid: "",
|
||||||
BeginDate: "2024-07-01 00:00:00",
|
BeginDate: "2024-07-01 00:00:00",
|
||||||
EndDate: "2024-07-01 23:59:59",
|
EndDate: "2024-07-01 23:59:59",
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import (
|
|||||||
// AuthConfig api鉴权参数
|
// AuthConfig api鉴权参数
|
||||||
type AuthConfig struct {
|
type AuthConfig struct {
|
||||||
Token string // 分配的token
|
Token string // 分配的token
|
||||||
|
AppId string // 应用id (getExternalChannelConfig接口返回的appId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 连接第三方平台的client
|
// 连接第三方平台的client
|
||||||
|
|||||||
@ -44,14 +44,32 @@ type OtherActivityUrl struct {
|
|||||||
ActivityUrl string `json:"activityUrl"` // 渠道方合作页地址
|
ActivityUrl string `json:"activityUrl"` // 渠道方合作页地址
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateUrlReq 生成链接的请求
|
// GenerateWechatUrlRequest 生成微信小程序链接的请求
|
||||||
type GenerateUrlRequest struct {
|
type GenerateWechatUrlRequest struct {
|
||||||
ActivityUrl string `json:"activityUrl"` // 活动url
|
ActivityUrl string `json:"activityUrl"` // 活动url
|
||||||
Uid string `json:"uid"` // 用户id
|
Uid string `json:"uid"` // 用户id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GenerateH5UrlRequest 生成H5链接请求
|
||||||
|
type GenerateH5UrlRequest struct {
|
||||||
|
ActivityUrl string `json:"activityUrl"` // 活动url
|
||||||
|
LinkCode string `json:"linkCode"` // 链接code
|
||||||
|
ActId string `json:"actId"` // 活动id
|
||||||
|
}
|
||||||
|
|
||||||
// 获取外部订单请求
|
// 获取外部订单请求
|
||||||
type QueryOrderListRequest struct {
|
type QueryOrderListRequest struct {
|
||||||
|
Trackid string `json:"trackid"` // 必传,跟踪id,排查问题使用,guid即可
|
||||||
|
BeginDate string `json:"begin_date"` // 订单更新时间查询起始,精确到秒, yyyy-MM-dd HH:mm:ss(除了传订单号外,其他查询必传)
|
||||||
|
EndDate string `json:"end_date"` // 订单更新时间查询结束,精确到秒, yyyy-MM-dd HH:mm:ss(除了传订单号外,其他查询必传)
|
||||||
|
OrderId string `json:"order_id"` // 指定订单号查询,返回该订单的最新详情
|
||||||
|
Update int32 `json:"update"` // 0:仅已支付的订单, 1:所有状态订单, 默认查所有传1
|
||||||
|
PageIndex int32 `json:"page_index"` // 分页index,从0开始(除了传订单号外,其他查询必传)
|
||||||
|
PageSize int32 `json:"page_size"` // 分页条数(除了传订单号外,其他查询必传)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取外部订单请求
|
||||||
|
type QueryOrderListReq struct {
|
||||||
AppId string `json:"appId"` // 必传,分配token查询接口提供的appId(getExternalChannelConfig接口返回的appId)
|
AppId string `json:"appId"` // 必传,分配token查询接口提供的appId(getExternalChannelConfig接口返回的appId)
|
||||||
Trackid string `json:"trackid"` // 必传,跟踪id,排查问题使用,guid即可
|
Trackid string `json:"trackid"` // 必传,跟踪id,排查问题使用,guid即可
|
||||||
BeginDate string `json:"begin_date"` // 订单更新时间查询起始,精确到秒, yyyy-MM-dd HH:mm:ss(除了传订单号外,其他查询必传)
|
BeginDate string `json:"begin_date"` // 订单更新时间查询起始,精确到秒, yyyy-MM-dd HH:mm:ss(除了传订单号外,其他查询必传)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user