From b1d6d2bd9bbf5e3b54a098f326cc6c2b1d2e1791 Mon Sep 17 00:00:00 2001 From: dy-hu Date: Mon, 3 Mar 2025 09:45:10 +0800 Subject: [PATCH] =?UTF-8?q?PC=E7=AB=AF=E5=BE=AE=E4=BF=A1=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E9=80=BB=E8=BE=91=E6=96=B0=E5=A2=9E=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E8=8E=B7=E5=8F=96=E5=95=86=E5=AE=B6=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E9=85=8D=E7=BD=AE=E4=BF=A1=E6=81=AF=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pay/weixin/service/impl/WxPayServiceImpl.java | 2 +- .../param/activity/ActivitySignSaveParam.java | 4 +- .../com/shop/cereshop/business/pay/PayService.java | 6 +- .../pay/alipay/service/impl/AliPayServiceImpl.java | 4 +- .../alipay/service/impl/HuabeiPayServiceImpl.java | 4 +- .../pay/hnapay/impl/HnaPayServiceImpl.java | 4 +- .../pay/weixin/service/impl/WxPayServiceImpl.java | 68 ++++++++++++---------- .../pay/xs/service/impl/XsPayServiceImpl.java | 4 +- .../activity/impl/CereActivitySignServiceImpl.java | 2 +- .../order/impl/CereShopOrderServiceImpl.java | 2 +- .../commons/domain/activity/CereActivitySign.java | 2 +- 11 files changed, 55 insertions(+), 47 deletions(-) diff --git a/cereshop-admin/src/main/java/com/shop/cereshop/admin/pay/weixin/service/impl/WxPayServiceImpl.java b/cereshop-admin/src/main/java/com/shop/cereshop/admin/pay/weixin/service/impl/WxPayServiceImpl.java index ad5d61b..1ae3438 100644 --- a/cereshop-admin/src/main/java/com/shop/cereshop/admin/pay/weixin/service/impl/WxPayServiceImpl.java +++ b/cereshop-admin/src/main/java/com/shop/cereshop/admin/pay/weixin/service/impl/WxPayServiceImpl.java @@ -160,7 +160,7 @@ public class WxPayServiceImpl implements WxPayService { // 退款原因,若商户传入,会在下发给用户的退款消息中体现退款原因 params.put("refund_desc","退款"); //退款回调 - params.put("notify_url", pc_refund_notify_url); + params.put("notify_url", pc_refund_notify_url + "/" + project); //签名算法 String sign = WXPayUtil.generateSignature(params, businessWxpay.getMchKey()); params.put("sign", sign); diff --git a/cereshop-business/src/main/java/com/shop/cereshop/business/param/activity/ActivitySignSaveParam.java b/cereshop-business/src/main/java/com/shop/cereshop/business/param/activity/ActivitySignSaveParam.java index 883e1b5..5a38a75 100644 --- a/cereshop-business/src/main/java/com/shop/cereshop/business/param/activity/ActivitySignSaveParam.java +++ b/cereshop-business/src/main/java/com/shop/cereshop/business/param/activity/ActivitySignSaveParam.java @@ -20,9 +20,9 @@ import java.util.List; public class ActivitySignSaveParam { /** - * 关联店铺id + * 关联店铺id(实际为商家id) */ - @ApiModelProperty(value = "关联店铺id") + @ApiModelProperty(value = "关联店铺id(实际为商家id)") private Long shopId; /** diff --git a/cereshop-business/src/main/java/com/shop/cereshop/business/pay/PayService.java b/cereshop-business/src/main/java/com/shop/cereshop/business/pay/PayService.java index 78e28d8..fdb1161 100644 --- a/cereshop-business/src/main/java/com/shop/cereshop/business/pay/PayService.java +++ b/cereshop-business/src/main/java/com/shop/cereshop/business/pay/PayService.java @@ -5,7 +5,6 @@ */ package com.shop.cereshop.business.pay; -import com.shop.cereshop.business.page.shop.Shop; import com.shop.cereshop.commons.exception.CoBusinessException; import java.math.BigDecimal; @@ -30,13 +29,14 @@ public interface PayService { /** * 生成收款码返回 + * @param businessId 商家id * @param orderFormid 订单编号 * @param money 金额 * @param ip IP地址 * @param tradeType 支付类型 * @throws Exception */ - String getCollectionCode(String orderFormid, BigDecimal money, String ip, String tradeType) throws CoBusinessException, Exception; + String getCollectionCode(Long businessId, String orderFormid, BigDecimal money, String ip, String tradeType) throws CoBusinessException, Exception; /** * 订单取消微信退款 @@ -47,5 +47,5 @@ public interface PayService { * @throws CoBusinessException * @throws Exception */ - public Map orderRefund(String orderFormId, String outTradeNo, String transactionId,String outRefundNo,BigDecimal total,BigDecimal refund) throws CoBusinessException,Exception; + public Map orderRefund(String project, String orderFormId, String outTradeNo, String transactionId,String outRefundNo,BigDecimal total,BigDecimal refund) throws CoBusinessException,Exception; } diff --git a/cereshop-business/src/main/java/com/shop/cereshop/business/pay/alipay/service/impl/AliPayServiceImpl.java b/cereshop-business/src/main/java/com/shop/cereshop/business/pay/alipay/service/impl/AliPayServiceImpl.java index 2ae1923..6273257 100644 --- a/cereshop-business/src/main/java/com/shop/cereshop/business/pay/alipay/service/impl/AliPayServiceImpl.java +++ b/cereshop-business/src/main/java/com/shop/cereshop/business/pay/alipay/service/impl/AliPayServiceImpl.java @@ -66,7 +66,7 @@ public class AliPayServiceImpl implements AliPayService { } @Override - public String getCollectionCode(String orderFormid, BigDecimal money, String ip, String tradeType) throws CoBusinessException, Exception { + public String getCollectionCode(Long businessId, String orderFormid, BigDecimal money, String ip, String tradeType) throws CoBusinessException, Exception { AlipayClient client = new DefaultAlipayClient(AlipayConfig.URL, AlipayConfig.APPID, AlipayConfig.RSA_PRIVATE_KEY, AlipayConfig.FORMAT, AlipayConfig.CHARSET, AlipayConfig.ALIPAY_PUBLIC_KEY, AlipayConfig.SIGNTYPE); AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest(); request.setNotifyUrl(AlipayConfig.BOND_NOTIFY_URL); @@ -88,7 +88,7 @@ public class AliPayServiceImpl implements AliPayService { } @Override - public Map orderRefund(String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception { + public Map orderRefund(String project, String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception { Map result = new HashMap<>(); AlipayClient client = new DefaultAlipayClient(AlipayConfig.URL, AlipayConfig.APPID, AlipayConfig.RSA_PRIVATE_KEY, AlipayConfig.FORMAT, AlipayConfig.CHARSET, AlipayConfig.ALIPAY_PUBLIC_KEY, AlipayConfig.SIGNTYPE); diff --git a/cereshop-business/src/main/java/com/shop/cereshop/business/pay/alipay/service/impl/HuabeiPayServiceImpl.java b/cereshop-business/src/main/java/com/shop/cereshop/business/pay/alipay/service/impl/HuabeiPayServiceImpl.java index f9b0221..cd51725 100644 --- a/cereshop-business/src/main/java/com/shop/cereshop/business/pay/alipay/service/impl/HuabeiPayServiceImpl.java +++ b/cereshop-business/src/main/java/com/shop/cereshop/business/pay/alipay/service/impl/HuabeiPayServiceImpl.java @@ -60,7 +60,7 @@ public class HuabeiPayServiceImpl implements HuabeiPayService { } @Override - public String getCollectionCode(String orderFormid, BigDecimal money, String ip, String tradeType) throws CoBusinessException, Exception { + public String getCollectionCode(Long businessId, String orderFormid, BigDecimal money, String ip, String tradeType) throws CoBusinessException, Exception { AlipayClient client = new DefaultAlipayClient(AlipayConfig.URL, AlipayConfig.APPID, AlipayConfig.RSA_PRIVATE_KEY, AlipayConfig.FORMAT, AlipayConfig.CHARSET, AlipayConfig.ALIPAY_PUBLIC_KEY, AlipayConfig.SIGNTYPE); AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest(); request.setNotifyUrl(AlipayConfig.BOND_NOTIFY_URL); @@ -82,7 +82,7 @@ public class HuabeiPayServiceImpl implements HuabeiPayService { } @Override - public Map orderRefund(String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception { + public Map orderRefund(String project, String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception { return null; } } diff --git a/cereshop-business/src/main/java/com/shop/cereshop/business/pay/hnapay/impl/HnaPayServiceImpl.java b/cereshop-business/src/main/java/com/shop/cereshop/business/pay/hnapay/impl/HnaPayServiceImpl.java index 63f5f64..d5be058 100644 --- a/cereshop-business/src/main/java/com/shop/cereshop/business/pay/hnapay/impl/HnaPayServiceImpl.java +++ b/cereshop-business/src/main/java/com/shop/cereshop/business/pay/hnapay/impl/HnaPayServiceImpl.java @@ -187,12 +187,12 @@ public class HnaPayServiceImpl implements HnaPayService { //获取保证金 @Override - public String getCollectionCode(String orderFormid, BigDecimal money, String ip, String tradeType) throws CoBusinessException, Exception { + public String getCollectionCode(Long businessId, String orderFormid, BigDecimal money, String ip, String tradeType) throws CoBusinessException, Exception { return null; } @Override - public Map orderRefund(String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception { + public Map orderRefund(String project, String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception { List orderList = null; String cereOrderFormId = orderFormId; String[] split = orderFormId.split("-"); diff --git a/cereshop-business/src/main/java/com/shop/cereshop/business/pay/weixin/service/impl/WxPayServiceImpl.java b/cereshop-business/src/main/java/com/shop/cereshop/business/pay/weixin/service/impl/WxPayServiceImpl.java index c655516..c8360d0 100644 --- a/cereshop-business/src/main/java/com/shop/cereshop/business/pay/weixin/service/impl/WxPayServiceImpl.java +++ b/cereshop-business/src/main/java/com/shop/cereshop/business/pay/weixin/service/impl/WxPayServiceImpl.java @@ -14,6 +14,7 @@ import com.shop.cereshop.business.pay.weixin.skd.WXPayUtil; import com.shop.cereshop.business.pay.weixin.skd.WXPayV3Util; import com.shop.cereshop.business.service.bwxpay.CereBusinessWxpayService; import com.shop.cereshop.commons.constant.WxPayEnum; +import com.shop.cereshop.commons.domain.bwxpay.CereBusinessWxpay; import com.shop.cereshop.commons.exception.CoBusinessException; import com.shop.cereshop.commons.utils.RandomStringUtil; import lombok.extern.slf4j.Slf4j; @@ -32,32 +33,32 @@ public class WxPayServiceImpl implements WxPayService { /** * 支付小程序appid */ - @Value("${weixin.appid}") - private String appid; +// @Value("${weixin.appid}") +// private String appid; /** * 支付APP端的appid */ - @Value("${weixin.app_appid}") - private String app_appid; +// @Value("${weixin.app_appid}") +// private String app_appid; /** * 支付小程序秘钥 */ - @Value("${weixin.secret}") - private String secret; +// @Value("${weixin.secret}") +// private String secret; /** * 商户号 */ - @Value("${weixin.mchid}") - private String mch_id; +// @Value("${weixin.mchid}") +// private String mch_id; /** * 证书路径 */ - @Value("${weixin.certurl}") - private String cert_url; +// @Value("${weixin.certurl}") +// private String cert_url; /** * pc回调地址 @@ -89,8 +90,8 @@ public class WxPayServiceImpl implements WxPayService { /** * 商户秘钥 */ - @Value("${weixin.key}") - private String key; +// @Value("${weixin.key}") +// private String key; @Autowired private WXPayV3Util wxPayV3Util; @@ -102,20 +103,20 @@ public class WxPayServiceImpl implements WxPayService { public Map refund(String project, String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund, Long afterId) throws CoBusinessException, Exception { //APPV3版本的退款,以APPV3开头 if (outRefundNo.startsWith("APPV3")) { - return refundWithV3(transactionId, outRefundNo, total, refund); + return refundWithV3(project, transactionId, outRefundNo, total, refund); } else { - return refundWithNormal(transactionId, outRefundNo, total, refund); + return refundWithNormal(project, transactionId, outRefundNo, total, refund); } } - private Map refundWithV3(String transactionId, String outRefundNo, + private Map refundWithV3(String project, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws Exception { log.info(" orderRefund refundWithV3 {}, {}, {}, {}", transactionId, outRefundNo, total, refund); Map params = new HashMap<>(); params.put("transaction_id", transactionId); params.put("out_refund_no", outRefundNo); - params.put("notify_url", appV3NotifyUrl); + params.put("notify_url", appV3NotifyUrl + "/" + project); params.put("amount", new HashMap(){ { put("refund", refund.multiply(new BigDecimal(100)).intValue()); @@ -137,18 +138,19 @@ public class WxPayServiceImpl implements WxPayService { return result; } - private Map refundWithNormal(String transactionId, String outRefundNo, + private Map refundWithNormal(String project, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws Exception { + CereBusinessWxpay businessWxpay = cereBusinessWxpayService.getByBusinessId(Long.valueOf(project)); //退款资金来源-可用余额退款 String refundAccount="REFUND_SOURCE_RECHARGE_FUNDS"; Map params = new HashMap<>(); if(outRefundNo.contains("APP")){ //APP微信退款 - params.put("appid", app_appid); + params.put("appid", businessWxpay.getAppAppId()); } else { - params.put("appid", appid); + params.put("appid", businessWxpay.getAppId()); } - params.put("mch_id",mch_id); + params.put("mch_id",businessWxpay.getMchId()); params.put("nonce_str", System.currentTimeMillis() / 1000 + ""); //商户订单号和微信订单号二选一 // params.put("out_trade_no", wxPayLog.getOutTradeNo()); @@ -160,27 +162,28 @@ public class WxPayServiceImpl implements WxPayService { // 退款原因,若商户传入,会在下发给用户的退款消息中体现退款原因 params.put("refund_desc","退款"); //退款回调 - params.put("notify_url", pc_refund_notify_url); + params.put("notify_url", pc_refund_notify_url + "/" + project); //签名算法 - String sign = WXPayUtil.generateSignature(params,key); + String sign = WXPayUtil.generateSignature(params,businessWxpay.getMchKey()); params.put("sign", sign); String xml = PaymentKit.toXml(params); log.info(xml); - String xmlStr = WXPayUtil.doRefund("https://api.mch.weixin.qq.com/secapi/pay/refund", xml, cert_url, mch_id); + String xmlStr = WXPayUtil.doRefund("https://api.mch.weixin.qq.com/secapi/pay/refund", xml, businessWxpay.getCertUrl(), businessWxpay.getMchId()); log.info(xmlStr); //加入微信支付日志 return PaymentKit.xmlToMap(xmlStr); } @Override - public String getCollectionCode(String orderFormid, BigDecimal money, String ip, String tradeType) throws CoBusinessException,Exception { + public String getCollectionCode(Long businessId, String orderFormid, BigDecimal money, String ip, String tradeType) throws CoBusinessException,Exception { + CereBusinessWxpay businessWxpay = cereBusinessWxpayService.getByBusinessId(businessId); Map reqParams = new HashMap<>(); //生成一个新的订单支付编号 String outTradeNo=orderFormid+"-"+ RandomStringUtil.getRandomCode(3,0); //微信分配的小程序ID - reqParams.put("appid",appid); + reqParams.put("appid",businessWxpay.getAppId()); //微信支付分配的商户号 - reqParams.put("mch_id",mch_id); + reqParams.put("mch_id",businessWxpay.getMchId()); //随机字符串 reqParams.put("nonce_str", System.currentTimeMillis() / 1000 + ""); //签名类型 @@ -196,13 +199,13 @@ public class WxPayServiceImpl implements WxPayService { // reqParams.put("spbill_create_ip", "127.0.0.1"); reqParams.put("spbill_create_ip", ip); //支付回调地址 - reqParams.put("notify_url", pc_notify_url); + reqParams.put("notify_url", pc_notify_url + "/" + businessId); //交易类型 reqParams.put("trade_type", tradeType); //用户标识 // reqParams.put("openid", openid); //签名 - String sign = WXPayUtil.generateSignature(reqParams,key); + String sign = WXPayUtil.generateSignature(reqParams, businessWxpay.getMchKey()); reqParams.put("sign", sign); /* 调用支付定义下单API,返回预付单信息 prepay_id @@ -215,7 +218,12 @@ public class WxPayServiceImpl implements WxPayService { } @Override - public Map orderRefund(String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception { - return null; + public Map orderRefund(String project, String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception { + //APPV3版本的退款,以APPV3开头 + if (outRefundNo.startsWith("APPV3")) { + return refundWithV3(project, transactionId, outRefundNo, total, refund); + } else { + return refundWithNormal(project, transactionId, outRefundNo, total, refund); + } } } diff --git a/cereshop-business/src/main/java/com/shop/cereshop/business/pay/xs/service/impl/XsPayServiceImpl.java b/cereshop-business/src/main/java/com/shop/cereshop/business/pay/xs/service/impl/XsPayServiceImpl.java index e4cb3ba..bc15a99 100644 --- a/cereshop-business/src/main/java/com/shop/cereshop/business/pay/xs/service/impl/XsPayServiceImpl.java +++ b/cereshop-business/src/main/java/com/shop/cereshop/business/pay/xs/service/impl/XsPayServiceImpl.java @@ -113,7 +113,7 @@ public class XsPayServiceImpl implements XsPayService { //订单退款 @Override - public Map orderRefund(String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception { + public Map orderRefund(String project, String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception { Map contentMap = build22ContentMap(orderFormId, outRefundNo, outTradeNo, transactionId, refund, XspayConfig.APP_NOTICE_URL); String respMsg = XsPayUtils.requestByXs(SHARE_REFUND_SER_CODE, contentMap); if(StrUtil.isNotBlank(respMsg)){ @@ -156,7 +156,7 @@ public class XsPayServiceImpl implements XsPayService { //获取保证金二维码 @Override - public String getCollectionCode(String orderFormid, BigDecimal money, String ip, String tradeType) throws CoBusinessException, Exception { + public String getCollectionCode(Long businessId, String orderFormid, BigDecimal money, String ip, String tradeType) throws CoBusinessException, Exception { //构建请求参数 Map contentMap = build05ContentMap(orderFormid, money, tradeType, XsPayEnum.PAY_TYPE_QRCODE.getCode(), XspayConfig.BUSINESS_RETURN_URL, XspayConfig.BUSINESS_NOTICE_URL); diff --git a/cereshop-business/src/main/java/com/shop/cereshop/business/service/activity/impl/CereActivitySignServiceImpl.java b/cereshop-business/src/main/java/com/shop/cereshop/business/service/activity/impl/CereActivitySignServiceImpl.java index 9f7d41a..517ffc8 100644 --- a/cereshop-business/src/main/java/com/shop/cereshop/business/service/activity/impl/CereActivitySignServiceImpl.java +++ b/cereshop-business/src/main/java/com/shop/cereshop/business/service/activity/impl/CereActivitySignServiceImpl.java @@ -338,7 +338,7 @@ public class CereActivitySignServiceImpl implements CereActivitySignService { formid="XSZKBZJ-"+cereActivitySign.getSignId(); } - String code_url = PayFactory.getPayService(bondPaymentMode).getCollectionCode(formid, param.getBondMoney(), ip, WxPayEnum.PAY_TYPE_NATIVE.getCode()); + String code_url = PayFactory.getPayService(bondPaymentMode).getCollectionCode(param.getShopId(), formid, param.getBondMoney(), ip, WxPayEnum.PAY_TYPE_NATIVE.getCode()); if(!EmptyUtils.isEmpty(code_url)){ //生成收款二维码图片 Map hints = new HashMap<>(); diff --git a/cereshop-business/src/main/java/com/shop/cereshop/business/service/order/impl/CereShopOrderServiceImpl.java b/cereshop-business/src/main/java/com/shop/cereshop/business/service/order/impl/CereShopOrderServiceImpl.java index 7a52fd7..9a1dfb1 100644 --- a/cereshop-business/src/main/java/com/shop/cereshop/business/service/order/impl/CereShopOrderServiceImpl.java +++ b/cereshop-business/src/main/java/com/shop/cereshop/business/service/order/impl/CereShopOrderServiceImpl.java @@ -382,7 +382,7 @@ public class CereShopOrderServiceImpl implements CereShopOrderService { //微信支付没通,暂时直接处理业务 // handleRefundTestWxLog(order.getOrderFormid(),refund.getTransactionId(),refund.getOutTradeNo()); PayService payService = PayFactory.getPayService(refund.getPaymentMode()); - Map resultMap = payService.orderRefund(refund.getOrderFormid(), refund.getOutTradeNo(), refund.getTransactionId(), refund.getOutRefundNo(), refund.getTotalFee(), refund.getTotalFee()); + Map resultMap = payService.orderRefund(refund.getProject(), refund.getOrderFormid(), refund.getOutTradeNo(), refund.getTransactionId(), refund.getOutRefundNo(), refund.getTotalFee(), refund.getTotalFee()); if(!EmptyUtils.isEmpty(resultMap)){ if(resultMap.get("return_msg").equals(WxPayEnum.REFUND_SUCCESS.getCode())&& resultMap.get("return_code").equals(WxPayEnum.REFUND_OK.getCode())){ diff --git a/cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/activity/CereActivitySign.java b/cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/activity/CereActivitySign.java index bc86e84..e106acf 100644 --- a/cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/activity/CereActivitySign.java +++ b/cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/activity/CereActivitySign.java @@ -30,7 +30,7 @@ public class CereActivitySign implements Serializable { private String signCode; /** - * 关联店铺id + * 关联店铺id(实际为商家id) */ private Long shopId;