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.
wechatopen/cgi-bin.component.setprivac...

72 lines
2.3 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 wechatopen
import (
"context"
"encoding/json"
"fmt"
"go.dtapp.net/gorequest"
"net/http"
)
type CgiBinComponentSetPrivacySettingResponse struct {
Errcode int `json:"errcode"` // 返回码
Errmsg string `json:"errmsg"` // 返回码信息
}
type CgiBinComponentSetPrivacySettingResult struct {
Result CgiBinComponentSetPrivacySettingResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
}
func newCgiBinComponentSetPrivacySettingResult(result CgiBinComponentSetPrivacySettingResponse, body []byte, http gorequest.Response) *CgiBinComponentSetPrivacySettingResult {
return &CgiBinComponentSetPrivacySettingResult{Result: result, Body: body, Http: http}
}
// CgiBinComponentSetPrivacySetting 配置小程序用户隐私保护指引
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/privacy_config/set_privacy_setting.html
func (c *Client) CgiBinComponentSetPrivacySetting(ctx context.Context, notMustParams ...gorequest.Params) (*CgiBinComponentSetPrivacySettingResult, error) {
// 检查
err := c.checkComponentIsConfig()
if err != nil {
return nil, err
}
err = c.checkAuthorizerIsConfig()
if err != nil {
return nil, err
}
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/cgi-bin/component/setprivacysetting?access_token=%s", c.GetAuthorizerAccessToken(ctx)), params, http.MethodPost)
if err != nil {
return nil, err
}
// 定义
var response CgiBinComponentSetPrivacySettingResponse
err = json.Unmarshal(request.ResponseBody, &response)
if err != nil {
return nil, err
}
return newCgiBinComponentSetPrivacySettingResult(response, request.ResponseBody, request), nil
}
// ErrcodeInfo 错误描述
func (resp *CgiBinComponentSetPrivacySettingResult) ErrcodeInfo() string {
switch resp.Result.Errcode {
case 86069:
return "owner_setting必填字段字段缺失"
case 86070:
return "notice_method必填字段字段缺失"
case 86072:
return "store_expire_timestamp参数无效。如果是编码格式不对也会报这个错"
case 86073:
return "ext_file_media_id参数无效"
case 86074:
return "现网隐私协议不存在"
case 86075:
return "现网隐私协议的ext_file_media_id禁止修改"
}
return "系统繁忙"
}