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

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package wechatunion
import (
"context"
"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 // 错误
}
func newPromotionAddResult(result PromotionAddResponse, body []byte, http gorequest.Response, err error) *PromotionAddResult {
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
func (c *Client) PromotionAdd(ctx context.Context, promotionSourceName string) *PromotionAddResult {
// 参数
params := gorequest.NewParams()
params.Set("promotionSourceName", promotionSourceName) // 推广位名称
// 请求
request, err := c.request(ctx, apiUrl+fmt.Sprintf("/promoter/promotion/add?access_token%s", c.getAccessToken(ctx)), params, http.MethodPost)
// 定义
var response PromotionAddResponse
err = json.Unmarshal(request.ResponseBody, &response)
return newPromotionAddResult(response, request.ResponseBody, request, err)
}