-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.go
197 lines (188 loc) · 6.37 KB
/
code.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package wechat
import (
"strconv"
"errors"
)
var errNoJSON = errors.New("no json")
var errCode = map[int]string{
-1: "系统繁忙",
0: "请求成功",
40001: "AppSecret 错误,或者 access_token 无效",
40002: "不合法的凭证类型",
40003: "不合法的OpenID",
40004: "不合法的媒体文件类型",
40005: "不合法的文件类型",
40006: "不合法的文件大小",
40007: "不合法的媒体文件id",
40008: "不合法的消息类型",
40009: "不合法的图片文件大小",
40010: "不合法的语音文件大小",
40011: "不合法的视频文件大小",
40012: "不合法的缩略图文件大小",
40013: "不合法的 APPID",
40014: "不合法的 access_token",
40015: "不合法的菜单类型",
40016: "不合法的按钮个数",
40017: "不合法的按钮类型",
40018: "不合法的按钮名字长度",
40019: "不合法的按钮 KEY 长度",
40020: "不合法的按钮 URL 长度",
40021: "不合法的菜单版本号",
40022: "不合法的子菜单级数",
40023: "不合法的子菜单按钮个数",
40024: "不合法的子菜单按钮类型",
40025: "不合法的子菜单按钮名字长度",
40026: "不合法的子菜单按钮 KEY 长度",
40027: "不合法的子菜单按钮 URL 长度",
40028: "不合法的自定义菜单使用用户",
40029: "不合法的 oauth_code",
40030: "不合法的 refresh_token",
40031: "不合法的 openid 列表",
40032: "不合法的 openid 列表长度/每次传入的 openid 列表个数不能超过50个",
40033: "不合法的请求字符,不能包含 \\uxxxx 格式的字符",
40035: "不合法的参数",
40038: "不合法的请求格式",
40039: "不合法的 URL 长度",
40050: "不合法的分组 id",
40051: "分组名字不合法",
40066: "不合法的 url",
40099: "该 code 已被核销",
40226: "高风险等级用户,登录拦截",
41001: "缺少 access_token 参数",
40125: "appsecret 无效",
45011: "频率限制,每个用户每分钟100次",
40130: "参数错误",
41002: "缺少 appid 参数",
41003: "缺少 refresh_token 参数",
41004: "缺少 secret 参数",
41005: "缺少多媒体文件数据",
41006: "缺少 media_id 参数",
41007: "缺少子菜单数据",
41008: "缺少 oauth code",
41009: "缺少 openid",
42001: "access_token 超时",
42002: "refresh_token 超时",
42003: "oauth_code 超时",
42005: "调用接口频率超过上限",
43001: "需要 GET 请求",
43002: "需要 POST 请求",
43003: "需要 HTTPS 请求",
43004: "需要接收者关注",
43005: "需要好友关系",
44001: "多媒体文件为空",
44002: "POST 的数据包为空",
44003: "图文消息内容为空",
44004: "文本消息内容为空",
45001: "多媒体文件大小超过限制",
45002: "消息内容超过限制",
45003: "标题字段超过限制",
45004: "描述字段超过限制",
45005: "链接字段超过限制",
45006: "图片链接字段超过限制",
45007: "语音播放时间超过限制",
45008: "图文消息超过限制",
45009: "接口调用超过限制",
45010: "创建菜单个数超过限制",
45015: "回复时间超过限制",
45016: "系统分组,不允许修改",
45017: "分组名字过长",
45018: "分组数量超过上限",
45024: "账号数量超过上限",
45157: "标签名非法,请注意不能和其他标签重名",
45158: "标签名长度超过30个字节",
45056: "创建的标签数过多,请注意不能超过100个",
45058: "不能修改0/1/2这三个系统默认保留的标签",
45057: "该标签下粉丝数超过10w,不允许直接删除",
45059: "有粉丝身上的标签数已经超过限制",
45159: "非法的 tag_id",
46001: "不存在媒体数据",
46002: "不存在的菜单版本",
46003: "不存在的菜单数据",
46004: "不存在的用户",
47001: "解析 JSON/XML 内容错误",
48001: "api功能未授权",
48002: "粉丝拒收消息",
48004: "api 接口被封禁",
48005: "api 禁止删除被自动回复和自定义菜单引用的素材",
48006: "api 禁止清零调用次数,因为清零次数达到上限",
48008: "没有该类型消息的发送权限",
49003: "传入的 openid 不属于此 AppID",
50001: "用户未授权该 api",
50002: "用户受限,可能是违规后接口被封禁",
50005: "用户未关注公众号",
61450: "系统错误",
61451: "参数错误",
61452: "无效客服账号",
61453: "账号已存在",
61454: "客服帐号名长度超过限制(仅允许10个英文字符,不包括@及@后的公众号的微信号)",
61455: "客服账号名包含非法字符(英文+数字)",
61456: "客服账号个数超过限制(10个客服账号)",
61457: "无效头像文件类型",
61458: "客户正在被其他客服接待",
61459: "客服不在线",
61500: "日期格式错误",
61501: "日期范围错误",
7000000: "请求正常,无语义结果",
7000001: "缺失请求参数",
7000002: "signature 参数无效",
7000003: "地理位置相关配置 1 无效",
7000004: "地理位置相关配置 2 无效",
7000005: "请求地理位置信息失败",
7000006: "地理位置结果解析失败",
7000007: "内部初始化失败",
7000008: "非法 appid(获取密钥失败)",
7000009: "请求语义服务失败",
7000010: "非法 post 请求",
7000011: "post 请求 json 字段无效",
7000030: "查询 query 太短",
7000031: "查询 query 太长",
7000032: "城市、经纬度信息缺失",
7000033: "query 请求语义处理失败",
7000034: "获取天气信息失败",
7000035: "获取股票信息失败",
7000036: "utf8 编码转换失败",
}
func code2Str(code int) string {
s, _ := errCode[code]
return s
}
type httpError struct {
Code int
Msg string
}
func (e httpError) Error() string {
return e.Msg
}
func (e httpError) message() (msg string) {
msg = code2Str(e.Code)
if msg == "" {
msg = strconv.Itoa(e.Code) + " " + e.Msg
}
return
}
// ErrorMsg Get error information
func ErrorMsg(err error) string {
if err == nil {
return ""
}
e, ok := err.(httpError)
if ok {
return e.message()
}
s := err.Error()
if s == "" {
return "未知错误"
}
return s
}
// ErrorCode Get error code
func ErrorCode(err error) int {
if err == nil {
return -1
}
e, ok := err.(httpError)
if ok {
return e.Code
}
return -1
}