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

86 lines
2.3 KiB

2 years ago
package wechatopen
import (
2 years ago
"context"
2 years ago
"encoding/json"
"fmt"
"go.dtapp.net/gorequest"
"net/http"
)
type WxaCommitResponse struct {
Errcode int `json:"errcode"`
Errmsg string `json:"errmsg"`
}
type WxaCommitResult struct {
Result WxaCommitResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
}
2 years ago
func newWxaCommitResult(result WxaCommitResponse, body []byte, http gorequest.Response) *WxaCommitResult {
return &WxaCommitResult{Result: result, Body: body, Http: http}
2 years ago
}
// WxaCommit 上传小程序代码并生成体验版
// https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/code/commit.html
2 years ago
func (c *Client) WxaCommit(ctx context.Context, notMustParams ...gorequest.Params) (*WxaCommitResult, error) {
// 检查
err := c.checkComponentIsConfig()
if err != nil {
return nil, err
}
err = c.checkAuthorizerIsConfig()
if err != nil {
return nil, err
}
2 years ago
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
2 years ago
request, err := c.request(ctx, fmt.Sprintf(apiUrl+"/wxa/commit?access_token=%s", c.GetAuthorizerAccessToken(ctx)), params, http.MethodPost)
2 years ago
if err != nil {
return nil, err
}
2 years ago
// 定义
var response WxaCommitResponse
err = json.Unmarshal(request.ResponseBody, &response)
2 years ago
if err != nil {
return nil, err
}
return newWxaCommitResult(response, request.ResponseBody, request), nil
2 years ago
}
// ErrcodeInfo 错误描述
func (resp *WxaCommitResult) ErrcodeInfo() string {
switch resp.Result.Errcode {
case 85013:
return "无效的自定义配置"
case 85014:
return "无效的模板编号"
case 85043:
return "模板错误"
case 85044:
return "代码包超过大小限制"
case 85045:
return "ext_json 有不存在的路径"
case 85046:
return "tabBar 中缺少 path"
case 85047:
return "pages 字段为空"
case 85048:
return "ext_json 解析失败"
case 80082:
return "没有权限使用该插件"
case 80067:
return "找不到使用的插件"
case 80066:
return "非法的插件版本"
case 9402202:
return "请勿频繁提交,待上一次操作完成后再提交"
case 9402203:
return `标准模板ext_json错误传了不合法的参数 如果是标准模板库的模板则ext_json支持的参数仅为{"extAppid":'', "ext": {}, "window": {}}`
}
return "系统繁忙"
}