소스 검색

微信支付JSSDK及退款接口增加异常处理

为解决接口调用端无法取到调用微信服务器的返回结果的问题,微信支付JSSDK及退款接口增加了异常处理。

Change-Id: I2fe5255edb416336b64bef84a4bac5ba51231d67
Signed-off-by: Liu Kai <liukai@tinkers.com.cn>
master
Liu Kai 9 년 전
부모
커밋
2a6993713a
2개의 변경된 파일30개의 추가작업 그리고 9개의 파일을 삭제
  1. +4
    -2
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java
  2. +26
    -7
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java

+ 4
- 2
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java 파일 보기

@@ -726,8 +726,9 @@ public interface WxMpService {
* @param parameters
* the required or optional parameters
* @return
* @throws WxErrorException
*/
Map<String, String> getJSSDKPayInfo(Map<String, String> parameters);
Map<String, String> getJSSDKPayInfo(Map<String, String> parameters) throws WxErrorException;
/**
* 该接口调用“统一下单”接口,并拼装JSSDK发起支付请求需要的参数
@@ -740,10 +741,11 @@ public interface WxMpService {
* @param ip 发起支付的客户端IP
* @param notifyUrl 通知地址
* @return
* @throws WxErrorException
* @deprecated Use me.chanjar.weixin.mp.api.WxMpService.getJSSDKPayInfo(Map<String, String>) instead
*/
@Deprecated
Map<String, String> getJSSDKPayInfo(String openId, String outTradeNo, double amt, String body, String tradeType, String ip, String notifyUrl);
Map<String, String> getJSSDKPayInfo(String openId, String outTradeNo, double amt, String body, String tradeType, String ip, String notifyUrl) throws WxErrorException;

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


+ 26
- 7
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java 파일 보기

@@ -883,7 +883,8 @@ public class WxMpServiceImpl implements WxMpService {
}

@Override
public Map<String, String> getJSSDKPayInfo(String openId, String outTradeNo, double amt, String body, String tradeType, String ip, String callbackUrl) {
public Map<String, String> getJSSDKPayInfo(String openId, String outTradeNo, double amt, String body, String tradeType, String ip, String callbackUrl)
throws WxErrorException {
Map<String, String> packageParams = new HashMap<String, String>();
packageParams.put("appid", wxMpConfigStorage.getAppId());
packageParams.put("mch_id", wxMpConfigStorage.getPartnerId());
@@ -899,8 +900,21 @@ public class WxMpServiceImpl implements WxMpService {
}

@Override
public Map<String, String> getJSSDKPayInfo(Map<String, String> parameters) {
public Map<String, String> getJSSDKPayInfo(Map<String, String> parameters) throws WxErrorException {
WxMpPrepayIdResult wxMpPrepayIdResult = getPrepayId(parameters);
if (!"SUCCESS".equalsIgnoreCase(wxMpPrepayIdResult.getReturn_code())
||!"SUCCESS".equalsIgnoreCase(wxMpPrepayIdResult.getResult_code())) {
WxError error = new WxError();
error.setErrorCode(-1);
error.setErrorMsg("return_code:" + wxMpPrepayIdResult.getReturn_code() +
"return_msg:" + wxMpPrepayIdResult.getReturn_msg() +
"result_code:" + wxMpPrepayIdResult.getResult_code() +
"err_code" + wxMpPrepayIdResult.getErr_code() +
"err_code_des" + wxMpPrepayIdResult.getErr_code_des());
throw new WxErrorException(error);
}
String prepayId = wxMpPrepayIdResult.getPrepay_id();
if (prepayId == null || prepayId.equals("")) {
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 class WxMpServiceImpl implements WxMpService {
xstream.processAnnotations(WxRedpackResult.class);
WxMpPayRefundResult wxMpPayRefundResult = (WxMpPayRefundResult) xstream.fromXML(responseContent);
if ("FAIL".equals(wxMpPayRefundResult.getResultCode())) {
WxError error = new WxError();
error.setErrorCode(-1);
error.setErrorMsg(wxMpPayRefundResult.getErrCodeDes());
throw new WxErrorException(error);
if (!"SUCCESS".equalsIgnoreCase(wxMpPayRefundResult.getResultCode())
||!"SUCCESS".equalsIgnoreCase(wxMpPayRefundResult.getReturnCode())) {
WxError error = new WxError();
error.setErrorCode(-1);
error.setErrorMsg("return_code:" + wxMpPayRefundResult.getReturnCode() +
"return_msg:" + wxMpPayRefundResult.getReturnMsg() +
"result_code:" + wxMpPayRefundResult.getResultCode() +
"err_code" + wxMpPayRefundResult.getErrCode() +
"err_code_des" + wxMpPayRefundResult.getErrCodeDes());
throw new WxErrorException(error);
}
return wxMpPayRefundResult;


불러오는 중...
취소
저장