Skip to content

Commit 2a69937

Browse files
author
Liu Kai
committed
微信支付JSSDK及退款接口增加异常处理
为解决接口调用端无法取到调用微信服务器的返回结果的问题,微信支付JSSDK及退款接口增加了异常处理。 Change-Id: I2fe5255edb416336b64bef84a4bac5ba51231d67 Signed-off-by: Liu Kai <[email protected]>
1 parent 852017f commit 2a69937

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,9 @@ public interface WxMpService {
726726
* @param parameters
727727
* the required or optional parameters
728728
* @return
729+
* @throws WxErrorException
729730
*/
730-
Map<String, String> getJSSDKPayInfo(Map<String, String> parameters);
731+
Map<String, String> getJSSDKPayInfo(Map<String, String> parameters) throws WxErrorException;
731732

732733
/**
733734
* 该接口调用“统一下单”接口,并拼装JSSDK发起支付请求需要的参数
@@ -740,10 +741,11 @@ public interface WxMpService {
740741
* @param ip 发起支付的客户端IP
741742
* @param notifyUrl 通知地址
742743
* @return
744+
* @throws WxErrorException
743745
* @deprecated Use me.chanjar.weixin.mp.api.WxMpService.getJSSDKPayInfo(Map<String, String>) instead
744746
*/
745747
@Deprecated
746-
Map<String, String> getJSSDKPayInfo(String openId, String outTradeNo, double amt, String body, String tradeType, String ip, String notifyUrl);
748+
Map<String, String> getJSSDKPayInfo(String openId, String outTradeNo, double amt, String body, String tradeType, String ip, String notifyUrl) throws WxErrorException;
747749

748750
/**
749751
* 该接口提供所有微信支付订单的查询,当支付通知处理异常戒丢失的情冴,商户可以通过该接口查询订单支付状态。

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,8 @@ private void checkParameters(Map<String, String> parameters) {
883883
}
884884

885885
@Override
886-
public Map<String, String> getJSSDKPayInfo(String openId, String outTradeNo, double amt, String body, String tradeType, String ip, String callbackUrl) {
886+
public Map<String, String> getJSSDKPayInfo(String openId, String outTradeNo, double amt, String body, String tradeType, String ip, String callbackUrl)
887+
throws WxErrorException {
887888
Map<String, String> packageParams = new HashMap<String, String>();
888889
packageParams.put("appid", wxMpConfigStorage.getAppId());
889890
packageParams.put("mch_id", wxMpConfigStorage.getPartnerId());
@@ -899,8 +900,21 @@ public Map<String, String> getJSSDKPayInfo(String openId, String outTradeNo, dou
899900
}
900901

901902
@Override
902-
public Map<String, String> getJSSDKPayInfo(Map<String, String> parameters) {
903+
public Map<String, String> getJSSDKPayInfo(Map<String, String> parameters) throws WxErrorException {
903904
WxMpPrepayIdResult wxMpPrepayIdResult = getPrepayId(parameters);
905+
906+
if (!"SUCCESS".equalsIgnoreCase(wxMpPrepayIdResult.getReturn_code())
907+
||!"SUCCESS".equalsIgnoreCase(wxMpPrepayIdResult.getResult_code())) {
908+
WxError error = new WxError();
909+
error.setErrorCode(-1);
910+
error.setErrorMsg("return_code:" + wxMpPrepayIdResult.getReturn_code() +
911+
"return_msg:" + wxMpPrepayIdResult.getReturn_msg() +
912+
"result_code:" + wxMpPrepayIdResult.getResult_code() +
913+
"err_code" + wxMpPrepayIdResult.getErr_code() +
914+
"err_code_des" + wxMpPrepayIdResult.getErr_code_des());
915+
throw new WxErrorException(error);
916+
}
917+
904918
String prepayId = wxMpPrepayIdResult.getPrepay_id();
905919
if (prepayId == null || prepayId.equals("")) {
906920
throw new RuntimeException(String.format("Failed to get prepay id due to error code '%s'(%s).", wxMpPrepayIdResult.getErr_code(), wxMpPrepayIdResult.getErr_code_des()));
@@ -1004,11 +1018,16 @@ public WxMpPayRefundResult refundPay(Map<String, String> parameters) throws WxEr
10041018
xstream.processAnnotations(WxRedpackResult.class);
10051019
WxMpPayRefundResult wxMpPayRefundResult = (WxMpPayRefundResult) xstream.fromXML(responseContent);
10061020

1007-
if ("FAIL".equals(wxMpPayRefundResult.getResultCode())) {
1008-
WxError error = new WxError();
1009-
error.setErrorCode(-1);
1010-
error.setErrorMsg(wxMpPayRefundResult.getErrCodeDes());
1011-
throw new WxErrorException(error);
1021+
if (!"SUCCESS".equalsIgnoreCase(wxMpPayRefundResult.getResultCode())
1022+
||!"SUCCESS".equalsIgnoreCase(wxMpPayRefundResult.getReturnCode())) {
1023+
WxError error = new WxError();
1024+
error.setErrorCode(-1);
1025+
error.setErrorMsg("return_code:" + wxMpPayRefundResult.getReturnCode() +
1026+
"return_msg:" + wxMpPayRefundResult.getReturnMsg() +
1027+
"result_code:" + wxMpPayRefundResult.getResultCode() +
1028+
"err_code" + wxMpPayRefundResult.getErrCode() +
1029+
"err_code_des" + wxMpPayRefundResult.getErrCodeDes());
1030+
throw new WxErrorException(error);
10121031
}
10131032

10141033
return wxMpPayRefundResult;

0 commit comments

Comments
 (0)