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.deletetemplate.go

59 lines
1.7 KiB

2 years ago
package wechatopen
import (
2 years ago
"context"
2 years ago
"encoding/json"
"fmt"
"go.dtapp.net/gorequest"
"net/http"
)
type WxaDeleteTemplateResponse struct {
Errcode int `json:"errcode"`
Errmsg string `json:"errmsg"`
}
type WxaDeleteTemplateResult struct {
Result WxaDeleteTemplateResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
}
2 years ago
func newWxaDeleteTemplateResult(result WxaDeleteTemplateResponse, body []byte, http gorequest.Response) *WxaDeleteTemplateResult {
return &WxaDeleteTemplateResult{Result: result, Body: body, Http: http}
2 years ago
}
// WxaDeleteTemplate 删除指定代码模板
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/code_template/deletetemplate.html
2 years ago
func (c *Client) WxaDeleteTemplate(ctx context.Context, templateId string) (*WxaDeleteTemplateResult, error) {
// 检查
err := c.checkComponentIsConfig()
if err != nil {
return nil, err
}
2 years ago
// 参数
2 years ago
params := gorequest.NewParams()
2 years ago
params.Set("template_id", templateId)
// 请求
2 years ago
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/wxa/deletetemplate?access_token=%s", c.GetComponentAccessToken(ctx)), params, http.MethodPost)
2 years ago
if err != nil {
return nil, err
}
2 years ago
// 定义
var response WxaDeleteTemplateResponse
err = json.Unmarshal(request.ResponseBody, &response)
2 years ago
if err != nil {
return nil, err
}
return newWxaDeleteTemplateResult(response, request.ResponseBody, request), nil
2 years ago
}
// ErrcodeInfo 错误描述
func (resp *WxaDeleteTemplateResult) ErrcodeInfo() string {
switch resp.Result.Errcode {
case 85064:
return "找不到模板请检查模板id是否输入正确"
}
return "系统繁忙"
}