修改weixin4j ,使其更适用于wyying
This commit is contained in:
parent
fe8166d1a4
commit
a874973428
@ -2,65 +2,82 @@ package com.foxinmy.weixin4j.exception;
|
||||
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
import com.foxinmy.weixin4j.util.WeixinErrorUtil;
|
||||
import com.foxinmy.weixin4j.util.WeixinErrorUtil2;
|
||||
|
||||
/**
|
||||
* 调用微信接口抛出的异常
|
||||
*
|
||||
* @className WeixinException
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @className WeixinException
|
||||
* @date 2014年4月10日
|
||||
* @since JDK 1.6
|
||||
* @see
|
||||
* @since JDK 1.6
|
||||
*/
|
||||
public class WeixinException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 7148145661883468514L;
|
||||
private static final long serialVersionUID = 7148145661883468514L;
|
||||
|
||||
private String code;
|
||||
private String desc;
|
||||
private String code;
|
||||
private String desc;
|
||||
private String describeErrorMsg;
|
||||
|
||||
public WeixinException(String code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
public WeixinException(String code, String desc) {
|
||||
this(code, desc, null);
|
||||
}
|
||||
|
||||
public WeixinException(String desc) {
|
||||
this.code = "-1";
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public WeixinException(Throwable e) {
|
||||
super(e);
|
||||
}
|
||||
public WeixinException(String errorCode, String errorMsg, String describeErrorMsg) {
|
||||
this.code = errorCode;
|
||||
this.desc = errorMsg;
|
||||
if (describeErrorMsg == null) {
|
||||
this.describeErrorMsg = errorMsg;
|
||||
} else {
|
||||
this.describeErrorMsg = describeErrorMsg;
|
||||
}
|
||||
}
|
||||
|
||||
public WeixinException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
public WeixinException(String desc) {
|
||||
this.code = "-1";
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getErrorCode() {
|
||||
return code;
|
||||
}
|
||||
public String getDescribeErrorMsg() {
|
||||
return describeErrorMsg;
|
||||
}
|
||||
|
||||
public String getErrorDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public String getErrorText() {
|
||||
return WeixinErrorUtil.getText(code);
|
||||
}
|
||||
public WeixinException(Throwable e) {
|
||||
super(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
if (StringUtil.isNotBlank(code)) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(code).append(" >> ").append(desc);
|
||||
String text = getErrorText();
|
||||
if (StringUtil.isNotBlank(text)) {
|
||||
buf.append(" >> ").append(text);
|
||||
}
|
||||
return buf.toString();
|
||||
} else {
|
||||
return super.getMessage();
|
||||
}
|
||||
}
|
||||
public WeixinException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public String getErrorCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getErrorDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public String getErrorText() {
|
||||
return WeixinErrorUtil2.getText(code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
if (StringUtil.isNotBlank(code)) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(code).append(" >> ").append(desc);
|
||||
String text = getErrorText();
|
||||
if (StringUtil.isNotBlank(text)) {
|
||||
buf.append(" >> ").append(text);
|
||||
}
|
||||
return buf.toString();
|
||||
} else {
|
||||
return super.getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,21 +28,24 @@ import com.foxinmy.weixin4j.http.message.XmlMessageConverter;
|
||||
import com.foxinmy.weixin4j.logging.InternalLogLevel;
|
||||
import com.foxinmy.weixin4j.logging.InternalLogger;
|
||||
import com.foxinmy.weixin4j.logging.InternalLoggerFactory;
|
||||
|
||||
|
||||
import com.foxinmy.weixin4j.util.Consts;
|
||||
import com.foxinmy.weixin4j.util.WeixinErrorUtil2;
|
||||
|
||||
/**
|
||||
* 负责微信请求的执行
|
||||
*
|
||||
* @author jy
|
||||
* @className WeixinRequestExecutor
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2015年8月15日
|
||||
* @since JDK 1.6
|
||||
* @see
|
||||
* @since JDK 1.6
|
||||
*/
|
||||
public class WeixinRequestExecutor {
|
||||
|
||||
protected final InternalLogger logger = InternalLoggerFactory
|
||||
.getInstance(getClass());
|
||||
protected final InternalLogger logger = InternalLoggerFactory.getInstance(getClass());
|
||||
|
||||
private static final String SUCCESS_CODE = ",0,success,";
|
||||
|
||||
@ -58,7 +61,7 @@ public class WeixinRequestExecutor {
|
||||
|
||||
/**
|
||||
* Post方法执行微信请求
|
||||
*
|
||||
*
|
||||
* @param url
|
||||
* 请求URL
|
||||
* @param body
|
||||
@ -75,7 +78,7 @@ public class WeixinRequestExecutor {
|
||||
|
||||
/**
|
||||
* Post方法执行微信请求,用于文件上传
|
||||
*
|
||||
*
|
||||
* @param url
|
||||
* 请求URL
|
||||
* @param bodyParts
|
||||
@ -97,7 +100,7 @@ public class WeixinRequestExecutor {
|
||||
|
||||
/**
|
||||
* Get方法执行微信请求
|
||||
*
|
||||
*
|
||||
* @param url
|
||||
* 请求URL,如:https://api.weixin.qq.com/cgi-bin/token
|
||||
* @param parameters
|
||||
@ -118,7 +121,7 @@ public class WeixinRequestExecutor {
|
||||
|
||||
/**
|
||||
* 执行微信请求
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
* 微信请求
|
||||
* @return 微信响应
|
||||
@ -130,6 +133,9 @@ public class WeixinRequestExecutor {
|
||||
logger.debug("weixin request >> " + request.getMethod() + " "
|
||||
+ request.getURI().toString());
|
||||
}
|
||||
if(request.getEntity() instanceof StringEntity){
|
||||
logger.debug("weixin request body >> " + ((StringEntity) request.getEntity()).getContentString());
|
||||
}
|
||||
HttpResponse httpResponse = httpClient.execute(request);
|
||||
WeixinResponse response = new WeixinResponse(httpResponse);
|
||||
handleResponse(response);
|
||||
@ -141,7 +147,7 @@ public class WeixinRequestExecutor {
|
||||
|
||||
/**
|
||||
* 响应内容是否为流
|
||||
*
|
||||
*
|
||||
* @param response
|
||||
* 微信响应
|
||||
* @return true/false
|
||||
@ -159,7 +165,7 @@ public class WeixinRequestExecutor {
|
||||
|
||||
/**
|
||||
* handle the weixin response
|
||||
*
|
||||
*
|
||||
* @param response
|
||||
* 微信请求响应
|
||||
* @throws WeixinException
|
||||
@ -182,7 +188,7 @@ public class WeixinRequestExecutor {
|
||||
if (!SUCCESS_CODE.contains(String.format(",%s,", result.getReturnCode()
|
||||
.toLowerCase()))) {
|
||||
throw new WeixinException(result.getReturnCode(),
|
||||
result.getReturnMsg());
|
||||
result.getReturnMsg(),WeixinErrorUtil2.getText(result.getReturnCode()));
|
||||
}
|
||||
if (XmlMessageConverter.GLOBAL.canConvert(XmlResult.class, response)) {
|
||||
try {
|
||||
@ -191,7 +197,7 @@ public class WeixinRequestExecutor {
|
||||
if (!SUCCESS_CODE.contains(String.format(",%s,", xmlResult
|
||||
.getResultCode().toLowerCase()))) {
|
||||
throw new WeixinException(xmlResult.getErrCode(),
|
||||
xmlResult.getErrCodeDes());
|
||||
xmlResult.getErrCodeDes(),WeixinErrorUtil2.getText(xmlResult.getErrCode()));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
;
|
||||
@ -205,7 +211,7 @@ public class WeixinRequestExecutor {
|
||||
|
||||
/**
|
||||
* 创建 SSL微信请求对象
|
||||
*
|
||||
*
|
||||
* @param password
|
||||
* 加载密钥
|
||||
* @param inputStream
|
||||
|
||||
@ -2,14 +2,16 @@
|
||||
<!-- 公众平台错误码:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433747234&token=&lang=zh_CN -->
|
||||
<!-- 企业号错误码:http://qydev.weixin.qq.com/wiki/index.php?title=%E5%85%A8%E5%B1%80%E8%BF%94%E5%9B%9E%E7%A0%81%E8%AF%B4%E6%98%8E -->
|
||||
<errors>
|
||||
<error>
|
||||
<code>-1</code>
|
||||
<text>系统繁忙,请稍后再试</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>0</code>
|
||||
<text>请求成功</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>-1</code>
|
||||
<desc>system error</desc>
|
||||
<text>微信系统繁忙,请稍候再试</text>
|
||||
</error>
|
||||
<!-- 公众平台&企业号API错误 -->
|
||||
<error>
|
||||
<code>40001</code>
|
||||
<text>获取access_token时AppSecret错误,或者access_token无效</text>
|
||||
@ -36,7 +38,8 @@
|
||||
</error>
|
||||
<error>
|
||||
<code>40007</code>
|
||||
<text>无效的media_id</text>
|
||||
<desc>invalid media_id</desc>
|
||||
<text>请检查您的素材!</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>40008</code>
|
||||
@ -133,7 +136,7 @@
|
||||
</error>
|
||||
<error>
|
||||
<code>40031</code>
|
||||
<text>不合法的openid列表</text>
|
||||
<text>不合法的粉丝列表</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>40032</code>
|
||||
@ -339,6 +342,10 @@
|
||||
<code>40116</code>
|
||||
<text>不合法的Code码。</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>40113</code>
|
||||
<text>不支持的文件类型</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>40117</code>
|
||||
<text>分组名字不合法</text>
|
||||
@ -375,6 +382,15 @@
|
||||
<code>40132</code>
|
||||
<text>微信号不合法</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>40130</code>
|
||||
<text>最少选择两名粉丝</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>40132</code>
|
||||
<desc>invalid username</desc>
|
||||
<text>无效的微信号</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>40137</code>
|
||||
<text>不支持的图片格式</text>
|
||||
@ -533,7 +549,8 @@
|
||||
</error>
|
||||
<error>
|
||||
<code>43004</code>
|
||||
<text>需要接收者关注</text>
|
||||
<desc>require subscribe</desc>
|
||||
<text>未关注公众号</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>43005</code>
|
||||
@ -593,19 +610,23 @@
|
||||
</error>
|
||||
<error>
|
||||
<code>45001</code>
|
||||
<text>多媒体文件大小超过限制</text>
|
||||
<desc>media size out of limit</desc>
|
||||
<text>多媒体文件大小超过微信限制</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>45002</code>
|
||||
<text>消息内容超过限制</text>
|
||||
<desc>content size out of limit</desc>
|
||||
<text>发送内容超过限制</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>45003</code>
|
||||
<text>标题字段超过限制</text>
|
||||
<desc>title size out of limit</desc>
|
||||
<text>标题超过限制</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>45004</code>
|
||||
<text>描述字段超过限制</text>
|
||||
<desc>description size out of limit</desc>
|
||||
<text>描述超过限制</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>45005</code>
|
||||
@ -651,6 +672,10 @@
|
||||
<code>45021</code>
|
||||
<text>字段超过长度限制,请参考相应接口的字段说明。</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>45028</code>
|
||||
<text>群发次数超过限制</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>45022</code>
|
||||
<text>应用名字长度不合法,合法长度为2-16个字</text>
|
||||
@ -715,10 +740,32 @@
|
||||
<code>45058</code>
|
||||
<text>不能修改0/1/2这三个系统默认保留的标签</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>48001</code>
|
||||
<text>公众号没有调用该接口的权限</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>48002</code>
|
||||
<text>公众号没有调用该接口的权限</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>48003</code>
|
||||
<text>请登录公众号后台,打开“群发功能”,同意腾讯群发消息声明</text>
|
||||
</error>
|
||||
<!-- 多客服API错误 -->
|
||||
<error>
|
||||
<code>45059</code>
|
||||
<text>有粉丝身上的标签数已经超过限制</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>48005</code>
|
||||
<text>此素材被自定义菜单引用,请先解除引用关系再编辑素材</text>
|
||||
<desc>forbid to delete material used by auto-reply or menu hint: [JMOD7a0063e292]</desc>
|
||||
</error>
|
||||
<error>
|
||||
<code>61450</code>
|
||||
<text>系统错误(system error)</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>45157</code>
|
||||
<text>标签名非法,请注意不能和其他标签重名</text>
|
||||
@ -2420,8 +2467,8 @@
|
||||
<text>金额不匹配,报关的订单金额必须和支付的金额一致,请检查报关订单的金额是否正确</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>POST_DATA_EMPTY</code>
|
||||
<text>post数据为空,post数据不能为空,请检查post数据是否为空</text>
|
||||
<code>9001007</code>
|
||||
<text>上传文件无效</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>REQUIRE_POST_METHOD</code>
|
||||
@ -2432,9 +2479,8 @@
|
||||
<text>输入的参数xml格式有误,检查输入的xml格式是否正确</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>SECOND_OVER_LIMITED</code>
|
||||
<text>企业红包的按分钟发放受限,每分钟发送红包数量不得超过1800个;(可联系微信支付wxhongbao@tencent.com调高额度)
|
||||
</text>
|
||||
<code>9001010</code>
|
||||
<text>文件上传到微信失败</text>
|
||||
</error>
|
||||
<error>
|
||||
<code>SENDNUM_LIMIT</code>
|
||||
|
||||
@ -3,6 +3,7 @@ package com.foxinmy.weixin4j.model;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.cache.Cacheable;
|
||||
|
||||
/**
|
||||
@ -25,10 +26,12 @@ public class Token implements Cacheable {
|
||||
/**
|
||||
* 获取到的凭证
|
||||
*/
|
||||
@JSONField(name = "access_token")
|
||||
private String accessToken;
|
||||
/**
|
||||
* 凭证有效时间,单位:毫秒
|
||||
*/
|
||||
@JSONField(name = "expires_in")
|
||||
private long expires;
|
||||
/**
|
||||
* token创建的时间,单位:毫秒
|
||||
@ -39,6 +42,11 @@ public class Token implements Cacheable {
|
||||
*/
|
||||
private Map<String, String> extra;
|
||||
|
||||
/**
|
||||
* 请求返回的原始结果
|
||||
*/
|
||||
private String originalResult;
|
||||
|
||||
/**
|
||||
* 永不过期、创建时间为当前时间戳的token对象
|
||||
*
|
||||
@ -55,7 +63,7 @@ public class Token implements Cacheable {
|
||||
* @param accessToken
|
||||
* 凭证字符串
|
||||
* @param expires
|
||||
* 过期时间 单位毫秒
|
||||
* 过期时间 单位秒
|
||||
*/
|
||||
public Token(String accessToken, long expires) {
|
||||
this(accessToken, expires, System.currentTimeMillis());
|
||||
@ -77,6 +85,26 @@ public class Token implements Cacheable {
|
||||
this.extra = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
public void setAccessToken(String accessToken) {
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
|
||||
public void setExpires(long expires) {
|
||||
this.expires = expires;
|
||||
}
|
||||
|
||||
public void setCreateTime(long createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public String getOriginalResult() {
|
||||
return originalResult;
|
||||
}
|
||||
|
||||
public void setOriginalResult(String originalResult) {
|
||||
this.originalResult = originalResult;
|
||||
}
|
||||
|
||||
public String getAccessToken() {
|
||||
return accessToken;
|
||||
}
|
||||
@ -100,6 +128,8 @@ public class Token implements Cacheable {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Token [accessToken=" + accessToken + ", expires=" + expires
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user