Browse Source

PC端微信支付业务逻辑新增动态获取商家微信支付配置信息处理

multiwx
dy-hu 2 months ago
parent
commit
b1d6d2bd9b
  1. 2
      cereshop-admin/src/main/java/com/shop/cereshop/admin/pay/weixin/service/impl/WxPayServiceImpl.java
  2. 4
      cereshop-business/src/main/java/com/shop/cereshop/business/param/activity/ActivitySignSaveParam.java
  3. 6
      cereshop-business/src/main/java/com/shop/cereshop/business/pay/PayService.java
  4. 4
      cereshop-business/src/main/java/com/shop/cereshop/business/pay/alipay/service/impl/AliPayServiceImpl.java
  5. 4
      cereshop-business/src/main/java/com/shop/cereshop/business/pay/alipay/service/impl/HuabeiPayServiceImpl.java
  6. 4
      cereshop-business/src/main/java/com/shop/cereshop/business/pay/hnapay/impl/HnaPayServiceImpl.java
  7. 68
      cereshop-business/src/main/java/com/shop/cereshop/business/pay/weixin/service/impl/WxPayServiceImpl.java
  8. 4
      cereshop-business/src/main/java/com/shop/cereshop/business/pay/xs/service/impl/XsPayServiceImpl.java
  9. 2
      cereshop-business/src/main/java/com/shop/cereshop/business/service/activity/impl/CereActivitySignServiceImpl.java
  10. 2
      cereshop-business/src/main/java/com/shop/cereshop/business/service/order/impl/CereShopOrderServiceImpl.java
  11. 2
      cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/activity/CereActivitySign.java

2
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);

4
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;
/**

6
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<String,String> orderRefund(String orderFormId, String outTradeNo, String transactionId,String outRefundNo,BigDecimal total,BigDecimal refund) throws CoBusinessException,Exception;
public Map<String,String> orderRefund(String project, String orderFormId, String outTradeNo, String transactionId,String outRefundNo,BigDecimal total,BigDecimal refund) throws CoBusinessException,Exception;
}

4
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<String, String> orderRefund(String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception {
public Map<String, String> orderRefund(String project, String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception {
Map<String, String> 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);

4
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<String, String> orderRefund(String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception {
public Map<String, String> orderRefund(String project, String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception {
return null;
}
}

4
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<String, String> orderRefund(String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception {
public Map<String, String> orderRefund(String project, String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception {
List<CereShopOrder> orderList = null;
String cereOrderFormId = orderFormId;
String[] split = orderFormId.split("-");

68
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<String, String> 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<String, String> refundWithV3(String transactionId, String outRefundNo,
private Map<String, String> refundWithV3(String project, String transactionId, String outRefundNo,
BigDecimal total, BigDecimal refund) throws Exception {
log.info(" orderRefund refundWithV3 {}, {}, {}, {}", transactionId, outRefundNo,
total, refund);
Map<String, Object> 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<String, Object>(){
{
put("refund", refund.multiply(new BigDecimal(100)).intValue());
@ -137,18 +138,19 @@ public class WxPayServiceImpl implements WxPayService {
return result;
}
private Map<String, String> refundWithNormal(String transactionId, String outRefundNo,
private Map<String, String> 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<String, String> 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<String, String> 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<String, String> orderRefund(String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception {
return null;
public Map<String, String> 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);
}
}
}

4
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<String, String> orderRefund(String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception {
public Map<String, String> orderRefund(String project, String orderFormId, String outTradeNo, String transactionId, String outRefundNo, BigDecimal total, BigDecimal refund) throws CoBusinessException, Exception {
Map<String, Object> 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<String, Object> contentMap = build05ContentMap(orderFormid, money, tradeType, XsPayEnum.PAY_TYPE_QRCODE.getCode(), XspayConfig.BUSINESS_RETURN_URL,
XspayConfig.BUSINESS_NOTICE_URL);

2
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<EncodeHintType, Object> hints = new HashMap<>();

2
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<String, String> resultMap = payService.orderRefund(refund.getOrderFormid(), refund.getOutTradeNo(), refund.getTransactionId(), refund.getOutRefundNo(), refund.getTotalFee(), refund.getTotalFee());
Map<String, String> 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())){

2
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;

Loading…
Cancel
Save