This commit is contained in:
2026-01-14 18:31:52 +08:00
parent e301f996ad
commit c48c0f6d7d
9 changed files with 76 additions and 30 deletions

View File

@@ -43,4 +43,30 @@ public interface SystemConstants {
*/ */
public static final String CUSTOM = "custom"; public static final String CUSTOM = "custom";
} }
/**
* 三方支付类型
*/
class PayType {
/**
* 微信支付
*/
public static final String WECHAT = "wechatPay";
/**
* 支付宝支付
*/
public static final String ALIPAY = "alipay";
/**
* 微信小程序支付
*/
public static final String WECHAT_APP_ID = "wxd88fffa983758a30";
/**
* 支付宝小程序支付
*/
public static final String ALIPAY_APP_ID = "2021004145625815";
}
} }

View File

@@ -24,6 +24,10 @@ public class MkDistributionPayDTO implements Serializable {
private Long shopId; private Long shopId;
private String platformType = "DIS"; private String platformType = "DIS";
private Long userId; private Long userId;
/**
* 支付类型
* {@link com.czg.constants.SystemConstants.PayType}
*/
private String payType; private String payType;
private String returnUrl; private String returnUrl;
private String buyerRemark; private String buyerRemark;

View File

@@ -3,6 +3,7 @@ package com.czg.order.entity;
import com.mybatisflex.annotation.Column; import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id; import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.Table; import com.mybatisflex.annotation.Table;
import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@@ -45,6 +46,15 @@ public class ShopMerchant implements Serializable {
*/ */
private String relatedLicenceNo; private String relatedLicenceNo;
/**
* 微信appid
*/
private String wechatAppId;
/**
* 支付宝appid
*/
private String alipayAppId;
/** /**
* 聚合支付参数 * 聚合支付参数
*/ */

View File

@@ -63,6 +63,7 @@ public class CzgPayBaseReq<T> {
/** /**
* 支付类型 * 支付类型
* {@link com.czg.constants.SystemConstants.PayType}
*/ */
private String payType; private String payType;
/** /**

View File

@@ -18,12 +18,6 @@ public class PolyMerchantDTO {
@NotEmpty(message = "商户秘钥不为空") @NotEmpty(message = "商户秘钥不为空")
private String appSecret; private String appSecret;
// 支付密码 // 支付密码
@NotEmpty(message = "支付密码不为空") // @NotEmpty(message = "支付密码不为空")
private String payPassword; private String payPassword;
// 微信appid
@NotEmpty(message = "微信appid")
private String wechatSmallAppid;
// 支付宝appid
@NotEmpty(message = "支付宝appid")
private String alipaySmallAppid;
} }

View File

@@ -7,6 +7,7 @@ import com.czg.account.service.ShopUserService;
import com.czg.account.service.UserInfoService; import com.czg.account.service.UserInfoService;
import com.czg.constant.TableValueConstant; import com.czg.constant.TableValueConstant;
import com.czg.constants.PayTypeConstants; import com.czg.constants.PayTypeConstants;
import com.czg.constants.SystemConstants;
import com.czg.enums.CzgPayEnum; import com.czg.enums.CzgPayEnum;
import com.czg.exception.CzgException; import com.czg.exception.CzgException;
import com.czg.market.service.MkDistributionConfigService; import com.czg.market.service.MkDistributionConfigService;
@@ -82,7 +83,7 @@ public class DistributionPayServiceImpl implements DistributionPayService {
} else { } else {
UserInfo userInfo = userInfoService.getById(userId); UserInfo userInfo = userInfoService.getById(userId);
initInfo.setPayment(orderPayment).setShopUser(shopUserInfo) initInfo.setPayment(orderPayment).setShopUser(shopUserInfo)
.setOpenId("aliPay".equals(payParam.getPayType()) ? userInfo.getAlipayOpenId() : userInfo.getWechatOpenId()); .setOpenId(SystemConstants.PayType.ALIPAY.equals(payParam.getPayType()) ? userInfo.getAlipayOpenId() : userInfo.getWechatOpenId());
} }
return initInfo; return initInfo;
} }

View File

@@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.czg.PayAdapter; import com.czg.PayAdapter;
import com.czg.PayAdapterFactory; import com.czg.PayAdapterFactory;
import com.czg.constants.SystemConstants;
import com.czg.order.entity.ShopMerchant; import com.czg.order.entity.ShopMerchant;
import com.czg.order.service.ShopMerchantService; import com.czg.order.service.ShopMerchantService;
import com.czg.constant.PayChannelCst; import com.czg.constant.PayChannelCst;
@@ -63,6 +64,10 @@ public class PayServiceImpl implements PayService {
} else if (shopMerchant.getChannel().equals(PayChannelCst.POLY)) { } else if (shopMerchant.getChannel().equals(PayChannelCst.POLY)) {
payData = shopMerchant.getPolyPayJson(); payData = shopMerchant.getPolyPayJson();
} }
bizData.setSubAppid(SystemConstants.PayType.ALIPAY.equals(bizData.getPayType()) ? shopMerchant.getAlipayAppId() : shopMerchant.getWechatAppId());
if (payType.equals(CzgPayEnum.MICRO_PAY)) {
checkMicroPay((CzgPayBaseReq<String>) bizData, shopMerchant);
}
return adapter.pay(payType, payData, getDomain(), getNotifyUrl(shopMerchant.getChannel()), bizData); return adapter.pay(payType, payData, getDomain(), getNotifyUrl(shopMerchant.getChannel()), bizData);
} }
@@ -211,4 +216,25 @@ public class PayServiceImpl implements PayService {
} }
return notifyUrl; return notifyUrl;
} }
private void checkMicroPay(CzgPayBaseReq<String> bizData, ShopMerchant shopMerchant) {
String data = bizData.getData();
AssertUtil.isBlank(data, "扫码失败,请重试");
if (data.length() > 26) {
throw new CzgException("支付失败,不支持的条码");
}
String firstTwoDigitsStr = data.substring(0, 2);
// 将截取的字符串转换为整数
int firstTwoDigits = Integer.parseInt(firstTwoDigitsStr);
// 判断范围
if (firstTwoDigits >= 10 && firstTwoDigits <= 15) {
//微信支付
bizData.setSubAppid(shopMerchant.getWechatAppId());
} else if (firstTwoDigits >= 25 && firstTwoDigits <= 30) {
//支付宝支付
bizData.setSubAppid(shopMerchant.getAlipayAppId());
} else {
throw new CzgException("扫描码非法或暂不支持");
}
}
} }

View File

@@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.czg.account.service.ShopInfoService; import com.czg.account.service.ShopInfoService;
import com.czg.constant.PayChannelCst; import com.czg.constant.PayChannelCst;
import com.czg.constants.SystemConstants;
import com.czg.order.dto.ShopMerchantDTO; import com.czg.order.dto.ShopMerchantDTO;
import com.czg.order.entity.ShopDirectMerchant; import com.czg.order.entity.ShopDirectMerchant;
import com.czg.order.entity.ShopMerchant; import com.czg.order.entity.ShopMerchant;
@@ -75,6 +76,8 @@ public class ShopMerchantServiceImpl extends ServiceImpl<ShopMerchantMapper, Sho
shopMerchant = new ShopMerchant(); shopMerchant = new ShopMerchant();
shopMerchant.setChannel(shopMerchantParam.getChannel()); shopMerchant.setChannel(shopMerchantParam.getChannel());
shopMerchant.setRelatedLicenceNo(shopMerchantParam.getRelatedLicenceNo()); shopMerchant.setRelatedLicenceNo(shopMerchantParam.getRelatedLicenceNo());
shopMerchant.setAlipayAppId(SystemConstants.PayType.ALIPAY_APP_ID);
shopMerchant.setWechatAppId(SystemConstants.PayType.WECHAT_APP_ID);
if (PayChannelCst.NATIVE.equals(shopMerchantParam.getChannel()) && shopMerchantParam.getNativeMerchantDTO() != null) { if (PayChannelCst.NATIVE.equals(shopMerchantParam.getChannel()) && shopMerchantParam.getNativeMerchantDTO() != null) {
shopMerchant.setNativePayJson(JSONObject.toJSONString(shopMerchantParam.getNativeMerchantDTO())); shopMerchant.setNativePayJson(JSONObject.toJSONString(shopMerchantParam.getNativeMerchantDTO()));
} else if (PayChannelCst.POLY.equals(shopMerchantParam.getChannel()) && shopMerchantParam.getPolyMerchantDTO() != null) { } else if (PayChannelCst.POLY.equals(shopMerchantParam.getChannel()) && shopMerchantParam.getPolyMerchantDTO() != null) {

View File

@@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSONObject;
import com.czg.PayAdapter; import com.czg.PayAdapter;
import com.czg.PolyPayUtils; import com.czg.PolyPayUtils;
import com.czg.constant.PayChannelCst; import com.czg.constant.PayChannelCst;
import com.czg.constants.SystemConstants;
import com.czg.entity.resp.CzgBaseResp; import com.czg.entity.resp.CzgBaseResp;
import com.czg.entity.resp.CzgRefundResp; import com.czg.entity.resp.CzgRefundResp;
import com.czg.enums.CzgPayEnum; import com.czg.enums.CzgPayEnum;
@@ -75,16 +76,14 @@ public class PolyPayAdapter implements PayAdapter {
} }
private CzgResult<Map<String, Object>> jsPay(PolyMerchantDTO shopMerchant, String domain, String notifyUrl, CzgPayBaseReq<?> bizData) { private CzgResult<Map<String, Object>> jsPay(PolyMerchantDTO shopMerchant, String domain, String notifyUrl, CzgPayBaseReq<?> bizData) {
bizData.setSubAppid("aliPay".equals(bizData.getPayType()) ? shopMerchant.getAlipaySmallAppid() : shopMerchant.getWechatSmallAppid()); AssertUtil.isBlank(bizData.getSubAppid(), "暂不可用,请联系商家配置" + (SystemConstants.PayType.ALIPAY.equals(bizData.getPayType()) ? "支付宝" : "微信") + "小程序");
AssertUtil.isBlank(bizData.getSubAppid(), "暂不可用,请联系商家配置" + ("aliPay".equals(bizData.getPayType()) ? "支付宝" : "微信") + "小程序"); bizData.setPayType(SystemConstants.PayType.ALIPAY.equals(bizData.getPayType()) ? "ALIPAY" : "WECHAT");
bizData.setPayType("aliPay".equals(bizData.getPayType()) ? "ALIPAY" : "WECHAT");
bizData.polyBase(shopMerchant.getStoreId(), notifyUrl); bizData.polyBase(shopMerchant.getStoreId(), notifyUrl);
return PolyPayUtils.jsPay(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData); return PolyPayUtils.jsPay(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
} }
private CzgResult<Map<String, Object>> ltPay(PolyMerchantDTO shopMerchant, String domain, String notifyUrl, CzgPayBaseReq<?> bizData) { private CzgResult<Map<String, Object>> ltPay(PolyMerchantDTO shopMerchant, String domain, String notifyUrl, CzgPayBaseReq<?> bizData) {
bizData.setSubAppid("aliPay".equals(bizData.getPayType()) ? shopMerchant.getAlipaySmallAppid() : shopMerchant.getWechatSmallAppid());
AssertUtil.isBlank(bizData.getSubAppid(), "暂不可用,请联系商家配置" + ("aliPay".equals(bizData.getPayType()) ? "支付宝" : "微信") + "小程序"); AssertUtil.isBlank(bizData.getSubAppid(), "暂不可用,请联系商家配置" + ("aliPay".equals(bizData.getPayType()) ? "支付宝" : "微信") + "小程序");
bizData.polyBase(shopMerchant.getStoreId(), notifyUrl); bizData.polyBase(shopMerchant.getStoreId(), notifyUrl);
return PolyPayUtils.ltPay(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData); return PolyPayUtils.ltPay(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
@@ -96,25 +95,7 @@ public class PolyPayAdapter implements PayAdapter {
} }
private CzgResult<Map<String, Object>> microPay(PolyMerchantDTO shopMerchant, String domain, String notifyUrl, CzgPayBaseReq<String> bizData) { private CzgResult<Map<String, Object>> microPay(PolyMerchantDTO shopMerchant, String domain, String notifyUrl, CzgPayBaseReq<String> bizData) {
AssertUtil.isBlank(bizData.getData(), "扫码失败,请重试");
if (bizData.getData().length() > 26) {
throw new CzgException("支付失败,不支持的条码");
}
bizData.polyBase(shopMerchant.getStoreId(), notifyUrl); bizData.polyBase(shopMerchant.getStoreId(), notifyUrl);
String firstTwoDigitsStr = bizData.getData().substring(0, 2);
// 将截取的字符串转换为整数
int firstTwoDigits = Integer.parseInt(firstTwoDigitsStr);
// 判断范围
if (firstTwoDigits >= 10 && firstTwoDigits <= 15) {
//微信支付
bizData.setSubAppid(shopMerchant.getWechatSmallAppid());
} else if (firstTwoDigits >= 25 && firstTwoDigits <= 30) {
//支付宝支付
bizData.setSubAppid(shopMerchant.getAlipaySmallAppid());
} else {
throw new CzgException("扫描码非法或暂不支持");
}
return PolyPayUtils.microPay(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData); return PolyPayUtils.microPay(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
} }
} }