mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-10-31 10:38:42 +08:00 
			
		
		
		
	微信支付JSSDK及退款接口增加异常处理
为解决接口调用端无法取到调用微信服务器的返回结果的问题,微信支付JSSDK及退款接口增加了异常处理。 Change-Id: I2fe5255edb416336b64bef84a4bac5ba51231d67 Signed-off-by: Liu Kai <liukai@tinkers.com.cn>
This commit is contained in:
		| @ -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; | ||||
|  | ||||
|     /** | ||||
|      * 该接口提供所有微信支付订单的查询,当支付通知处理异常戒丢失的情冴,商户可以通过该接口查询订单支付状态。 | ||||
|  | ||||
| @ -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,10 +1018,15 @@ public class WxMpServiceImpl implements WxMpService { | ||||
|       xstream.processAnnotations(WxRedpackResult.class); | ||||
|       WxMpPayRefundResult wxMpPayRefundResult = (WxMpPayRefundResult) xstream.fromXML(responseContent); | ||||
|        | ||||
|       if ("FAIL".equals(wxMpPayRefundResult.getResultCode())) { | ||||
|       if (!"SUCCESS".equalsIgnoreCase(wxMpPayRefundResult.getResultCode()) | ||||
|             ||!"SUCCESS".equalsIgnoreCase(wxMpPayRefundResult.getReturnCode())) { | ||||
|         WxError error = new WxError(); | ||||
|         error.setErrorCode(-1); | ||||
|     	  error.setErrorMsg(wxMpPayRefundResult.getErrCodeDes()); | ||||
|         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); | ||||
|       } | ||||
|        | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Liu Kai
					Liu Kai