You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
meituan/api.generate_link.go

47 lines
1.9 KiB

2 years ago
package meituan
import (
2 years ago
"context"
2 years ago
"encoding/json"
"go.dtapp.net/gorequest"
"net/http"
)
type ApiGenerateLinkResponse struct {
Status int `json:"status"` // 状态值0为成功非0为异常
Des string `json:"des,omitempty"` // 异常描述信息
Data string `json:"data,omitempty"` // 最终的推广链接
}
type ApiGenerateLinkResult struct {
Result ApiGenerateLinkResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
Err error // 错误
}
2 years ago
func newApiGenerateLinkResult(result ApiGenerateLinkResponse, body []byte, http gorequest.Response, err error) *ApiGenerateLinkResult {
2 years ago
return &ApiGenerateLinkResult{Result: result, Body: body, Http: http, Err: err}
}
// ApiGenerateLink 自助取链接口(新版)
// https://union.meituan.com/v2/apiDetail?id=25
2 years ago
func (c *Client) ApiGenerateLink(ctx context.Context, actId int64, sid string, linkType, shortLink int) *ApiGenerateLinkResult {
2 years ago
// 参数
param := gorequest.NewParams()
2 years ago
param.Set("actId", actId) // 活动id可以在联盟活动列表中查看获取
param.Set("appkey", c.GetAppKey()) // 媒体名称,可在推广者备案-媒体管理中查询
param.Set("sid", sid) // 推广位sid支持通过接口自定义创建不受平台200个上限限制长度不能超过64个字符支持小写字母和数字历史已创建的推广位不受这个约束
param.Set("linkType", linkType) // 投放链接的类型
param.Set("shortLink", shortLink) // 获取长链还是短链
2 years ago
// 转换
params := gorequest.NewParamsWith(param)
2 years ago
params["sign"] = c.getSign(c.GetSecret(), params)
2 years ago
// 请求
2 years ago
request, err := c.request(ctx, apiUrl+"/api/generateLink", params, http.MethodGet)
2 years ago
// 定义
var response ApiGenerateLinkResponse
err = json.Unmarshal(request.ResponseBody, &response)
2 years ago
return newApiGenerateLinkResult(response, request.ResponseBody, request, err)
2 years ago
}