From 011a812f17b69e654647b52a654efb35907429b0 Mon Sep 17 00:00:00 2001 From: zhengfangyuan Date: Mon, 1 Aug 2022 19:24:29 +0800 Subject: [PATCH] fix bug --- .../src/main/java/com/iformall/pay/WxPay.java | 16 +++++++++++-- .../cashout/wx/WxCashOutAdapterService.java | 23 ++++++++++++++++++- .../java/com/iformall/utils/DateUtils.java | 2 ++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/mallinkService/src/main/java/com/iformall/pay/WxPay.java b/mallinkService/src/main/java/com/iformall/pay/WxPay.java index d408c4044..57723f1b7 100644 --- a/mallinkService/src/main/java/com/iformall/pay/WxPay.java +++ b/mallinkService/src/main/java/com/iformall/pay/WxPay.java @@ -1,10 +1,16 @@ package com.iformall.pay; +import java.security.cert.X509Certificate; import java.util.HashMap; +import java.util.List; import java.util.Map; +import javax.crypto.IllegalBlockSizeException; + +import com.alibaba.fastjson.JSON; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.WxPayService; +import com.github.binarywang.wxpay.v3.util.RsaCryptoUtil; import com.iformall.utils.HttpUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -254,9 +260,15 @@ public class WxPay { * 证书密码 * @return {String} * @throws WxPayException + * @throws IllegalBlockSizeException */ - public static String merchantTranferChange(WxPayService payService,String body) throws WxPayException { - return payService.postV3WithWechatpaySerial(MERCHANT_TRANSFER_CHANGE_URL, body); + public static String merchantTranferChange(WxPayService payService,WxCashOutPV3 cashOutV3) throws WxPayException, IllegalBlockSizeException { + X509Certificate certificate = payService.getConfig().getVerifier().getValidCertificate(); + List items = cashOutV3.getTransfer_detail_list(); + for (WxCashOutPV3Item it : items) { + it.setUser_name(RsaCryptoUtil.encryptOAEP(it.getUser_name(), certificate)); + } + return payService.postV3WithWechatpaySerial(MERCHANT_TRANSFER_CHANGE_URL, JSON.toJSONString(cashOutV3)); } /** diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/cashout/wx/WxCashOutAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/cashout/wx/WxCashOutAdapterService.java index d09fb52f6..b563a0e66 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/cashout/wx/WxCashOutAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/cashout/wx/WxCashOutAdapterService.java @@ -33,6 +33,7 @@ import com.iformall.mapper.WxPayAccountMapper; import com.iformall.mapper.WxPayOrderMapper; import com.iformall.mapper.WxRefundOrderMapper; import com.iformall.pay.WxCashOutP; +import com.iformall.pay.WxCashOutPV3; import com.iformall.pay.WxCashOutQueryP; import com.iformall.pay.WxPay; import com.iformall.pay.WxPayment; @@ -46,6 +47,7 @@ import com.iformall.service.pay.service.refund.entity.RefundAdapterResult; import com.iformall.service.pay.service.refund.entity.RefundNotifyAdapterResult; import com.iformall.utils.BeanUtils; import com.iformall.utils.CipherUtil; +import com.iformall.utils.DateUtils; import com.iformall.utils.MaUtil; import com.iformall.utils.Utility; import com.iformall.utils.XmlUtil; @@ -217,7 +219,7 @@ public class WxCashOutAdapterService implements CashOutAdapterService{ } String response = null; try { - response = WxPay.merchantTranferChange(payService,""); + response = WxPay.merchantTranferChange(payService,generateWxCashOutPV3(payAccount, cAppInfo, cashOut)); } catch (Exception e) { log.error("零钱支付异常: " + e.getMessage(),e); return new CashOutAdapterResult(false, EnumCashOutStatus.FAIL.getCode(), "微信零钱支付接口调用异常", null); @@ -230,6 +232,25 @@ public class WxCashOutAdapterService implements CashOutAdapterService{ // } } + private WxCashOutPV3 generateWxCashOutPV3(WxPayAccount payAccount,WxAppinfo appInfo,WxCashOut cashOut) { + String noncestr = Utility.generate32UUID(); + WxCashOutPV3 wxCashOutPv3 = new WxCashOutPV3(); + wxCashOutPv3.setAppid(appInfo.getAppId()); + wxCashOutPv3.setOut_batch_no(String.valueOf(cashOut.getId())); + wxCashOutPv3.setBatch_name(cashOut.getMerchantName()+"提现"); + +// wxCashOutP.setMch_appid(appInfo.getAppId()); +// wxCashOutP.setMchid(payAccount.getSubMchId()); +// wxCashOutP.setNonce_str(noncestr); +// wxCashOutP.setAmount(cashOut.getTotalFee()); +// wxCashOutP.setCheck_name("NO_CHECK"); +// wxCashOutP.setDesc("客户结算"); +// wxCashOutP.setOpenid(cashOut.getReciveOpenId()); +// wxCashOutP.setPartner_trade_no(String.valueOf(cashOut.getId())); + return wxCashOutPv3; + } + + // /** // * https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2 // * diff --git a/mallinkService/src/main/java/com/iformall/utils/DateUtils.java b/mallinkService/src/main/java/com/iformall/utils/DateUtils.java index 47217794f..7555833ea 100755 --- a/mallinkService/src/main/java/com/iformall/utils/DateUtils.java +++ b/mallinkService/src/main/java/com/iformall/utils/DateUtils.java @@ -23,6 +23,8 @@ public class DateUtils { public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss"; public final static String[] weekObj=new String[]{"日","一","二","三","四","五","六"}; + + public final static String DATE_PATTERN_NOSPACE = "yyyyMMdd"; public static String format(Date date) { return format(date, DATE_PATTERN);