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/wxa.gettemplatelist.go

71 lines
2.6 KiB

2 years ago
package wechatopen
import (
2 years ago
"context"
2 years ago
"encoding/json"
"fmt"
"go.dtapp.net/gorequest"
"net/http"
)
type WxaGetTemplateListResponse struct {
Errcode int `json:"errcode"`
Errmsg string `json:"errmsg"`
TemplateList []struct {
CreateTime int `json:"create_time"` // 被添加为模板的时间
UserVersion string `json:"user_version"` // 模板版本号,开发者自定义字段
UserDesc string `json:"user_desc"` // 模板描述,开发者自定义字段
TemplateId int64 `json:"template_id"` // 模板 id
TemplateType int `json:"template_type"` // 0对应普通模板1对应标准模板
SourceMiniprogramAppid string `json:"source_miniprogram_appid"` // 开发小程序的appid
SourceMiniprogram string `json:"source_miniprogram"` // 开发小程序的名称
Developer string `json:"developer"` // 开发者
CategoryList []interface{} `json:"category_list"`
} `json:"template_list"` // 模板信息列表
}
type WxaGetTemplateListResult struct {
Result WxaGetTemplateListResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
}
2 years ago
func newWxaGetTemplateListResult(result WxaGetTemplateListResponse, body []byte, http gorequest.Response) *WxaGetTemplateListResult {
return &WxaGetTemplateListResult{Result: result, Body: body, Http: http}
2 years ago
}
// WxaGetTemplateList 获取代码模板列表
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/code_template/gettemplatelist.html
2 years ago
func (c *Client) WxaGetTemplateList(ctx context.Context) (*WxaGetTemplateListResult, error) {
// 检查
err := c.checkComponentIsConfig()
if err != nil {
return nil, err
}
// 参数
params := gorequest.NewParams()
2 years ago
// 请求
2 years ago
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/wxa/gettemplatelist?access_token=%s", c.GetComponentAccessToken(ctx)), params, http.MethodGet)
if err != nil {
return nil, err
}
2 years ago
// 定义
var response WxaGetTemplateListResponse
err = json.Unmarshal(request.ResponseBody, &response)
2 years ago
if err != nil {
return nil, err
}
return newWxaGetTemplateListResult(response, request.ResponseBody, request), nil
2 years ago
}
// ErrcodeInfo 错误描述
func (resp *WxaGetTemplateListResult) ErrcodeInfo() string {
switch resp.Result.Errcode {
case 43001:
return "请使用GET不要使用post"
case 85064:
return "找不到模板"
}
return "系统繁忙"
}