From 1a4a16908d81441da5fa2cfe4482a0cd83117aad Mon Sep 17 00:00:00 2001 From: zhengfangyuan Date: Wed, 24 Aug 2022 13:44:22 +0800 Subject: [PATCH] =?UTF-8?q?fix=20pay=20v3=20=E4=B8=AD=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/iformall/pay/WxPayV3.java | 7 +++ .../wx/sft/WxCashOutSFTAdapterService.java | 2 +- .../wx/v2/WxCashOutAdapterService.java | 2 +- .../wx/sft/entity/SFTCombineItemOrder.java | 9 +++- .../appPay/WxMiniAppPaySFTAdapterService.java | 6 ++- .../pay/wx/v3/BaseWxPayV3AdapterService.java | 50 +------------------ .../pay/wx/v3/entity/V3CombineItemOrder.java | 9 +++- .../appPay/WxMiniAppPayV3AdapterService.java | 9 +++- .../wx/v3/WxRefundV3AdapterService.java | 14 +++++- .../share/wx/v3/WxPayShareV3Service.java | 7 ++- 10 files changed, 56 insertions(+), 59 deletions(-) diff --git a/mallinkService/src/main/java/com/iformall/pay/WxPayV3.java b/mallinkService/src/main/java/com/iformall/pay/WxPayV3.java index 5ca2859a7..7423689bc 100644 --- a/mallinkService/src/main/java/com/iformall/pay/WxPayV3.java +++ b/mallinkService/src/main/java/com/iformall/pay/WxPayV3.java @@ -1,6 +1,7 @@ package com.iformall.pay; import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.security.GeneralSecurityException; import java.security.cert.X509Certificate; import java.util.HashMap; @@ -65,6 +66,12 @@ public class WxPayV3 { private WxPayV3() { } + //处理中文 + public static String handleChinese(String content) throws UnsupportedEncodingException { + //中文必须要这样,否则会双方签名失败 + return new String(content.getBytes("ISO-8859-1"), "UTF-8"); + } + //敏感信息加密 public static String entry(WxPayService payService,String content) throws IllegalBlockSizeException { X509Certificate certificate = payService.getConfig().getVerifier().getValidCertificate(); diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/cashout/wx/sft/WxCashOutSFTAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/cashout/wx/sft/WxCashOutSFTAdapterService.java index 4ed7c09b1..8874bb470 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/cashout/wx/sft/WxCashOutSFTAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/cashout/wx/sft/WxCashOutSFTAdapterService.java @@ -242,7 +242,7 @@ public class WxCashOutSFTAdapterService implements CashOutAdapterService{ StringBuffer bn = new StringBuffer(cashOut.getMerchantName()).append("提现"); try { - wxCashOutPv3.setBatch_name(new String(bn.toString().getBytes("ISO-8859-1"), "UTF-8")); + wxCashOutPv3.setBatch_name(WxPayV3.handleChinese(bn.toString())); } catch (UnsupportedEncodingException e) { wxCashOutPv3.setBatch_name("tixian"); } diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/cashout/wx/v2/WxCashOutAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/cashout/wx/v2/WxCashOutAdapterService.java index ad5bba214..d1e8556c0 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/cashout/wx/v2/WxCashOutAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/cashout/wx/v2/WxCashOutAdapterService.java @@ -248,7 +248,7 @@ public class WxCashOutAdapterService implements CashOutAdapterService{ StringBuffer bn = new StringBuffer(cashOut.getMerchantName()).append("提现"); try { - wxCashOutPv3.setBatch_name(new String(bn.toString().getBytes("ISO-8859-1"), "UTF-8")); + wxCashOutPv3.setBatch_name(WxPayV3.handleChinese(bn.toString())); } catch (UnsupportedEncodingException e) { wxCashOutPv3.setBatch_name("tixian"); } diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/sft/entity/SFTCombineItemOrder.java b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/sft/entity/SFTCombineItemOrder.java index 5a54494db..1eea36c83 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/sft/entity/SFTCombineItemOrder.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/sft/entity/SFTCombineItemOrder.java @@ -1,8 +1,11 @@ package com.iformall.service.pay.service.pay.wx.sft.entity; +import java.io.UnsupportedEncodingException; + import com.iformall.domain.po.WxAppinfo; import com.iformall.domain.po.WxOrder; import com.iformall.domain.po.WxPayAccount; +import com.iformall.pay.WxPayV3; import lombok.Data; @@ -25,7 +28,11 @@ public class SFTCombineItemOrder { this.setAmount(amount); this.out_trade_no = String.valueOf(order.getId()); this.sub_mchid = subMchId; - this.description = appInfo.getName()+"-"+productName; + try { + this.description = WxPayV3.handleChinese(appInfo.getName()+"-"+productName); + } catch (UnsupportedEncodingException e) { + this.description = "weixin miniApp product"; + } SFTPaySettleReq settle = new SFTPaySettleReq(); settle.setProfit_sharing(true); this.setSettle_info(settle); 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 7b2d1c0a1..1aae1f8c6 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 @@ -70,7 +70,11 @@ public class WxMiniAppPaySFTAdapterService extends BaseWxPaySFTAdapterService i req.setSp_appid(String.valueOf(appInfo.getId())); req.setSp_mchid(payAccount.getMchId()); req.setSub_mchid(getMerchantUid(record,composeOrder.getSingleOrder())); - req.setDescription(appInfo.getName()+"-"+productName); + try { + req.setDescription(WxPayV3.handleChinese(appInfo.getName()+"-"+productName)); + }catch(Exception e) { + req.setDescription("weixin miniApp product"); + } req.setOut_trade_no(String.valueOf(composeOrder.getMainOrderId())); req.setNotify_url(payAccount.getPayNotifyV3Url()); diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v3/BaseWxPayV3AdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v3/BaseWxPayV3AdapterService.java index 1f0a591dc..8ef87684a 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v3/BaseWxPayV3AdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v3/BaseWxPayV3AdapterService.java @@ -1,56 +1,8 @@ package com.iformall.service.pay.service.pay.wx.v3; -import java.io.File; -import java.util.Date; -import java.util.Map; - -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; -import com.iformall.common.ErrorCode; -import com.iformall.common.Result; -import com.iformall.common.ResultData; -import com.iformall.domain.po.PosCouponOrderVerify; -import com.iformall.domain.po.WxAppinfo; -import com.iformall.domain.po.WxBatchOrder; -import com.iformall.domain.po.WxCouponOrder; -import com.iformall.domain.po.WxOrder; -import com.iformall.domain.po.WxPayAccount; -import com.iformall.domain.po.WxPayOrder; -import com.iformall.enums.EnumCouponOrderStatus; -import com.iformall.enums.EnumOrderFrom; -import com.iformall.enums.EnumOrderStatus; -import com.iformall.enums.EnumOrderType; -import com.iformall.enums.EnumPayMode; -import com.iformall.enums.EnumPayStatus; -import com.iformall.exception.MallinkException; -import com.iformall.pay.WxPay; -import com.iformall.pay.WxPayOrderQ; -import com.iformall.pay.WxPayOrderSQ; -import com.iformall.pay.WxPayment; -import com.iformall.service.QrCodeService; -import com.iformall.service.helper.WxPayOrderServiceHelper; -import com.iformall.service.pay.service.pay.PayAdapterService; -import com.iformall.service.pay.service.pay.entity.PayAdapterResult; -import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; +import java.io.UnsupportedEncodingException; import com.iformall.service.pay.service.pay.wx.BaseWxPayAdapterService; -import com.iformall.utils.BeanUtils; -import com.iformall.utils.MaUtil; -import com.iformall.utils.QRCodeUtils; -import com.iformall.utils.Utility; -import cn.binarywang.wx.miniapp.api.WxMaService; -import cn.binarywang.wx.miniapp.bean.WxMaCodeLineColor; -import lombok.extern.slf4j.Slf4j; -import me.chanjar.weixin.common.error.WxErrorException; -import me.chanjar.weixin.open.api.WxOpenService; - -@Slf4j public class BaseWxPayV3AdapterService extends BaseWxPayAdapterService{ - } diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v3/entity/V3CombineItemOrder.java b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v3/entity/V3CombineItemOrder.java index d13710ef0..0c17727d3 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v3/entity/V3CombineItemOrder.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/v3/entity/V3CombineItemOrder.java @@ -1,8 +1,11 @@ package com.iformall.service.pay.service.pay.wx.v3.entity; +import java.io.UnsupportedEncodingException; + import com.iformall.domain.po.WxAppinfo; import com.iformall.domain.po.WxOrder; import com.iformall.domain.po.WxPayAccount; +import com.iformall.pay.WxPayV3; import lombok.Data; @@ -25,7 +28,11 @@ public class V3CombineItemOrder { this.setAmount(amount); this.out_trade_no = String.valueOf(order.getId()); this.sub_mchid = subMchId; - this.description = appInfo.getName()+"-"+productName; + try { + this.description = WxPayV3.handleChinese(appInfo.getName()+"-"+productName); + } catch (UnsupportedEncodingException e) { + this.description = "weixin miniApp product"; + } V3PaySettleReq settle = new V3PaySettleReq(); settle.setProfit_sharing(true); this.setSettle_info(settle); 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 a8c8a723c..4de025533 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 @@ -1,6 +1,7 @@ package com.iformall.service.pay.service.pay.wx.v3.miniApp.appPay; import java.io.File; +import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -83,8 +84,12 @@ public class WxMiniAppPayV3AdapterService extends BaseWxPayV3AdapterService impl }else { throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"当前支付模式非法"); } - //req.setDescription(appInfo.getName()+"-"+productName); - req.setDescription("product"); + try { + //中文必须要这样,否则会双方签名失败 + req.setDescription(WxPayV3.handleChinese(appInfo.getName()+"-"+productName)); + } catch (UnsupportedEncodingException e) { + req.setDescription("weixin miniApp product"); + } req.setOut_trade_no(record.getPayOrderNo()); req.setNotify_url(payAccount.getPayNotifyV3Url()); 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 7d7f357c2..c9cd88720 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 @@ -1,5 +1,6 @@ package com.iformall.service.pay.service.refund.wx.v3; +import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -73,6 +74,7 @@ public class WxRefundV3AdapterService implements RefundPayAdapterService{ private V3PayRefundReq getReq(WxPayAccount payAccount,WxAppinfo appInfo,WxRefundOrder record,WxPayOrder payOrder,Long orderId,EnumPayType payType) { V3PayRefundReq req = new V3PayRefundReq(); + //直连 if (payAccount.getMchType() == EnumPayMchType.DIRECT.getCode()) { WxComposeChildOrderShare share = payOrder.getChildOrderShare(orderId); req.setSub_mchid(share.getMerchantUid()); @@ -84,7 +86,11 @@ public class WxRefundV3AdapterService implements RefundPayAdapterService{ } req.setOut_trade_no(payOrder.getPayOrderNo()); req.setOut_refund_no(String.valueOf(record.getId())); - req.setReason(payType.getMessage()); + try { + req.setReason(WxPayV3.handleChinese(payType.getMessage())); + } catch (UnsupportedEncodingException e) { + req.setReason(payType.getCode().toString()); + } req.setNotify_url(payAccount.getRefundNotifyV3Url()); V3PayRefundAmountReq amount = new V3PayRefundAmountReq(); amount.setRefund(record.getRefundFee()); @@ -93,7 +99,11 @@ public class WxRefundV3AdapterService implements RefundPayAdapterService{ List goods = new ArrayList(); WxOrder order = wxOrderService.getById(orderId, payAccount.getTenantId()); V3PayRefundGoodsReq gr = new V3PayRefundGoodsReq(); - gr.setGoods_name("商品"+order.getProductId()); + try { + gr.setGoods_name(WxPayV3.handleChinese("商品"+order.getProductId())); + } catch (UnsupportedEncodingException e) { + gr.setGoods_name("product:"+order.getProductId()); + } gr.setMerchant_goods_id(order.getProductId().toString()); gr.setRefund_amount(record.getRefundFee()); gr.setRefund_quantity(order.getCouponNumber()); 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 e54bc1386..bdb977614 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 @@ -1,6 +1,7 @@ package com.iformall.service.pay.service.share.wx.v3; import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.security.GeneralSecurityException; import java.text.ParseException; import java.util.*; @@ -142,7 +143,11 @@ public class WxPayShareV3Service extends PayShareBaseAdapterService{ } req.setTransaction_id(transcationId); req.setOut_order_no(String.valueOf(record.getOrderId())); - req.setDescription(appInfo.getName()+"支付订单:"+record.getOrderId()); + try { + req.setDescription(WxPayV3.handleChinese(appInfo.getName()+"支付订单:"+record.getOrderId())); + } catch (UnsupportedEncodingException e1) { + req.setDescription("weixin miniApp orderId:"+record.getOrderId()); + } WxPayService payService = maUtil.getWxPayService(appInfo, payAccount); String response = null;;