diff --git a/CHANGE.md b/CHANGE.md index fa52e2f9..d9cc6b08 100644 --- a/CHANGE.md +++ b/CHANGE.md @@ -774,4 +774,12 @@ * 2016-12-13 - + version upgrade to 1.7.3 \ No newline at end of file + + version upgrade to 1.7.3 + +* 2017-01-09 + + + 新增批量发红包接口 + + + 新增摇一摇周边接口 + + + version upgrade to 1.7.4 \ No newline at end of file diff --git a/pom.xml b/pom.xml index 8e290ca2..a6a21a45 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.foxinmy weixin4j - 1.7.4-SNAPSHOT + 1.7.4 pom weixin4j https://github.com/foxinmy/weixin4j @@ -44,6 +44,7 @@ weixin4j-mp weixin4j-qy weixin4j-server + weixin4j-example UTF-8 @@ -53,18 +54,6 @@ - - org.apache.maven.plugins - maven-source-plugin - 2.4 - - - - jar - - - - org.apache.maven.plugins maven-compiler-plugin @@ -222,8 +211,8 @@ src/main/resources - *.xml - *.properties + **/*.xml + **/*.properties @@ -259,27 +248,14 @@ - - - Project Releases - Project Releases - http://repo.wyying.com/nexus/content/repositories/releases/ - - Project Snapshots - Project Snapshots - http://repo.wyying.com/nexus/content/repositories/snapshots/ + oss-snapshot + https://oss.sonatype.org/content/repositories/snapshots/ + + oss-release + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + - - - - - - - - - - \ No newline at end of file diff --git a/weixin4j-base/.gitignore b/weixin4j-base/.gitignore index 87bd9366..c1e98e49 100644 --- a/weixin4j-base/.gitignore +++ b/weixin4j-base/.gitignore @@ -30,3 +30,5 @@ target/* Thumbs.db /target/ .DS_Store +/target/ +/target/ diff --git a/weixin4j-base/pom.xml b/weixin4j-base/pom.xml index 35f59332..1c99922d 100644 --- a/weixin4j-base/pom.xml +++ b/weixin4j-base/pom.xml @@ -5,7 +5,7 @@ com.foxinmy weixin4j - 1.7.4-SNAPSHOT + 1.7.4 weixin4j-base weixin4j-base diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/api/CashApi.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/api/CashApi.java index 9082d846..d514ee40 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/api/CashApi.java +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/api/CashApi.java @@ -1,8 +1,16 @@ package com.foxinmy.weixin4j.api; import java.math.BigDecimal; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.CompletionService; +import java.util.concurrent.ExecutorCompletionService; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; @@ -49,20 +57,6 @@ public class CashApi extends MchApi { * * @param redpacket * 红包信息 - * @see #sendRedpack(Redpacket,String) - */ - public RedpacketSendResult sendRedpack(Redpacket redpacket) - throws WeixinException { - return sendRedpack(redpacket, null); - } - - /** - * 发放红包 企业向微信用户个人发现金红包 - * - * @param redpacket - * 红包信息 - * @param appId - * 应用ID 可为空 主要是针对企业号支付时传入的agentid * @return 发放结果 * @see com.foxinmy.weixin4j.payment.mch.Redpacket * @see com.foxinmy.weixin4j.payment.mch.RedpacketSendResult @@ -74,25 +68,59 @@ public class CashApi extends MchApi { * 发放裂变红包接口 * @throws WeixinException */ - public RedpacketSendResult sendRedpack(Redpacket redpacket, String appId) + public RedpacketSendResult sendRedpack(Redpacket redpacket) throws WeixinException { + String appId = redpacket.getAppId(); super.declareMerchant(redpacket); - JSONObject obj = (JSONObject) JSON.toJSON(redpacket); + final JSONObject obj = (JSONObject) JSON.toJSON(redpacket); if (StringUtil.isNotBlank(appId)) { obj.put("appid", appId); } obj.put("wxappid", obj.remove("appid")); + final String redpack_uri = redpacket.getTotalNum() > 1 ? getRequestUri("groupredpack_send_uri") + : getRequestUri("redpack_send_uri"); obj.put("sign", weixinSignature.sign(obj)); String param = XmlStream.map2xml(obj); - WeixinResponse response = getWeixinSSLExecutor() - .post(redpacket.getTotalNum() > 1 ? getRequestUri("groupredpack_send_uri") - : getRequestUri("redpack_send_uri"), param); + WeixinResponse response = getWeixinSSLExecutor().post(redpack_uri, + param); String text = response.getAsString() .replaceFirst("", "") .replaceFirst("", ""); return XmlStream.fromXML(text, RedpacketSendResult.class); } + /** + * 批量发放红包 企业向微信用户个人发现金红包 + * + * @param redpacket + * 多个红包信息 + * @return 发放结果 + * @see #sendRedpacks(Redpacket...) + * @throws WeixinException + */ + public List> sendRedpacks( + Redpacket... redpackets) { + ExecutorService sendExecutor = Executors.newFixedThreadPool(Math.max(1, + redpackets.length / 10)); // 十分之一? + CompletionService completion = new ExecutorCompletionService( + sendExecutor); + List> callSendList = new ArrayList>( + redpackets.length); + for (final Redpacket redpacket : redpackets) { + Future futureSend = completion + .submit(new Callable() { + @Override + public RedpacketSendResult call() throws Exception { + return sendRedpack(redpacket); + } + }); + callSendList.add(futureSend); + } + // 关闭启动线程,不再接受新的任务 + sendExecutor.shutdown(); + return callSendList; + } + /** * 查询红包记录 * diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/api/MchApi.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/api/MchApi.java index 221a067b..86a878fc 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/api/MchApi.java +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/api/MchApi.java @@ -36,7 +36,7 @@ public class MchApi extends BaseApi { } protected final WeixinPayAccount weixinAccount; - protected final WeixinPaymentSignature weixinSignature; + protected final WeixinSignature weixinSignature; private volatile WeixinRequestExecutor weixinSSLExecutor; public MchApi(WeixinPayAccount weixinAccount) { diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/api/PayApi.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/api/PayApi.java index 24deccf6..db860ac0 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/api/PayApi.java +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/api/PayApi.java @@ -16,7 +16,6 @@ import java.util.Map; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.TypeReference; import com.foxinmy.weixin4j.exception.WeixinException; -import com.foxinmy.weixin4j.exception.WeixinPayException; import com.foxinmy.weixin4j.http.weixin.WeixinResponse; import com.foxinmy.weixin4j.http.weixin.XmlResult; import com.foxinmy.weixin4j.model.WeixinPayAccount; @@ -86,14 +85,8 @@ public class PayApi extends MchApi { String payJsRequestXml = XmlStream.toXML(payPackage); WeixinResponse response = weixinExecutor.post( getRequestUri("order_create_uri"), payJsRequestXml); - boolean validatePaySign = weixinSignature.validatePaySign(response); - if(validatePaySign) { - PrePay prePay = response.getAsObject(new TypeReference() { - }); - prePay.setResponse(response.getAsString()); - return prePay; - } - throw new WeixinPayException("验证签名信息失败,返回数据可能被篡改"); + return response.getAsObject(new TypeReference() { + }); } /** @@ -131,20 +124,19 @@ public class PayApi extends MchApi { MICROPayRequest microPayRequest = response .getAsObject(new TypeReference() { }); - microPayRequest.setResponse(response.getAsString()); microPayRequest.setPaymentAccount(weixinAccount); return microPayRequest; } PrePay prePay = createPrePay(payPackage); if (TradeType.APP.name().equals(tradeType)) { - return new APPPayRequest(prePay, weixinAccount); + return new APPPayRequest(prePay.getPrepayId(), weixinAccount); } else if (TradeType.JSAPI.name().equals(tradeType)) { - return new JSAPIPayRequest(prePay, weixinAccount); + return new JSAPIPayRequest(prePay.getPrepayId(), weixinAccount); } else if (TradeType.NATIVE.name().equals(tradeType)) { - return new NATIVEPayRequest(prePay, + return new NATIVEPayRequest(prePay.getPrepayId(), prePay.getCodeUrl(), weixinAccount); } else if (TradeType.WAP.name().equals(tradeType)) { - return new WAPPayRequest(prePay, weixinAccount); + return new WAPPayRequest(prePay.getPrepayId(), weixinAccount); } else { throw new WeixinException("unknown tradeType:" + tradeType); } @@ -180,36 +172,6 @@ public class PayApi extends MchApi { return createPayRequest(payPackage); } - /** - * 创建JSAPI支付请求对象 - * - * @param openId - * 用户ID - * @param body - * 订单描述 - * @param outTradeNo - * 订单号 - * @param totalFee - * 订单总额(元) - * @param notifyUrl - * 支付通知地址 - * @param createIp - * ip地址 - * @param attach - * 附加数据 非必填 - * @see com.foxinmy.weixin4j.payment.mch.JSAPIPayRequest - * @return JSAPI支付对象 - * @throws WeixinException - */ - public MchPayRequest createJSPayRequest(String openId, String body, - String outTradeNo, long totalFee, String notifyUrl, - String createIp, String attach) throws WeixinException { - MchPayPackage payPackage = new MchPayPackage(body, outTradeNo, - totalFee, notifyUrl, createIp, TradeType.JSAPI, openId, null, - null, attach); - return createPayRequest(payPackage); - } - /** *

