Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

加入一些小程序的错误码 #825

Merged
merged 6 commits into from
Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Please refer to [【代码贡献指南】](contribution.md).
2 changes: 1 addition & 1 deletion demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
1. 开放平台Demo:[GitHub](http://github.com/Wechat-Group/weixin-java-open-demo)、[码云](http://gitee.com/binary/weixin-java-open-demo)
1. 公众号Demo:
- 使用Spring MVC实现的公众号Demo:[GitHub](http://github.com/binarywang/weixin-java-mp-demo-springmvc)、[码云](https://gitee.com/binary/weixin-java-mp-demo)
- 使用Spring Boot实现的公众号Demo:[GitHub](http://github.com/binarywang/weixin-java-mp-demo-springboot)、[码云](http://gitee.com/binary/weixin-java-mp-demo-springboot)
- 使用Spring Boot实现的公众号Demo(支持多公众号):[GitHub](http://github.com/binarywang/weixin-java-mp-demo-springboot)、[码云](http://gitee.com/binary/weixin-java-mp-demo-springboot)
- 含公众号和部分微信支付代码的Demo:[GitHub](http://github.com/Wechat-Group/weixin-java-tools-springmvc)、[码云](http://gitee.com/binary/weixin-java-tools-springmvc)
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<httpclient.version>4.5</httpclient.version>
<jetty.version>9.3.0.RC0</jetty.version>
<jetty.version>9.3.24.v20180605</jetty.version>
</properties>

<dependencyManagement>
Expand Down
5 changes: 3 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## 全能微信Java开发工具包(SDK)
#### 支持包括微信支付、开放平台、公众号、企业微信/企业号、小程序等微信功能的后端开发。
---------------------------------
[![码云Gitee](https://gitee.com/binary/weixin-java-tools/badge/star.svg?theme=blue)](https://gitee.com/binary/weixin-java-tools)
[![Github](https://img.shields.io/badge/Github-10k+-green.svg)](https://github.com/Wechat-Group/weixin-java-tools)
[![码云Gitee](https://gitee.com/binary/weixin-java-tools/badge/star.svg?theme=blue)](https://gitee.com/binary/weixin-java-tools)
[![Github](http://github-svg-buttons.herokuapp.com/star.svg?user=Wechat-Group&repo=weixin-java-tools&style=flat&background=1081C1)](https://github.com/Wechat-Group/weixin-java-tools)
[![Maven Central](https://img.shields.io/maven-central/v/com.github.binarywang/weixin-java-parent.svg)](http://mvnrepository.com/artifact/com.github.binarywang/weixin-java-parent)
[![Build Status](https://travis-ci.org/Wechat-Group/weixin-java-tools.svg?branch=develop)](https://travis-ci.org/Wechat-Group/weixin-java-tools)
[![使用IntelliJ IDEA开发维护](https://img.shields.io/badge/IntelliJ%20IDEA-提供支持-blue.svg)](https://www.jetbrains.com/idea/)
Expand Down Expand Up @@ -47,6 +47,7 @@
1. 公众号和小程序:民医台(可自行搜索)
1. 洽洽企业号
1. 高善人力资源
1. 小程序:树懒揽书+
1. 其他更多案例请[【访问这里】](https://github.com/Wechat-Group/weixin-java-tools/issues/729),持续更新中。

---------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public static WxError fromJson(String json, WxType type) {
if (msg != null) {
wxError.setErrorMsg(msg);
}
} else if (type == WxType.MiniApp) {
final String msg = WxMiniappErrorMsgEnum.findMsgByCode(wxError.getErrorCode());
if (msg != null) {
wxError.setErrorMsg(msg);
}
}

return wxError;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
package me.chanjar.weixin.common.error;

import lombok.Getter;

/**
* 微信小程序错误码
* @author <a href="https://github.com/biggates">biggates</a>
*/
@Getter
public enum WxMiniappErrorMsgEnum {
/**
* 获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的小程序调用接口
* <p>对应操作:<code>sendCustomerMessage</code></p>
* <p>对应地址:
* <pre>POST https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN</pre>
* </p>
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/customer-message/sendCustomerMessage.html
*/
CODE_40001(40001, "access_token 无效或 AppSecret 错误"),
/**
* 不合法的凭证类型
* <p>对应操作:<code>sendCustomerMessage</code></p>
* <p>对应地址:
* <pre>POST https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN</pre>
* </p>
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/customer-message/sendCustomerMessage.html
*/
CODE_40002(40002, "不合法的凭证类型"),
/**
* touser不是正确的openid
* <p>对应操作:<code>sendCustomerMessage</code>, <code>sendUniformMessage</code></p>
* <p>对应地址:
* <pre>POST https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN</pre>
* <pre>POST https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=ACCESS_TOKEN</pre>
* </p>
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/customer-message/sendCustomerMessage.html
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/uniform-message/sendUniformMessage.html
*/
CODE_40003(40003, "openid 不正确"),
/**
* 无效媒体文件类型
* <p>对应操作:<code>uploadTempMedia</code></p>
* <p>对应地址:
* <pre>POST https://api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=TYPE</pre>
* </p>
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/customer-message/uploadTempMedia.html
*/
CODE_40004(40004, "无效媒体文件类型"),
/**
* 无效媒体文件 ID
* <p>对应操作:<code>getTempMedia</code></p>
* <p>对应地址:
* <pre>GET https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID</pre>
* </p>
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/customer-message/getTempMedia.html
*/
CODE_40007(40007, "无效媒体文件 ID"),
/**
* appid不正确,或者不符合绑定关系要求
* <p>对应操作:<code>sendUniformMessage</code></p>
* <p>对应地址:
* <pre>POST https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=ACCESS_TOKEN</pre>
* </p>
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/uniform-message/sendUniformMessage.html
*/
CODE_40013(40013, "appid不正确,或者不符合绑定关系要求"),
/**
* template_id 不正确
* <p>对应操作:<code>sendUniformMessage</code>, <code>sendTemplateMessage</code></p>
* <p>对应地址:
* <pre>POST https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=ACCESS_TOKEN</pre>
* <pre>POST https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=ACCESS_TOKEN</pre>
* </p>
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/uniform-message/sendUniformMessage.html
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/template-message/sendTemplateMessage.html
*/
CODE_40037(40037, "template_id 不正确"),
/**
* form_id不正确,或者过期
* <p>对应操作:<code>sendUniformMessage</code>, <code>sendTemplateMessage</code></p>
* <p>对应地址:
* <pre>POST https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=ACCESS_TOKEN</pre>
* <pre>POST https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=ACCESS_TOKEN</pre>
* </p>
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/uniform-message/sendUniformMessage.html
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/template-message/sendTemplateMessage.html
*/
CODE_41028(41028, "form_id 不正确,或者过期"),
/**
* code 或 template_id 不正确
* <p>对应操作:<code>code2Session</code>, <code>sendUniformMessage</code>, <code>sendTemplateMessage</code></p>
* <p>对应地址:
* <pre>GET https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code</pre>
* <pre>POST https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=ACCESS_TOKEN</pre>
* <pre>POST https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=ACCESS_TOKEN</pre>
* </p>
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/login/code2Session.html
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/uniform-message/sendUniformMessage.html
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/template-message/sendTemplateMessage.html
*/
CODE_41029(41029, "请求的参数不正确"),
/**
* form_id 已被使用,或者所传page页面不存在,或者小程序没有发布
* <p>对应操作:<code>sendUniformMessage</coce>, <code>getWXACodeUnlimit</code></p>
* <p>对应地址:
* <pre>POST https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=ACCESS_TOKEN</pre>
* <pre>POST https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=ACCESS_TOKEN</pre>
* </p>
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/uniform-message/sendUniformMessage.html
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/qr-code/getWXACodeUnlimit.html
*/
CODE_41030(41030, "请求的参数不正确"),
/**
* 调用分钟频率受限
* <p>对应操作:<code>getWXACodeUnlimit</code>, <code>sendUniformMessage</coce>, <code>sendTemplateMessage</code></p>
* <p>对应地址:
* <pre>POST https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=ACCESS_TOKEN</pre>
* <pre>POST https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=ACCESS_TOKEN</pre>
* <pre>POST https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=ACCESS_TOKEN</pre>
* </p>
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/uniform-message/sendUniformMessage.html
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/qr-code/getWXACodeUnlimit.html
*/
CODE_45009(45009, "调用分钟频率受限"),
/**
* 频率限制,每个用户每分钟100次
* <p>对应操作:<code>code2Session</code></p>
* <p>对应地址:
* <pre>GET https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code</pre>
* </p>
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/login/code2Session.html
*/
CODE_45011(45011, "频率限制,每个用户每分钟100次"),
/**
* 回复时间超过限制
* <p>对应操作:<code>sendCustomerMessage</code></p>
* <p>对应地址:
* <pre>POST https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN</pre>
* </p>
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/customer-message/sendCustomerMessage.html
*/
CODE_45015(45015, "回复时间超过限制"),
/**
* 接口调用超过限额, 或生成码个数总和到达最大个数限制
* <p>对应操作:<code>createWXAQRCode</code>, <code>sendTemplateMessage</code></p>
* <p>对应地址:
* <pre>POST https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=ACCESS_TOKEN</pre>
* <pre>POST https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=ACCESS_TOKEN</pre>
* </p>
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/qr-code/getWXACode.html
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/template-message/sendTemplateMessage.html
*/
CODE_45029(45029, "接口调用超过限额"),
/**
* 客服接口下行条数超过上限
* <p>对应操作:<code>sendCustomerMessage</code></p>
* <p>对应地址:
* <pre>POST https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN</pre>
* </p>
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/customer-message/sendCustomerMessage.html
*/
CODE_45047(45047, "客服接口下行条数超过上限"),
/**
* command字段取值不对
* <p>对应操作:<code>customerTyping</code>
* <p>对应地址:
* <pre>POST https://api.weixin.qq.com/cgi-bin/message/custom/typing?access_token=ACCESS_TOKEN</pre>
* </p>
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/customer-message/customerTyping.html
*/
CODE_45072(45072, "command字段取值不对"),
/**
* 下发输入状态,需要之前30秒内跟用户有过消息交互
* <p>对应操作:<code>customerTyping</code>
* <p>对应地址:
* <pre>POST https://api.weixin.qq.com/cgi-bin/message/custom/typing?access_token=ACCESS_TOKEN</pre>
* </p>
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/customer-message/customerTyping.html
*/
CODE_45080(45080, "下发输入状态,需要之前30秒内跟用户有过消息交互"),
/**
* 已经在输入状态,不可重复下发
* <p>对应操作:<code>customerTyping</code>
* <p>对应地址:
* <pre>POST https://api.weixin.qq.com/cgi-bin/message/custom/typing?access_token=ACCESS_TOKEN</pre>
* </p>
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/customer-message/customerTyping.html
*/
CODE_45081(45081, "已经在输入状态,不可重复下发"),
/**
* API 功能未授权,请确认小程序已获得该接口
* <p>对应操作:<code>sendCustomerMessage</code></p>
* <p>对应地址:
* <pre>POST https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN</pre>
* </p>
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/customer-message/sendCustomerMessage.html
*/
CODE_48001(48001, "API 功能未授权"),
/**
* 内容含有违法违规内容
* <p>对应操作:<code>imgSecCheck</code>, <code>msgSecCheck</code></p>
* <p>对应地址:
* <pre>POST https://api.weixin.qq.com/wxa/img_sec_check?access_token=ACCESS_TOKEN</pre>
* <pre>POST https://api.weixin.qq.com/wxa/msg_sec_check?access_token=ACCESS_TOKEN</pre>
* </p>
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/sec-check/imgSecCheck.html
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/sec-check/msgSecCheck.html
*/
CODE_87014(87014, "内容含有违法违规内容"),
;

private int code;
private String msg;

WxMiniappErrorMsgEnum(int code, String msg) {
this.code = code;
this.msg = msg;
}

/**
* 通过错误代码查找其中文含义.
*/
public static String findMsgByCode(int code) {
WxMiniappErrorMsgEnum[] values = WxMiniappErrorMsgEnum.values();
for (WxMiniappErrorMsgEnum value : values) {
if (value.code == code) {
return value.msg;
}
}

return null;
}
}