From 3c1ecc2b4c314ec9b5dd245c2b72fe861331674f Mon Sep 17 00:00:00 2001 From: zhengfangyuan Date: Tue, 23 Aug 2022 19:26:48 +0800 Subject: [PATCH] fix pay v3 --- .../service/impl/WxPayOrderServiceImpl.java | 2 +- .../appPay/WxMiniAppPaySFTAdapterService.java | 37 +++++++++++++------ .../appPay/WxMiniAppPayV3AdapterService.java | 36 +++++++++++++----- .../wx/v3/WxRefundV3AdapterService.java | 22 +++++++++-- .../share/wx/v3/WxPayShareV3Service.java | 11 +++--- 5 files changed, 78 insertions(+), 30 deletions(-) diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java index 1a9384993..11cd1df4d 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java @@ -208,7 +208,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { wxpaystatus = payServiceFactory.getPayAdapterService(oldRecord.getPayVendor(),payAccount.getPayVersion()).queryPayStatus(queryResult, oldRecord.getPayOrderNo()); } catch (Exception e) { logger.error("pay order service handleWxOrderQuery error: " ,e); - throw new MallinkException(ErrorCode.PAY_ORDER_ERROR); + throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(),e.getMessage()); } if (EnumPayStatus.PAY_STATUS_SUCCESS.getCode()==wxpaystatus) { diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/sft/miniApp/appPay/WxMiniAppPaySFTAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/sft/miniApp/appPay/WxMiniAppPaySFTAdapterService.java index 85215fb08..7b2d1c0a1 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/sft/miniApp/appPay/WxMiniAppPaySFTAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/sft/miniApp/appPay/WxMiniAppPaySFTAdapterService.java @@ -14,6 +14,7 @@ import org.springframework.stereotype.Service; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.WxPayService; import com.iformall.common.ErrorCode; import com.iformall.common.Result; @@ -169,9 +170,13 @@ public class WxMiniAppPaySFTAdapterService extends BaseWxPaySFTAdapterService i */ if (childOrders.size() == 1) { SFTPayCommonMiniAppReq payReq = generatePayCommonRequest(payAccount,composeOrder,productName,record,openId,appInfo,currentDate); - String response = WxPayV3SFT.payCommonWithMiniApp(payService, payReq); - log.info("pay order v3, " + payReq.toString() + ", response: " + response.toString()); - return getOrderPResult(response,record); + try { + String response = WxPayV3SFT.payCommonWithMiniApp(payService, payReq); + return getOrderPResult(response,record); + }catch(WxPayException e) { + log.error("weixin sft pay error.",e); + throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),e.getCustomErrorMsg()); + } } else { throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"因电商收付通合单查询无法处理,暂时不支持合单支付"); //合单支付/小程序支付 @@ -226,12 +231,17 @@ public class WxMiniAppPaySFTAdapterService extends BaseWxPaySFTAdapterService i req.setSp_mchid(payAccount.getMchId()); req.setSub_mchid(oldRecord.getSingleChildOrderShare().getMerchantUid()); req.setOut_trade_no(String.valueOf(oldRecord.getId())); - String response = WxPayV3SFT.payCommonQuery(payService, req); - if (StringUtils.isBlank(response)){ - log.error("pay common sft query response is null."+JSON.toJSONString(req)); - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"pay common sft query response is null."+JSON.toJSONString(req)); + try { + String response = WxPayV3SFT.payCommonQuery(payService, req); + if (StringUtils.isBlank(response)){ + log.error("pay common sft query response is null."+JSON.toJSONString(req)); + throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"pay common sft query response is null."+JSON.toJSONString(req)); + } + return getPayCommonQueryResult(response); + }catch(WxPayException e) { + log.error("weixin sft pay query error.",e); + throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),e.getCustomErrorMsg()); } - return getPayCommonQueryResult(response); }else { throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"因电商收付通合单查询无法处理,暂时不支持合单支付查询"); // req.setOut_trade_no(String.valueOf(oldRecord.getId())); @@ -262,9 +272,14 @@ public class WxMiniAppPaySFTAdapterService extends BaseWxPaySFTAdapterService i SFTPayQueryReq req = new SFTPayQueryReq(); req.setSp_mchid(payAccount.getMchId()); req.setSub_mchid(record.getSingleChildOrderShare().getMerchantUid()); - req.setOut_trade_no(String.valueOf(record.getId())); - WxPayV3SFT.payCommonClose(payService, req); - return new PayAdapterResult(true, "close success", req, null); + req.setOut_trade_no(String.valueOf(record.getId())); + try { + WxPayV3SFT.payCommonClose(payService, req); + return new PayAdapterResult(true, "close success", req, null); + }catch(WxPayException e) { + log.error("weixin sft order close error.",e); + throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),e.getCustomErrorMsg()); + } }else { throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"因电商收付通合单查询无法处理,暂时不支持合单支付关闭"); diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v3/miniApp/appPay/WxMiniAppPayV3AdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v3/miniApp/appPay/WxMiniAppPayV3AdapterService.java index 003654a19..b7ddd029d 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v3/miniApp/appPay/WxMiniAppPayV3AdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v3/miniApp/appPay/WxMiniAppPayV3AdapterService.java @@ -14,6 +14,7 @@ import org.springframework.stereotype.Service; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.WxPayService; import com.iformall.common.ErrorCode; import com.iformall.common.Result; @@ -182,9 +183,13 @@ public class WxMiniAppPayV3AdapterService extends BaseWxPayV3AdapterService impl */ if (childOrders.size() == 1) { V3PayCommonMiniAppReq payReq = generatePayCommonRequest(payAccount,composeOrder,productName,record,openId,appInfo,currentDate); - String response = WxPayV3.payCommonWithMiniApp(payService, payReq); - log.info("pay order v3, " + payReq.toString() + ", response: " + response.toString()); - return getOrderPResult(response,record); + try { + String response = WxPayV3.payCommonWithMiniApp(payService, payReq); + return getOrderPResult(response,record); + }catch(WxPayException e) { + log.error("wexin pay v3 error",e); + throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),e.getCustomErrorMsg()); + } } else { throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"合单查询无法处理,暂时不支持合单支付"); //合单支付/小程序支付 @@ -244,12 +249,18 @@ public class WxMiniAppPayV3AdapterService extends BaseWxPayV3AdapterService impl req.setSub_mchid(oldRecord.getSingleChildOrderShare().getMerchantUid()); } req.setOut_trade_no(oldRecord.getPayOrderNo()); - String response = WxPayV3.payCommonQuery(payService, req); - if (StringUtils.isBlank(response)){ - log.error("pay common v3 query response is null."+JSON.toJSONString(req)); - throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"pay common v3 query response is null."+JSON.toJSONString(req)); + try { + String response = WxPayV3.payCommonQuery(payService, req); + if (StringUtils.isBlank(response)){ + log.error("pay common v3 query response is null."+JSON.toJSONString(req)); + throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"pay common v3 query response is null."+JSON.toJSONString(req)); + } + return getPayCommonQueryResult(response); + }catch(WxPayException e) { + log.error("pay common v3 query response error",e); + throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),e.getCustomErrorMsg()); } - return getPayCommonQueryResult(response); + }else { throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"合单查询无法处理,暂时不支持合单支付查询"); // req.setOut_trade_no(String.valueOf(oldRecord.getId())); @@ -286,8 +297,13 @@ public class WxMiniAppPayV3AdapterService extends BaseWxPayV3AdapterService impl req.setSub_mchid(record.getSingleChildOrderShare().getMerchantUid()); } req.setOut_trade_no(record.getPayOrderNo()); - WxPayV3SFT.payCommonClose(payService, req); - return new PayAdapterResult(true, "close success", req, null); + try { + WxPayV3.payCommonClose(payService, req); + return new PayAdapterResult(true, "close success", req, null); + }catch(WxPayException e) { + log.error("wexin pay v3 close error.",e); + throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),e.getCustomErrorMsg()); + } }else { throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"因合单查询无法处理,暂时不支持合单支付关闭"); diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/refund/wx/v3/WxRefundV3AdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/refund/wx/v3/WxRefundV3AdapterService.java index dbf66b0dd..7d7f357c2 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/refund/wx/v3/WxRefundV3AdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/refund/wx/v3/WxRefundV3AdapterService.java @@ -13,6 +13,7 @@ import org.springframework.stereotype.Service; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.WxPayService; import com.iformall.common.ErrorCode; import com.iformall.common.Result; @@ -121,9 +122,19 @@ public class WxRefundV3AdapterService implements RefundPayAdapterService{ try { //合单和普通一样 if (!payOrder.isMulity()) { - response = WxPayV3.payCommonRefund(payService, getReq(payAccount, appInfo, record, payOrder,orderId, payType)); + try { + response = WxPayV3.payCommonRefund(payService, getReq(payAccount, appInfo, record, payOrder,orderId, payType)); + }catch(WxPayException e) { + log.error("weixin pay v3 refund error. " ,e); + throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), e.getCustomErrorMsg()); + } }else { - response = WxPayV3.payCommonRefund(payService, getReq(payAccount, appInfo, record, payOrder,orderId, payType)); + try { + response = WxPayV3.payCommonRefund(payService, getReq(payAccount, appInfo, record, payOrder,orderId, payType)); + }catch(WxPayException e) { + log.error("weixin pay v3 refund error. " ,e); + throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), e.getCustomErrorMsg()); + } } } catch (Exception e) { log.error("退款异常: " + e.getMessage()); @@ -138,7 +149,12 @@ public class WxRefundV3AdapterService implements RefundPayAdapterService{ WxPayService payService = maUtil.getWxPayService(appInfo, payAccount); String response = null; try { - response = WxPayV3.payCommonRefundQuery(payService, String.valueOf(record.getId())); + try { + response = WxPayV3.payCommonRefundQuery(payService, String.valueOf(record.getId())); + }catch(WxPayException e) { + log.error("weixin pay v3 query refund error " ,e); + throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR.getCode(), e.getCustomErrorMsg()); + } JSONObject result = JSON.parseObject(response); String refund_status_0 = result.getString("status"); if("SUCCESS".equals(refund_status_0)){ diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java index 6bba99019..e54bc1386 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java @@ -153,7 +153,7 @@ public class WxPayShareV3Service extends PayShareBaseAdapterService{ } } catch (WxPayException e) { log.error("wx v3 noreciver share error:",e); - return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode(),ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getMessage()+":"+e.getMessage(), null,null); + return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode(),ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getMessage()+":"+e.getCustomErrorMsg(), null,null); } JSONObject result = JSON.parseObject(response); @@ -182,9 +182,9 @@ public class WxPayShareV3Service extends PayShareBaseAdapterService{ if (StringUtils.isBlank(response)) { return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode(),"分账请求失败.返回值为空", null,null); } - } catch (Exception e) { + } catch (WxPayException e) { log.error("wx v3 recivers share error:",e); - return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode(), ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getMessage()+":"+e.getMessage(), null, null); + return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode(), ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getMessage()+":"+e.getCustomErrorMsg(), null, null); } JSONObject result = JSON.parseObject(response); @@ -211,8 +211,9 @@ public class WxPayShareV3Service extends PayShareBaseAdapterService{ if (StringUtils.isBlank(response)) { throw new MallinkException(EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode(),"分账请求失败.返回值为空"); } - }catch (Exception e){ - throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getCode(), ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getMessage()+e.getMessage()); + } catch (WxPayException e) { + log.error("weixin pay v3 share error.",e); + throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getCode(), ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getMessage()+e.getCustomErrorMsg()); } JSONObject result = JSON.parseObject(response); String return_code = result.getString("state");