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.
wechatunion/promoter.promotion.add.go

41 lines
1.4 KiB

2 years ago
package wechatunion
import (
2 years ago
"context"
2 years ago
"encoding/json"
"fmt"
"go.dtapp.net/gorequest"
"net/http"
)
type PromotionAddResponse struct {
Errcode int `json:"errcode"` // 错误码
Errmsg string `json:"errmsg"` // 错误信息
Pid string `json:"pid"` // 推广位IDPID
}
type PromotionAddResult struct {
Result PromotionAddResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
Err error // 错误
}
2 years ago
func newPromotionAddResult(result PromotionAddResponse, body []byte, http gorequest.Response, err error) *PromotionAddResult {
2 years ago
return &PromotionAddResult{Result: result, Body: body, Http: http, Err: err}
}
// PromotionAdd 添加推广位
// https://developers.weixin.qq.com/doc/ministore/union/access-guidelines/promoter/api/promotion.html#_1-%E6%B7%BB%E5%8A%A0%E6%8E%A8%E5%B9%BF%E4%BD%8D
2 years ago
func (c *Client) PromotionAdd(ctx context.Context, promotionSourceName string) *PromotionAddResult {
2 years ago
// 参数
2 years ago
params := gorequest.NewParams()
2 years ago
params.Set("promotionSourceName", promotionSourceName) // 推广位名称
// 请求
2 years ago
request, err := c.request(ctx, apiUrl+fmt.Sprintf("/promoter/promotion/add?access_token%s", c.getAccessToken(ctx)), params, http.MethodPost)
2 years ago
// 定义
var response PromotionAddResponse
err = json.Unmarshal(request.ResponseBody, &response)
2 years ago
return newPromotionAddResult(response, request.ResponseBody, request, err)
2 years ago
}