* 生成编辑地址请求 @@ -311,43 +273,6 @@ public class PayApi extends MchApi { return new NativePayResponse(weixinAccount, prePay.getPrepayId()); } - /** - * 创建Native支付(扫码支付)回调对象【模式一】 - * - * @param productId - * 商品ID - * @param body - * 商品描述 - * @param outTradeNo - * 商户内部唯一订单号 - * @param totalFee - * 商品总额 单位元 - * @param notifyUrl - * 支付回调URL - * @param createIp - * 订单生成的机器 IP - * @param attach - * 附加数据 非必填 - * @return Native回调对象 - * @see com.foxinmy.weixin4j.payment.mch.NativePayResponse - * @see 扫码支付 - * - * @see 模式一 - * - * @throws WeixinException - */ - public NativePayResponse createNativePayResponse(String productId, - String body, String outTradeNo, long totalFee, String notifyUrl, - String createIp, String attach) throws WeixinException { - MchPayPackage payPackage = new MchPayPackage(body, outTradeNo, - totalFee, notifyUrl, createIp, TradeType.NATIVE, null, null, - productId, attach); - PrePay prePay = createPrePay(payPackage); - return new NativePayResponse(weixinAccount, prePay.getPrepayId()); - } - /** * 创建Native支付(扫码支付)链接【模式二】 * @@ -384,42 +309,6 @@ public class PayApi extends MchApi { return createPayRequest(payPackage); } - /** - * 创建Native支付(扫码支付)链接【模式二】 - * - * @param productId - * 商品ID - * @param body - * 商品描述 - * @param outTradeNo - * 商户内部唯一订单号 - * @param totalFee - * 商品总额 单位元 - * @param notifyUrl - * 支付回调URL - * @param createIp - * 订单生成的机器 IP - * @param attach - * 附加数据 非必填 - * @return Native支付对象 - * @see com.foxinmy.weixin4j.payment.mch.NATIVEPayRequest - * @see 扫码支付 - * - * @see 模式二 - * - * @throws WeixinException - */ - public MchPayRequest createNativePayRequest(String productId, String body, - String outTradeNo, long totalFee, String notifyUrl, - String createIp, String attach) throws WeixinException { - MchPayPackage payPackage = new MchPayPackage(body, outTradeNo, - totalFee, notifyUrl, createIp, TradeType.NATIVE, null, null, - productId, attach); - return createPayRequest(payPackage); - } - /** * 创建APP支付请求对象 * @@ -451,37 +340,6 @@ public class PayApi extends MchApi { return createPayRequest(payPackage); } - /** - * 创建APP支付请求对象 - * - * @param body - * 商品描述 - * @param outTradeNo - * 商户内部唯一订单号 - * @param totalFee - * 商品总额 单位元 - * @param notifyUrl - * 支付回调URL - * @param createIp - * 订单生成的机器 IP - * @param attach - * 附加数据 非必填 - * @return APP支付对象 - * @see com.foxinmy.weixin4j.payment.mch.APPPayRequest - * @see - * APP支付 - * @throws WeixinException - */ - public MchPayRequest createAppPayRequest(String body, String outTradeNo, - long totalFee, String notifyUrl, String createIp, String attach) - throws WeixinException { - MchPayPackage payPackage = new MchPayPackage(body, outTradeNo, - totalFee, notifyUrl, createIp, TradeType.APP, null, null, null, - attach); - return createPayRequest(payPackage); - } - /** * 创建WAP支付请求对象 * @@ -513,37 +371,6 @@ public class PayApi extends MchApi { return createPayRequest(payPackage); } - /** - * 创建WAP支付请求对象 - * - * @param body - * 商品描述 - * @param outTradeNo - * 商户内部唯一订单号 - * @param totalFee - * 商品总额 单位元 - * @param notifyUrl - * 支付回调URL - * @param createIp - * 订单生成的机器 IP - * @param attach - * 附加数据 非必填 - * @return WAP支付对象 - * @see com.foxinmy.weixin4j.payment.mch.WAPPayRequest - * @see WAP支付 - * - * @throws WeixinException - */ - public MchPayRequest createWapPayRequest(String body, String outTradeNo, - long totalFee, String notifyUrl, String createIp, String attach) - throws WeixinException { - MchPayPackage payPackage = new MchPayPackage(body, outTradeNo, - totalFee, notifyUrl, createIp, TradeType.WAP, null, null, null, - attach); - return createPayRequest(payPackage); - } - /** * 提交被扫支付 * @@ -568,43 +395,11 @@ public class PayApi extends MchApi { * @throws WeixinException */ public MchPayRequest createMicroPayRequest(String authCode, String body, - String outTradeNo, double totalFee, String createIp, String attach) + String outTradeNo, double totalFee, String createIp, String attach) throws WeixinException { MchPayPackage payPackage = new MchPayPackage(body, outTradeNo, - totalFee, null, createIp, TradeType.MICROPAY, null, authCode, - null, attach); - return createPayRequest(payPackage); - } - - /** - * 提交被扫支付 - * - * @param authCode - * 扫码支付授权码 ,设备读取用户微信中的条码或者二维码信息 - * @param body - * 商品描述 - * @param outTradeNo - * 商户内部唯一订单号 - * @param totalFee - * 商品总额 单位元 - * @param createIp - * 订单生成的机器 IP - * @param attach - * 附加数据 非必填 - * @return 支付的订单信息 - * @see com.foxinmy.weixin4j.payment.mch.MICROPayRequest - * @see com.foxinmy.weixin4j.payment.mch.Order - * @see - * 提交被扫支付API - * @throws WeixinException - */ - public MchPayRequest createMicroPayRequest(String authCode, String body, - String outTradeNo, long totalFee, String createIp, String attach) - throws WeixinException { - MchPayPackage payPackage = new MchPayPackage(body, outTradeNo, - totalFee, null, createIp, TradeType.MICROPAY, null, authCode, - null, attach); + totalFee, null, createIp, TradeType.MICROPAY, null, authCode, + null, attach); return createPayRequest(payPackage); } @@ -675,51 +470,13 @@ public class PayApi extends MchApi { double totalFee, double refundFee, CurrencyType refundFeeType, String opUserId, RefundAccountType refundAccountType) throws WeixinException { - return applyRefund(idQuery, outRefundNo, DateUtil.formatYuan2Fen(totalFee), DateUtil.formatYuan2Fen(refundFee), refundFeeType, opUserId, - refundAccountType); - } - - /** - * 申请退款(请求需要双向证书) - *

- * 当交易发生之后一段时间内,由于买家或者卖家的原因需要退款时,卖家可以通过退款接口将支付款退还给买家,微信支付将在收到退款请求并且验证成功之后, - * 按照退款规则将支付款按原路退到买家帐号上。 - *

- *

- * 1.交易时间超过半年的订单无法提交退款; - * 2.微信支付退款支持单笔交易分多次退款,多次退款需要提交原支付订单的商户订单号和设置不同的退款单号。一笔退款失败后重新提交 - * ,要采用原来的退款单号。总退款金额不能超过用户实际支付金额。 - *

- * - * @param idQuery - * 商户系统内部的订单号, transaction_id 、 out_trade_no 二选一,如果同时存在优先级: - * transaction_id> out_trade_no - * @param outRefundNo - * 商户系统内部的退款单号,商 户系统内部唯一,同一退款单号多次请求只退一笔 - * @param totalFee - * 订单总金额,单位为元 - * @param refundFee - * 退款总金额,单位为元,可以做部分退款 - * @param refundFeeType - * 货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY - * @param opUserId - * 操作员帐号, 默认为商户号 - * @param refundAccountType - * @return 退款申请结果 - * @see com.foxinmy.weixin4j.payment.mch.RefundResult - * @see - * 申请退款API - * @since V3 - * @throws WeixinException - */ - public RefundResult applyRefund(IdQuery idQuery, String outRefundNo, long totalFee, long refundFee, CurrencyType refundFeeType, - String opUserId, RefundAccountType refundAccountType) throws WeixinException { WeixinResponse response = null; Map map = createBaseRequestMap(idQuery); map.put("out_refund_no", outRefundNo); - map.put("total_fee", String.valueOf(totalFee)); - map.put("refund_fee", String.valueOf(refundFee)); + map.put("total_fee", + Integer.toString(DateUtil.formatYuan2Fen(totalFee))); + map.put("refund_fee", + Integer.toString(DateUtil.formatYuan2Fen(refundFee))); if (StringUtil.isBlank(opUserId)) { opUserId = weixinAccount.getMchId(); } @@ -750,7 +507,7 @@ public class PayApi extends MchApi { * 商户系统内部的退款单号,商 户系统内部唯一,同一退款单号多次请求只退一笔 * @param totalFee * 订单总金额,单位为元 - * @see {@link #applyRefund(IdQuery, String, double, double,CurrencyType, String,RefundAccountType)} + * @see {@link #applyRefund(IdQuery, String, double, double,CurrencyType, String)} */ public RefundResult applyRefund(IdQuery idQuery, String outRefundNo, double totalFee) throws WeixinException { @@ -758,23 +515,6 @@ public class PayApi extends MchApi { null, null); } - /** - * 退款申请(全额退款) - * - * @param idQuery - * 商户系统内部的订单号, transaction_id 、 out_trade_no 二选一,如果同时存在优先级: - * transaction_id> out_trade_no - * @param outRefundNo - * 商户系统内部的退款单号,商 户系统内部唯一,同一退款单号多次请求只退一笔 - * @param totalFee - * 订单总金额,单位为元 - * @see {@link #applyRefund(IdQuery, String, double, double,CurrencyType, String,RefundAccountType)} - */ - public RefundResult applyRefund(IdQuery idQuery, String outRefundNo, - long totalFee) throws WeixinException { - return applyRefund(idQuery, outRefundNo, totalFee, totalFee, null, null, null); - } - /** * 冲正订单(需要证书)
当支付返回失败,或收银系统超时需要取消交易,可以调用该接口
接口逻辑:支 * 付失败的关单,支付成功的撤销支付
7天以内的单可撤销,其他正常支付的单 @@ -1024,6 +764,4 @@ public class PayApi extends MchApi { return response.getAsObject(new TypeReference() { }); } - - } diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/exception/WeixinException.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/exception/WeixinException.java index aa6b5681..40a5c752 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/exception/WeixinException.java +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/exception/WeixinException.java @@ -2,82 +2,65 @@ package com.foxinmy.weixin4j.exception; import com.foxinmy.weixin4j.util.StringUtil; import com.foxinmy.weixin4j.util.WeixinErrorUtil; -import com.foxinmy.weixin4j.util.WeixinErrorUtil2; /** * 调用微信接口抛出的异常 * - * @author jinyu(foxinmy@gmail.com) * @className WeixinException + * @author jinyu(foxinmy@gmail.com) * @date 2014年4月10日 - * @see * @since JDK 1.6 + * @see */ 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 describeErrorMsg; + private String code; + private String desc; - public WeixinException(String code, String desc) { - this(code, desc, null); - } + public WeixinException(String code, String desc) { + this.code = code; + this.desc = desc; + } + public WeixinException(String desc) { + this.code = "-1"; + this.desc = desc; + } - 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(Throwable e) { + super(e); + } - public WeixinException(String desc) { - this.code = "-1"; - this.desc = desc; - } + public WeixinException(String message, Throwable cause) { + super(message, cause); + } - public String getDescribeErrorMsg() { - return describeErrorMsg; - } + public String getErrorCode() { + return code; + } + public String getErrorDesc() { + return desc; + } - public WeixinException(Throwable e) { - super(e); - } + public String getErrorText() { + return WeixinErrorUtil.getText(code); + } - 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(); - } - } + @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(); + } + } } diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/exception/WeixinPayException.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/exception/WeixinPayException.java deleted file mode 100644 index 7a480362..00000000 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/exception/WeixinPayException.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.foxinmy.weixin4j.exception; - -/** - * 调用微信支付抛出的异常 - * - * @className WeixinPayException - * @author jinyu(foxinmy@gmail.com) - * @date 2014年10月28日 - * @since JDK 1.6 - * @see - */ -public class WeixinPayException extends WeixinException { - private static final long serialVersionUID = 7148145661883468514L; - - public WeixinPayException(String desc) { - super(desc); - } - - public WeixinPayException(String code, String desc) { - super(code, desc); - } - - public WeixinPayException(Throwable e) { - super(e); - } -} diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/SimpleHttpClient.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/SimpleHttpClient.java index f32e821c..27005fff 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/SimpleHttpClient.java +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/SimpleHttpClient.java @@ -28,7 +28,7 @@ import com.foxinmy.weixin4j.util.StringUtil; * @since JDK 1.6 * @see */ -public class SimpleHttpClient extends AbstractHttpClient implements HttpClient { +public class SimpleHttpClient extends AbstractHttpClient { private final HttpParams params; diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/weixin/WeixinRequestExecutor.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/weixin/WeixinRequestExecutor.java index 24153148..8a22fe65 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/weixin/WeixinRequestExecutor.java +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/weixin/WeixinRequestExecutor.java @@ -28,24 +28,21 @@ 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日 - * @see * @since JDK 1.6 + * @see */ 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,"; @@ -61,7 +58,7 @@ public class WeixinRequestExecutor { /** * Post方法执行微信请求 - * + * * @param url * 请求URL * @param body @@ -78,7 +75,7 @@ public class WeixinRequestExecutor { /** * Post方法执行微信请求,用于文件上传 - * + * * @param url * 请求URL * @param bodyParts @@ -100,7 +97,7 @@ public class WeixinRequestExecutor { /** * Get方法执行微信请求 - * + * * @param url * 请求URL,如:https://api.weixin.qq.com/cgi-bin/token * @param parameters @@ -111,9 +108,9 @@ public class WeixinRequestExecutor { public WeixinResponse get(String url, URLParameter... parameters) throws WeixinException { // always contain the question mark - StringBuilder buf = new StringBuilder(url).append("&"); + StringBuilder buf = new StringBuilder(url); if (parameters != null && parameters.length > 0) { - buf.append(FormUrlEntity.formatParameters(Arrays.asList(parameters))); + buf.append("&").append(FormUrlEntity.formatParameters(Arrays.asList(parameters))); } HttpRequest request = new HttpRequest(HttpMethod.GET, buf.toString()); return doRequest(request); @@ -121,7 +118,7 @@ public class WeixinRequestExecutor { /** * 执行微信请求 - * + * * @param request * 微信请求 * @return 微信响应 @@ -145,7 +142,7 @@ public class WeixinRequestExecutor { /** * 响应内容是否为流 - * + * * @param response * 微信响应 * @return true/false @@ -163,7 +160,7 @@ public class WeixinRequestExecutor { /** * handle the weixin response - * + * * @param response * 微信请求响应 * @throws WeixinException @@ -187,7 +184,7 @@ public class WeixinRequestExecutor { .toLowerCase()))) { printHttpRequest(request,InternalLogLevel.WARN); throw new WeixinException(result.getReturnCode(), - result.getReturnMsg(),WeixinErrorUtil2.getText(result.getReturnCode())); + result.getReturnMsg()); } if (XmlMessageConverter.GLOBAL.canConvert(XmlResult.class, response)) { try { @@ -197,7 +194,7 @@ public class WeixinRequestExecutor { .getResultCode().toLowerCase()))) { printHttpRequest(request,InternalLogLevel.WARN); throw new WeixinException(xmlResult.getErrCode(), - xmlResult.getErrCodeDes(),WeixinErrorUtil2.getText(xmlResult.getErrCode())); + xmlResult.getErrCodeDes()); } } catch (IOException e) { ; @@ -223,7 +220,7 @@ public class WeixinRequestExecutor { /** * 创建 SSL微信请求对象 - * + * * @param password * 加载密钥 * @param inputStream diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/weixin/error.xml b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/weixin/error.xml index 81665ba5..a520e717 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/weixin/error.xml +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/http/weixin/error.xml @@ -2,16 +2,14 @@ + + -1 + 系统繁忙,请稍后再试 + 0 请求成功 - - -1 - system error - 微信系统繁忙,请稍候再试 - - 40001 获取access_token时AppSecret错误,或者access_token无效 @@ -38,8 +36,7 @@ 40007 - invalid media_id - 请检查您的素材! + 无效的media_id 40008 @@ -136,7 +133,7 @@ 40031 - 不合法的粉丝列表 + 不合法的openid列表 40032 @@ -264,7 +261,7 @@ 40073 - 不合法的cardid + 不合法的openid 40074 @@ -342,10 +339,6 @@ 40116 不合法的Code码。 - - 40113 - 不支持的文件类型 - 40117 分组名字不合法 @@ -382,15 +375,6 @@ 40132 微信号不合法 - - 40130 - 最少选择两名粉丝 - - - 40132 - invalid username - 无效的微信号 - 40137 不支持的图片格式 @@ -549,8 +533,7 @@ 43004 - require subscribe - 未关注公众号 + 需要接收者关注 43005 @@ -610,23 +593,19 @@ 45001 - media size out of limit - 多媒体文件大小超过微信限制 + 多媒体文件大小超过限制 45002 - content size out of limit - 发送内容超过限制 + 消息内容超过限制 45003 - title size out of limit - 标题超过限制 + 标题字段超过限制 45004 - description size out of limit - 描述超过限制 + 描述字段超过限制 45005 @@ -672,10 +651,6 @@ 45021 字段超过长度限制,请参考相应接口的字段说明。 - - 45028 - 群发次数超过限制 - 45022 应用名字长度不合法,合法长度为2-16个字 @@ -740,32 +715,10 @@ 45058 不能修改0/1/2这三个系统默认保留的标签 - - 48001 - 公众号没有调用该接口的权限 - - - 48002 - 公众号没有调用该接口的权限 - - - 48003 - 请登录公众号后台,打开“群发功能”,同意腾讯群发消息声明 - - 45059 有粉丝身上的标签数已经超过限制 - - 48005 - 此素材被自定义菜单引用,请先解除引用关系再编辑素材 - forbid to delete material used by auto-reply or menu hint: [JMOD7a0063e292] - - - 61450 - 系统错误(system error) - 45157 标签名非法,请注意不能和其他标签重名 @@ -2467,8 +2420,8 @@ 金额不匹配,报关的订单金额必须和支付的金额一致,请检查报关订单的金额是否正确 - 9001007 - 上传文件无效 + POST_DATA_EMPTY + post数据为空,post数据不能为空,请检查post数据是否为空 REQUIRE_POST_METHOD @@ -2479,8 +2432,9 @@ 输入的参数xml格式有误,检查输入的xml格式是否正确 - 9001010 - 文件上传到微信失败 + SECOND_OVER_LIMITED + 企业红包的按分钟发放受限,每分钟发送红包数量不得超过1800个;(可联系微信支付wxhongbao@tencent.com调高额度) + SENDNUM_LIMIT diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/model/Button.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/model/Button.java index 3666d9e8..d6620c87 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/model/Button.java +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/model/Button.java @@ -72,7 +72,7 @@ public class Button implements Serializable { */ public Button(String name, Button... subButtons) { this.name = name; - this.subs = Arrays.asList(subButtons); + this.subs = new ArrayList