支付调整

This commit is contained in:
2026-01-14 17:04:48 +08:00
parent e8be5dee9d
commit 4eaedcce41
70 changed files with 1065 additions and 829 deletions

View File

@@ -3,9 +3,9 @@ package com.czg.controller;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.IoUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.CzgPayUtils;
import com.czg.PolyPayUtils;
import com.czg.constants.PayTypeConstants;
import com.czg.entity.CzgBaseRespParams;
import com.czg.entity.PolyBaseResp;
import com.czg.market.entity.MkShopConsumeDiscountRecord;
import com.czg.market.service.MkDistributionUserService;
import com.czg.market.service.MkShopConsumeDiscountRecordService;
@@ -61,8 +61,8 @@ public class NotifyController {
@RequestMapping("/payCallBack")
public String notifyCallBack(@RequestBody CzgBaseRespParams respParams) {
JSONObject czg = CzgPayUtils.getCzg(respParams);
public String notifyCallBack(@RequestBody PolyBaseResp respParams) {
JSONObject czg = PolyPayUtils.getCzg(respParams);
AssertUtil.isNull(czg, "支付回调数据为空");
log.info("支付回调数据为:{}", czg);
orderInfoCustomService.payCallBackOrder(czg.getString("mchOrderNo"), czg, 0);
@@ -89,10 +89,10 @@ public class NotifyController {
@RequestMapping("/native/wx/pay/distributionRecharge")
public String nativeNotify(HttpServletRequest request) throws IOException {
String timestamp = request.getHeader("Wechatpay-Timestamp");
String nonce = request.getHeader("Wechatpay-Nonce");
String serialNo = request.getHeader("Wechatpay-Serial");
String signature = request.getHeader("Wechatpay-Signature");
// String timestamp = request.getHeader("Wechatpay-Timestamp");
// String nonce = request.getHeader("Wechatpay-Nonce");
// String serialNo = request.getHeader("Wechatpay-Serial");
// String signature = request.getHeader("Wechatpay-Signature");
String result = IoUtil.readUtf8(request.getInputStream());
JSONObject jsonObject = JSONObject.parseObject(result);
JSONObject resource = jsonObject.getJSONObject("resource");
@@ -127,8 +127,8 @@ public class NotifyController {
@RequestMapping("/refundCallBack")
public String refundCallBack(@RequestBody CzgBaseRespParams respParams) {
JSONObject czg = CzgPayUtils.getCzg(respParams);
public String refundCallBack(@RequestBody PolyBaseResp respParams) {
JSONObject czg = PolyPayUtils.getCzg(respParams);
AssertUtil.isNull(czg, "退款回调数据为空");
log.info("退款回调数据为:{}", czg);
orderInfoCustomService.refundCallBackOrder(czg.getString("mchOrderNo"), czg);

View File

@@ -1,18 +1,18 @@
package com.czg.controller.admin;
import com.czg.account.dto.merchant.ShopMerchantEditDTO;
import com.czg.account.entity.ShopMerchant;
import com.czg.account.service.ShopMerchantService;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.annotation.SaAdminCheckRole;
import com.czg.order.dto.ShopMerchantDTO;
import com.czg.order.entity.ShopDirectMerchant;
import com.czg.order.service.ShopMerchantService;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* 商户信息管理
*
* @author Administrator
*/
@RestController
@@ -24,25 +24,36 @@ public class ShopMerchantController {
/**
* 商户支付信息获取
* 权限标识: shopMerchant:detail
*
* @param shopId 店铺id
* @return 支付信息
*/
@SaAdminCheckRole("管理员")
@SaAdminCheckPermission(parentName = "支付参数信息", value = "shopMerchant:detail", name = "商户支付信息获取")
@GetMapping
public CzgResult<ShopMerchant> detail(@RequestParam Integer shopId) {
public CzgResult<ShopMerchantDTO> detail(@RequestParam Long shopId) {
return CzgResult.success(shopMerchantService.detail(shopId));
}
/**
* 商户支付信息修改
* 权限标识: shopMerchant:edit
*
* @return 是否成功
*/
@SaAdminCheckRole("管理员")
@SaAdminCheckPermission(parentName = "支付参数信息", value = "shopMerchant:edit", name = "商户支付信息修改")
@PutMapping
public CzgResult<Boolean> edit(@RequestBody @Validated ShopMerchantEditDTO shopMerchantEditDTO) {
return CzgResult.success(shopMerchantService.edit(shopMerchantEditDTO));
public CzgResult<Boolean> edit(@RequestBody ShopMerchantDTO shopMerchant) {
shopMerchant.setShopId(StpKit.USER.getShopId());
return CzgResult.success(shopMerchantService.editEntry(shopMerchant, true));
}
/**
* 获取当前店铺的主店进件信息
*/
@GetMapping("getMainMerchant")
public CzgResult<ShopDirectMerchant> getMainMerchant() {
return CzgResult.success(shopMerchantService.getMainMerchant(StpKit.USER.getShopId()));
}
}

View File

@@ -4,9 +4,12 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.EntryManager;
import com.czg.PayCst;
import com.czg.account.service.ShopInfoService;
import com.czg.constant.PayChannelCst;
import com.czg.dto.resp.QueryStatusResp;
import com.czg.order.dto.ShopMerchantDTO;
import com.czg.order.entity.ShopDirectMerchant;
import com.czg.order.service.ShopMerchantService;
import com.czg.pay.NativeMerchantDTO;
import com.czg.service.order.service.ShopDirectMerchantService;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
@@ -28,7 +31,7 @@ public class EntryManagerTask {
@Resource
private ShopDirectMerchantService shopDirectMerchantService;
@DubboReference
private ShopInfoService shopInfoService;
private ShopMerchantService shopMerchantService;
//每10分钟查一次
@Scheduled(cron = "0 0/10 * * * ? ")
@@ -58,7 +61,8 @@ public class EntryManagerTask {
QueryStatusResp wechatStatus = EntryManager.queryWechatEntryStatus(shopDirectMerchant.getWechatApplyId());
shopDirectMerchant.setWechatStatus(wechatStatus.getStatus());
shopDirectMerchant.setWechatErrorMsg(wechatStatus.getFailReason());
shopDirectMerchant.setWechatSignUrl(wechatStatus.getSignUrl());
shopDirectMerchant.setWechatSignUrl("");
shopDirectMerchant.setWechatMerchantId(wechatStatus.getThirdMerchantId());
if (PayCst.EntryStatus.FINISH.equals(wechatStatus.getStatus())) {
wechatMerchantId = wechatStatus.getThirdMerchantId();
}
@@ -67,14 +71,24 @@ public class EntryManagerTask {
QueryStatusResp alipayStatus = EntryManager.queryAlipayEntryStatus(shopDirectMerchant.getAlipayOrderId());
shopDirectMerchant.setAlipayStatus(alipayStatus.getStatus());
shopDirectMerchant.setAlipayErrorMsg(alipayStatus.getFailReason());
shopDirectMerchant.setAlipaySignUrl(alipayStatus.getSignUrl());
shopDirectMerchant.setAlipaySignUrl("");
shopDirectMerchant.setAlipayMerchantId(alipayStatus.getThirdMerchantId());
if (PayCst.EntryStatus.FINISH.equals(alipayStatus.getStatus())) {
alipayMerchantId = alipayStatus.getThirdMerchantId();
}
}
shopDirectMerchantService.updateById(shopDirectMerchant);
if (StrUtil.isNotBlank(wechatMerchantId) || StrUtil.isNotBlank(alipayMerchantId)) {
shopInfoService.editEntry(shopDirectMerchant.getShopId(), wechatMerchantId, alipayMerchantId, shopDirectMerchant.getAlipayAuthInfo());
ShopMerchantDTO shopMerchantDTO = new ShopMerchantDTO();
shopMerchantDTO.setShopId(shopId);
shopMerchantDTO.setChannel(PayChannelCst.NATIVE);
shopMerchantDTO.setRelatedLicenceNo(licenceNo);
NativeMerchantDTO nativeMerchantDTO = new NativeMerchantDTO();
nativeMerchantDTO.setWechatMerchantId(wechatMerchantId);
nativeMerchantDTO.setAlipayMerchantId(alipayMerchantId);
shopMerchantDTO.setNativeMerchantDTO(nativeMerchantDTO);
shopMerchantDTO.setNativeMerchantDTO(nativeMerchantDTO);
shopMerchantService.editEntry(shopMerchantDTO, false);
}
}
}

View File

@@ -32,7 +32,6 @@ public class ShopInfo implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 使用系统用户 sys_user id
*/
@@ -142,18 +141,6 @@ public class ShopInfo implements Serializable {
* -1 平台禁用 0-过期1正式营业
*/
private Integer status;
/**
* 微信商户id
*/
private String wechatMerchantId;
/**
* 支付宝商户id
*/
private String alipayMerchantId;
/**
* 支付宝授权信息
*/
private String alipayAuthInfo;
/**
* 到期时间

View File

@@ -38,11 +38,6 @@ public interface ShopInfoService extends IService<ShopInfo> {
Boolean edit(ShopInfoEditDTO shopInfoEditDTO);
/**
* 进件结果保存
*/
Boolean editEntry(Long shopId, String wechatMerchantId, String alipayMerchantId, String alipayAuthInfo);
ShopDetailDTO detail(Long id) throws CzgException;
ShopInfoByCodeDTO getByCode(String tableCode, String lat, String lng, boolean checkState);

View File

@@ -1,22 +0,0 @@
package com.czg.account.service;
import com.czg.account.dto.merchant.ShopMerchantEditDTO;
import com.czg.account.entity.ShopMerchant;
import com.mybatisflex.core.service.IService;
import java.io.Serializable;
/**
* 第三方商户进件 服务层。
*
* @author Administrator
* @since 2025-02-11
*/
public interface ShopMerchantService extends IService<ShopMerchant> {
ShopMerchant detail(Integer shopId);
Boolean edit(ShopMerchantEditDTO shopMerchantEditDTO);
@Override
ShopMerchant getById(Serializable id);
}

View File

@@ -79,7 +79,9 @@ public interface ParamCodeCst {
* 超掌柜支付回调地址
* <p>支付宝/微信支付完成后,支付平台回调我方系统的地址</p>
*/
public static String PAY_CZG_NOTIFY_URL = "pay_czg_notify_url";
// public static String PAY_CZG_NOTIFY_URL = "pay_czg_notify_url";
public static String NATIVE_PAY_NOTIFY_URL = "native_pay_notify_url";
public static String POLY_PAY_NOTIFY_URL = "poly_pay_notify_url";
/**
* 排队到号通知
*/

View File

@@ -28,6 +28,7 @@ public class OrderInfoAddDTO implements Serializable {
* 已出菜 SENT_OUT
* 已上菜 DELIVERED
* 已超时 EXPIRED
* 加急 URGENT
*/
private String subStatus;
//限时折扣部分

View File

@@ -0,0 +1,40 @@
package com.czg.order.dto;
import com.czg.order.entity.ShopDirectMerchant;
import com.czg.pay.NativeMerchantDTO;
import com.czg.pay.PolyMerchantDTO;
import lombok.Data;
/**
* 支付信息
*
* @author ww
*/
@Data
public class ShopMerchantDTO {
private Long shopId;
/**
* poly 聚合(支付平台) native 原生(wx/ali 原生)
* {@link com.czg.constant.PayChannelCst}
*/
private String channel;
/**
* 聚合支付商户
* native 必填 对应 tb_shop_direct_merchant 的 licence_no 营业执照
*/
private String relatedLicenceNo;
/**
* 原生支付参数
*/
private NativeMerchantDTO nativeMerchantDTO;
/**
* 聚合支付参数
*/
private PolyMerchantDTO polyMerchantDTO;
/**
* 店铺绑定的商户信息
*/
private ShopDirectMerchant shopDirectMerchant;
}

View File

@@ -5,6 +5,7 @@ import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@@ -40,6 +41,12 @@ public class OrderPayment implements Serializable {
*/
private Long shopId;
/**
* 支付渠道
* {@link com.czg.constant.PayChannelCst}
*/
private String channel;
/**
* 来源Id 订单Id或充值id
*/
@@ -104,28 +111,66 @@ public class OrderPayment implements Serializable {
public OrderPayment() {
}
public OrderPayment(@NonNull Long shopId,@NonNull Long sourceId, @NotBlank String sourceType,@NotBlank String payType, @NotBlank String orderNo,
String authCode, @NonNull BigDecimal amount) {
this.shopId = shopId;
this.sourceId = sourceId;
this.sourceType = sourceType;
this.payType = payType;
this.orderNo = orderNo;
this.authCode = authCode;
this.amount = amount;
this.payStatus = PayTypeConstants.PayStatus.INIT;
/**
* 订单专用支付
*
* @param sourceId 订单Id
* @param amount 单元 元
* @param authCode 扫码支付时必填 扫描码
*/
public static OrderPayment orderPay(@NonNull Long shopId, @NonNull Long sourceId,
@NotBlank String orderNo, @NonNull BigDecimal amount, String authCode) {
OrderPayment orderPayment = getInstance(shopId, sourceId, PayTypeConstants.SourceType.ORDER, orderNo, amount, authCode, null);
orderPayment.setPayType(PayTypeConstants.PayType.PAY);
orderPayment.setPayStatus(PayTypeConstants.PayStatus.INIT);
return orderPayment;
}
public OrderPayment(@NonNull Long shopId,@NonNull Long sourceId, @NotBlank String sourceType,@NotBlank String payType, @NotBlank String orderNo,
String authCode, @NonNull BigDecimal amount, Long relatedId) {
this.shopId = shopId;
this.sourceId = sourceId;
this.sourceType = sourceType;
this.payType = payType;
this.orderNo = orderNo;
this.authCode = authCode;
this.amount = amount;
this.relatedId = relatedId;
this.payStatus = PayTypeConstants.PayStatus.INIT;
/**
* 初始化支付参数
*
* @param sourceId 充值时为会员Id shopUserID
* 购买时为商品Id
* @param sourceType {@link PayTypeConstants.SourceType} 支付来源
* @param amount 单元 元
* @param authCode 扫码支付时必填 扫描码
* @param relatedId 霸王餐充值为 订单id 会员充值为 活动id 充值并支付时 为 MkShopRechargeDetail
*/
public static OrderPayment pay(@NonNull Long shopId, @NonNull Long sourceId, @NotBlank String sourceType,
@NotBlank String orderNo, @NonNull BigDecimal amount,
String authCode, Long relatedId) {
OrderPayment orderPayment = getInstance(shopId, sourceId, sourceType, orderNo, amount, authCode, relatedId);
orderPayment.setPayType(PayTypeConstants.PayType.PAY);
orderPayment.setPayStatus(PayTypeConstants.PayStatus.INIT);
return orderPayment;
}
public static OrderPayment refund(@NonNull Long shopId, @NonNull Long sourceId, @NotBlank String sourceType,
@NotBlank String orderNo, @NonNull BigDecimal amount, Long relatedId) {
OrderPayment orderPayment = getInstance(shopId, sourceId, sourceType, orderNo, amount, null, relatedId);
orderPayment.setPayType(PayTypeConstants.PayType.REFUND);
orderPayment.setPayStatus(PayTypeConstants.PayStatus.INIT);
return orderPayment;
}
public static OrderPayment refundCompensate(@NonNull Long shopId, @NonNull Long sourceId, @NotBlank String sourceType,
@NotBlank String orderNo, @NonNull BigDecimal amount, Long relatedId) {
OrderPayment orderPayment = getInstance(shopId, sourceId, sourceType, orderNo, amount, null, relatedId);
orderPayment.setPayType(PayTypeConstants.PayType.REFUND_COMPENSATE);
orderPayment.setPayStatus(PayTypeConstants.PayStatus.INIT);
return orderPayment;
}
private static OrderPayment getInstance(Long shopId, Long sourceId, String sourceType,
String orderNo, BigDecimal amount, String authCode, Long relatedId) {
OrderPayment orderPayment = new OrderPayment();
orderPayment.shopId = shopId;
orderPayment.sourceId = sourceId;
orderPayment.sourceType = sourceType;
orderPayment.orderNo = orderNo;
orderPayment.authCode = authCode;
orderPayment.amount = amount;
orderPayment.relatedId = relatedId;
return orderPayment;
}
}

View File

@@ -44,7 +44,6 @@ public class ShopDirectMerchant implements Serializable {
/**
* 营业执照编号
*/
@Id
private String licenceNo;
/**
* 支付宝账号
@@ -124,11 +123,6 @@ public class ShopDirectMerchant implements Serializable {
*/
private String alipayStatus;
/**
* 支付宝授信息
*/
private String alipayAuthInfo;
/**
* 支付宝进件错误信息
*/
@@ -138,4 +132,18 @@ public class ShopDirectMerchant implements Serializable {
*/
private String alipaySignUrl;
/**
* 支付宝授信息
*/
private String alipayAuthInfo;
/**
* 微信商户id
*/
private String wechatMerchantId;
/**
* 支付宝商户id
*/
private String alipayMerchantId;
}

View File

@@ -1,4 +1,4 @@
package com.czg.account.entity;
package com.czg.order.entity;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
@@ -18,57 +18,45 @@ import java.time.LocalDateTime;
* @since 2025-02-11
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_shop_merchant")
@Table("tb_shop_merchant2")
public class ShopMerchant implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Id
private Long id;
/**
* 店铺id
*/
@Id
private Long shopId;
/**
* 支付系统商户id
* poly 聚合(支付平台) native 原生(wx/ali 原生)
* {@link com.czg.constant.PayChannelCst}
*/
private String storeId;
private String merchantName;
private String channel;
/**
* 商户应用id
* 聚合支付商户
* native 必填 对应 tb_shop_direct_merchant licence_no 营业执照
*/
private String appId;
private String relatedLicenceNo;
/**
* 商户token
* 聚合支付参数
*/
private String appSecret;
private String polyPayJson;
/**
* 微信小程序appid
* 原生支付参数
*/
private String wechatSmallAppid;
/**
* 支付宝小程序appid
*/
private String alipaySmallAppid;
/**
* 支付密码
*/
private String payPassword;
private String nativePayJson;
@Column(onInsertValue = "now()")
private LocalDateTime createTime;
@Column(onInsertValue = "now()", onUpdateValue = "now()")
private LocalDateTime updateTime;
}

View File

@@ -0,0 +1,30 @@
package com.czg.order.service;
import com.czg.order.dto.ShopMerchantDTO;
import com.czg.order.entity.ShopDirectMerchant;
import com.czg.order.entity.ShopMerchant;
import com.mybatisflex.core.service.IService;
import java.io.Serializable;
/**
* 第三方商户进件 服务层。
*
* @author Administrator
* @since 2025-02-11
*/
public interface ShopMerchantService extends IService<ShopMerchant> {
ShopMerchantDTO detail(Long shopId);
/**
* 进件结果保存/ 支付参数修改
*/
Boolean editEntry(ShopMerchantDTO shopMerchantParam, boolean isUp);
@Override
ShopMerchant getById(Serializable id);
ShopDirectMerchant getMainMerchant(Long shopId);
}

View File

@@ -1,4 +1,4 @@
package com.czg.third.alipay.dto;
package com.czg.pay;
import com.alibaba.fastjson2.annotation.JSONField;
import lombok.Data;

View File

@@ -0,0 +1,132 @@
package com.czg.pay;
import lombok.Data;
import lombok.NonNull;
/**
* @author ww
*/
@Data
public class CzgPayBaseReq<T> {
//必填范围
/**
* 订单标题
*/
private String subject;
/**
* 订单描述 String(256)
*/
private String body;
/**
* 交易金额 分
*/
private Long amount;
/**
* 货币类型 cny
*/
private String currency = "cny";
/**
* 商户订单号 String(30)
* 操作方式+雪花算法
* 收银机客户端 PC+雪花ID
* 微信小程序 WX+雪花ID
* 支付宝小程序 ALI+雪花ID
* PC管理端 WEB+雪花ID
* APP管理端 APP+雪花ID
* <p>
* 退款 re+雪花ID
*/
private String mchOrderNo;
/**
* 异步通知地址 String(128)
* 支付结果异步回调URL,只有传了该值才会发起回调
*/
private String notifyUrl;
/**
* 扩展参数 String(512)
* 商户扩展参数,回调时会原样返回
* * 扩展参数
* * {
* * "pay_type": "order/vip"
* * }
*/
private String extParam;
/**
* 原生支付 不需要 store_id
*/
private String storeId;
/**
* 支付类型
*/
private String payType;
/**
* 用户唯一标识 String(30)
* 微信支付时传入用户的openId
* 支付宝支付和银联支付时传入用户的userId
*/
private String userId;
/**
* 用户IP
* 需要传付款用户客户端IP地址
*/
private String clientIp;
/**
* 子商户 appid ,微信付款支付的时候 需要上送
* isScreen 为 false 的情况下需要传入
*/
private String subAppid;
/**
* 额外参数
*/
private T data;
public CzgPayBaseReq() {
}
public CzgPayBaseReq(String mchOrderNo, String detail, Long amount, String payType, String userId, String clientIp) {
this.mchOrderNo = mchOrderNo;
this.subject = detail;
this.body = detail;
this.amount = amount;
this.payType = payType;
this.userId = userId;
this.clientIp = clientIp;
}
public void polyBase(@NonNull String storeId, @NonNull String notifyUrl) {
this.storeId = storeId;
this.notifyUrl = notifyUrl;
}
public static CzgPayBaseReq<?> ltPayReq(@NonNull String mchOrderNo, @NonNull String detail, @NonNull Long amount
, @NonNull String payType, @NonNull String openId, @NonNull String clientIp) {
return new CzgPayBaseReq<>(mchOrderNo, detail, amount, payType, openId, clientIp);
}
public static CzgPayBaseReq<?> h5PayReq(@NonNull String mchOrderNo, @NonNull String detail, @NonNull Long amount, @NonNull String clientIp) {
return new CzgPayBaseReq<>(mchOrderNo, detail, amount, null, null, clientIp);
}
public static CzgPayBaseReq<?> jsPayReq(@NonNull String mchOrderNo, @NonNull String detail, @NonNull Long amount
, @NonNull String payType, @NonNull String openId, @NonNull String clientIp) {
return new CzgPayBaseReq<>(mchOrderNo, detail, amount, payType, openId, clientIp);
}
public static CzgPayBaseReq<?> scanPayReq(@NonNull String mchOrderNo, @NonNull String detail, @NonNull Long amount, @NonNull String clientIp) {
return new CzgPayBaseReq<>(mchOrderNo, detail, amount, null, null, clientIp);
}
public static CzgPayBaseReq<String> microPay(@NonNull String mchOrderNo, @NonNull String detail, @NonNull Long amount, @NonNull String authCode) {
CzgPayBaseReq<String> stringReq = new CzgPayBaseReq<>(mchOrderNo, detail, amount, null, null, null);
stringReq.setData(authCode);
return stringReq;
}
}

View File

@@ -1,4 +1,4 @@
package com.czg.entity.req;
package com.czg.pay;
import lombok.Data;
import lombok.NonNull;
@@ -23,7 +23,10 @@ public class CzgRefundReq {
* 单位为分
*/
private Long refundAmount;
/**
* 原订单总金额 单位
*/
private Long orderTotalAmount;
//非必填范围
/**
@@ -51,10 +54,11 @@ public class CzgRefundReq {
* payOrderId和mchOrderNo 二选一 必填
*/
public CzgRefundReq(@NonNull String mchRefundNo, @NonNull String refundReason, @NonNull Long refundAmount,
String mchOrderNo, String extParam) {
@NonNull Long orderTotalAmount, String mchOrderNo, String extParam) {
this.mchRefundNo = mchRefundNo;
this.refundReason = refundReason;
this.refundAmount = refundAmount;
this.orderTotalAmount = orderTotalAmount;
this.mchOrderNo = mchOrderNo;
this.extParam = extParam;
}

View File

@@ -0,0 +1,17 @@
package com.czg.pay;
import lombok.Data;
/**
* 原生支付参数
* @author ww
*/
@Data
public class NativeMerchantDTO {
private String wechatMerchantId;
private String alipayMerchantId;
/**
* 支付宝 授权信息解析
*/
private AlipayAuthInfoDto alipayAuthInfo;
}

View File

@@ -1,16 +1,14 @@
package com.czg.account.dto.merchant;
package com.czg.pay;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
/**
* @author Administrator
* 聚合支付参数
* @author ww
*/
@Data
public class ShopMerchantEditDTO {
@NotNull(message = "店铺id不为空")
private Long shopId;
public class PolyMerchantDTO {
@NotEmpty(message = "支付系统商户id不为空")
private String storeId;
@NotEmpty(message = "支付系统商户名称不为空")

View File

@@ -0,0 +1,18 @@
package com.czg.constant;
/**
* 支付渠道常量
* @author ww
*/
public interface PayChannelCst {
/**
* 聚合支付
* 对应 类 PolyPay
*/
String POLY = "poly";
/**
* 原生支付
* 对应 类 NativePay
*/
String NATIVE = "native";
}

View File

@@ -44,7 +44,6 @@
<netty.version>4.1.128.Final</netty.version>
<wechatpay.version>0.2.17</wechatpay.version>
<apipay-v3.version>3.1.65.ALL</apipay-v3.version>
<dom4j.version>2.2.0</dom4j.version>
</properties>
<dependencyManagement>
@@ -283,13 +282,6 @@
<artifactId>alipay-sdk-java-v3</artifactId>
<version>${apipay-v3.version}</version>
</dependency>
<dependency>
<groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>${dom4j.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
</dependencyManagement>

View File

@@ -35,13 +35,6 @@
<artifactId>ocr_api20210707</artifactId>
<version>3.1.2</version>
</dependency>
<!-- Source: https://mvnrepository.com/artifact/org.dom4j/dom4j -->
<dependency>
<groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@@ -9,7 +9,6 @@ import com.czg.exception.CzgException;
import com.czg.third.alipay.AlipayEntryManager;
import com.czg.third.alipay.AlipayIsvEntryManager;
import com.czg.third.wechat.WechatEntryManager;
import com.czg.third.wechat.dto.req.entry.business.sales.WechatEntryStoreInfoReqDto;
import com.czg.utils.AssertUtil;
import com.czg.utils.AsyncTaskExecutor;
import org.jetbrains.annotations.NotNull;
@@ -385,8 +384,8 @@ public class EntryManager {
// verifyEntryParam(merchantDto);
// uploadParamImage(merchantDto);
//// System.out.println(merchantDto);
// EntryRespDto respDto = entryMerchant(merchantDto, PayCst.Platform.WECHAT);
EntryRespDto respDto = entryMerchant(merchantDto, PayCst.Platform.ALIPAY);
EntryRespDto respDto = entryMerchant(merchantDto, PayCst.Platform.WECHAT);
// entryMerchant(merchantDto, PayCst.Platform.ALIPAY);
// entryMerchant(merchantDto, PayCst.Platform.WECHAT, PayCst.Platform.ALIPAY);
System.out.println(respDto);
}

View File

@@ -1,51 +1,22 @@
package com.czg;
import com.czg.dto.req.PayParamsDto;
import com.czg.exception.CzgException;
import com.czg.third.alipay.AlipayIsvPayManager;
import com.czg.third.wechat.WechatPayManager;
import java.util.Map;
/**
* @author yjjie
* @date 2026/1/9 11:24
*/
public class PayManager {
/**
* jsapi支付
*
* @param paramsDto 参数
* @return 结果
*/
public static Map<String, Object> jsapiPay(PayParamsDto paramsDto) {
public static void jsapiPay(PayParamsDto paramsDto) {
paramsDto.verifyParams();
if (PayCst.Platform.WECHAT.equals(paramsDto.getPlatform())) {
return WechatPayManager.jsapiPay(null, paramsDto);
WechatPayManager.jsapiPay(null, paramsDto);
} else if (PayCst.Platform.ALIPAY.equals(paramsDto.getPlatform())) {
return AlipayIsvPayManager.jsapiPay(null, paramsDto);
} else {
throw new CzgException("不支持的支付平台");
}
}
/**
* 条码支付
*
* @param paramsDto 参数
* @return 结果
*/
public static Map<String, Object> barPay(PayParamsDto paramsDto) {
paramsDto.verifyParams();
if (PayCst.Platform.WECHAT.equals(paramsDto.getPlatform())) {
return WechatPayManager.barPay(null, paramsDto);
} else if (PayCst.Platform.ALIPAY.equals(paramsDto.getPlatform())) {
return AlipayIsvPayManager.barPay(null, paramsDto);
} else {
throw new CzgException("不支持的支付平台");
AlipayIsvPayManager.jsapiPay(null, paramsDto);
}
}
@@ -64,10 +35,10 @@ public class PayManager {
jsapiPay(new PayParamsDto()
.setPlatform(PayCst.Platform.WECHAT)
.setAppId("wxd88fffa983758a30")
.setOpenId("or1l86yipGvwyfPhrKIAcQuSfAV8")
.setOpenId("123123123")
.setOrderNo("1111231231213")
.setTitle("1213")
.setMerchantId("1738216504")
.setMerchantId("1665469114")
.setBody("1213")
.setAmount(1000L)
.setPayParams("{\"app_auth_token\": \"ssss\"}")

View File

@@ -3,7 +3,7 @@ package com.czg.dto.req;
import com.alibaba.fastjson2.JSONObject;
import com.czg.PayCst;
import com.czg.exception.CzgException;
import com.czg.third.alipay.dto.AlipayAuthInfoDto;
import com.czg.pay.AlipayAuthInfoDto;
import com.czg.utils.AssertUtil;
import lombok.Data;
import lombok.experimental.Accessors;

View File

@@ -9,13 +9,12 @@ import com.czg.dto.req.*;
import com.czg.dto.resp.EntryThirdRespDto;
import com.czg.dto.resp.QueryStatusResp;
import com.czg.exception.CzgException;
import com.czg.third.alipay.dto.AlipayAuthInfoDto;
import com.czg.pay.AlipayAuthInfoDto;
import com.czg.third.alipay.dto.config.AlipayConfigDto;
import com.czg.utils.UploadFileUtil;
import lombok.extern.slf4j.Slf4j;
import java.io.File;
import java.io.IOException;
/**
* 支付宝服务商进件管理

View File

@@ -56,7 +56,6 @@ public class WechatPayConfigDto {
return new WechatPayConfigDto()
.setMerchantId("1643779408")
.setApiV3Key("a92baac5eb7a36ed8ec198113e769a03")
.setApiV2Key("3caf37225b6ea77a624ee03b7e3d03bb")
.setSerialNumber("4DE9BAC2EA584C3F274F694C9753CA814C4E9BF4")
.setPublicKey("""
-----BEGIN PUBLIC KEY-----

View File

@@ -1,124 +0,0 @@
package com.czg.entity.req;
import lombok.Data;
import lombok.NonNull;
/**
* @author ww
*/
@Data
public class CzgBaseReq {
//必填范围
/**
* 订单标题
*/
private String subject;
/**
* 订单描述 String(256)
*/
private String body;
/**
* 交易金额
*/
private Long amount;
/**
* 货币类型 cny
*/
private String currency = "cny";
/**
* 商户订单号 String(30)
* 操作方式+雪花算法
* 收银机客户端 PC+雪花ID
* 微信小程序 WX+雪花ID
* 支付宝小程序 ALI+雪花ID
* PC管理端 WEB+雪花ID
* APP管理端 APP+雪花ID
* <p>
* 退款 re+雪花ID
*/
private String mchOrderNo;
/**
* 门店编号 tb_shop_merchant 的 store_id
*/
private String storeId;
//非必填项
/**
* 订单备注 String(50)
*/
private String buyerRemark;
/**
* 异步通知地址 String(128)
* 支付结果异步回调URL,只有传了该值才会发起回调
*/
private String notifyUrl;
/**
* 失效时间 int 15
* 订单失效时间,单位分钟,默认15小时.
* 取值范围 5-1440 分钟
* 订单在(创建时间+失效时间)后失效
*/
private Integer expiredTime;
/**
* 分账模式:
* 0-该笔订单不允许分账[默认],
* 1-实时分账
* 2-延时分账
*/
private Integer divisionMode;
/**
* 分账详情
*/
private String divisionDetail;
/**
* 扩展参数 String(512)
* 商户扩展参数,回调时会原样返回
* * 扩展参数
* * {
* * "pay_type": "order/vip"
* * }
*/
private String extParam;
/**
* 花呗分期数
* 支付宝交易时可传 而且金额需要大于或等于 100.00元时生效
* 3/6/12
*/
private Integer hbFqNum;
/**
* 卖家是否承担手续费
* 100卖家承担手续费
* 0买家承担手续费
*/
private Integer hbFqPercent;
/**
* 是否禁用信用卡
* -1不禁用 1禁用
* 不传默认为不限制
*/
private Integer limitPay;
public CzgBaseReq() {
}
public CzgBaseReq(String mchOrderNo, Long amount, String body,
String buyerRemark, String extParam) {
this.mchOrderNo = mchOrderNo;
this.body = body;
this.amount = amount;
this.buyerRemark = buyerRemark;
this.extParam = extParam;
}
public void assignMerchant(@NonNull String storeId, @NonNull String subject, @NonNull String notifyUrl) {
this.storeId = storeId;
this.subject = subject;
this.notifyUrl = notifyUrl;
}
}

View File

@@ -1,39 +0,0 @@
package com.czg.entity.req;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
/**
* h5支付请求参数
*
* @author ww
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class CzgH5PayReq extends CzgBaseReq {
//必填范围
/**
* 用户IP 支付的用户IP
*/
private String clientIp;
private String payType;
//?
private String openId;
//非必填范围
/**
* 跳转通知地址
* 支付结果同步跳转通知URL
*/
private String returnUrl;
public CzgH5PayReq(@NonNull String mchOrderNo, @NonNull Long amount, String body, @NonNull String clientIp,
String returnUrl, String buyerRemark, @NonNull String extParam) {
super(mchOrderNo, amount, body, buyerRemark, extParam);
this.clientIp = clientIp;
this.returnUrl = returnUrl;
}
}

View File

@@ -1,71 +0,0 @@
package com.czg.entity.req;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
/**
* 公众号/生活号/银联js支付
*
* @author ww
* <p>
* ● 码牌、台卡、立牌等
* 用户通过扫描微信/支付宝/云闪付APP静态二维码输入订单金额进行付款动作。
* ● 公众号 / 生活号商城
* 用户通过公众号下单,输入密码完成付款动作。适用于自有公众号主体交易
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class CzgJsPayReq extends CzgBaseReq {
//必填范围
/**
* 用户唯一标识 String(30)
* 微信支付时传入用户的openId
* 支付宝支付和银联支付时传入用户的userId
*/
private String userId;
/**
* 用户IP
* 需要传付款用户客户端IP地址
*/
private String clientIp;
/**
* 微信 WECHAT
* 支付宝 ALIPAY
* 银联云闪付 UNIONPAY
*/
private String payType;
//非必填范围
/**
* 子商户appid ,微信付款支付的时候 需要上送
*/
private String subAppid;
/**
* 跳转通知地址
* 支付结果同步跳转通知URL
*/
private String returnUrl;
/**
* 银联js支付成功前端跳转
*/
private String frontUrl;
/**
* 银联js支付失败前端跳转地址
*/
private String frontFailUrl;
public CzgJsPayReq(@NonNull String mchOrderNo,
@NonNull Long amount, String body,
@NonNull String openId, @NonNull String clientIp,
String returnUrl, String buyerRemark,@NonNull String extParam) {
super(mchOrderNo, amount, body, buyerRemark, extParam);
this.userId = openId;
this.clientIp = clientIp;
this.returnUrl = returnUrl;
}
}

View File

@@ -1,63 +0,0 @@
package com.czg.entity.req;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
/**
* 小程序支付
*
* @author ww
* 自有小程序拉起支付
* 自有小程序拉起服务商小程序,(微信)半屏小程序支付
* 半屏小程序需要在商户自己的小程序中的半屏小程序配置里面申请 否则会拉起全屏小程序支付
* <p>
* 半屏小程序支付适用场景是商户自己的小程序被纳入微信实物电商类型小程序导致间联商户无法绑定这类的小程序APPID
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class CzgLtPayReq extends CzgBaseReq {
//必填范围
/**
* 用户唯一标识 String(30)
* 微信支付时,传入用户的 openId
* 支付宝支付和银联支付时,传入用户的 userId
*/
private String userId;
private String payType;
/**
* 用户 IP 支付的用户 IP
*/
private String clientIp;
//非必填范围
/**
* 跳转通知地址
* 支付结果同步跳转通知 URL
*/
private String returnUrl;
/**
* 子商户 appid ,微信付款支付的时候 需要上送
* isScreen 为 false 的情况下需要传入
*/
private String subAppid;
/**
* 是否半屏
* 是否使用半屏小程序,默认为 false
* 前提小程序被纳入了实物电商类型的小程序,间联商户无法绑定这类的小程序的 appid
*/
private boolean isScreen;
public CzgLtPayReq(@NonNull String mchOrderNo, @NonNull Long amount, @NonNull String payType,
String body, @NonNull String openId, @NonNull String clientIp,
String returnUrl, String buyerRemark, @NonNull String extParam) {
super(mchOrderNo, amount, body, buyerRemark, extParam);
this.userId = openId;
this.payType = "aliPay".equals(payType) ? "ALIPAY" : "WECHAT";
this.clientIp = clientIp;
this.returnUrl = returnUrl;
}
}

View File

@@ -1,37 +0,0 @@
package com.czg.entity.req;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
/**
* 反扫请求参数
*
* @author ww
* <p>
* 被扫免密同步返回支付结果,不推送异步通知。
* 被扫输密,推送异步通知。
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class CzgMicroPayReq extends CzgBaseReq {
//必填范围
/**
* 付款码信息 String(30)
* 扫码设备获取微信或支付宝上付款的信息
*/
private String authCode;
//非必填范围
/**
* 子商户appid ,微信付款支付的时候 需要上送
*/
private String subAppid;
public CzgMicroPayReq(@NonNull String mchOrderNo, @NonNull Long amount, String body,
@NonNull String authCode, String buyerRemark, @NonNull String extParam) {
super(mchOrderNo, amount, body, buyerRemark, extParam);
this.authCode = authCode;
}
}

View File

@@ -1,35 +0,0 @@
package com.czg.entity.req;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
/**
* 正扫支付请求参数
*
* @author ww
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class CzgScanPayReq extends CzgBaseReq {
// 必填项
/**
* 用户IP 支付的用户IP
*/
private String clientIp;
//非必填项
/**
* 跳转通知地址
* String(128)
*/
private String returnUrl;
public CzgScanPayReq(@NonNull String mchOrderNo, @NonNull Long amount, String body,
@NonNull String clientIp, String returnUrl, String buyerRemark, @NonNull String extParam) {
super(mchOrderNo, amount, body, buyerRemark, extParam);
this.clientIp = clientIp;
this.returnUrl = returnUrl;
}
}

View File

@@ -9,7 +9,7 @@
<version>1.0.0</version>
</parent>
<artifactId>czg-pay</artifactId>
<artifactId>poly-pay</artifactId>
<properties>
<maven.compiler.source>21</maven.compiler.source>

View File

@@ -8,11 +8,12 @@ import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import com.czg.entity.CzgBaseReqParams;
import com.czg.entity.CzgBaseRespParams;
import com.czg.entity.req.*;
import com.czg.entity.PolyBaseReq;
import com.czg.entity.PolyBaseResp;
import com.czg.entity.resp.*;
import com.czg.enums.CzgPayEnum;
import com.czg.pay.CzgPayBaseReq;
import com.czg.pay.CzgRefundReq;
import com.czg.resp.CzgRespCode;
import com.czg.resp.CzgResult;
import com.czg.utils.AssertUtil;
@@ -26,10 +27,10 @@ import java.util.stream.Collectors;
/**
* @author ww
* @description 超掌柜支付类
* @description 聚合支付类
*/
@Slf4j
public class CzgPayUtils {
public class PolyPayUtils {
/**
* h5支付
@@ -39,8 +40,8 @@ public class CzgPayUtils {
* @param appSecret 应用密钥 tb_shop_merchant 表中的 app_secret
* CzgResult<CzgH5PayResp>
*/
public static CzgResult<Map<String, Object>> h5Pay(@NonNull String domain, @NonNull String appId, @NonNull String appSecret, CzgH5PayReq bizData) {
return execPayResult(sendCzg(domain.concat(CzgPayEnum.H5PAY.getUri()), CzgBaseReqParams.getInstance(appId, appSecret, bizData), CzgH5PayResp.class));
public static CzgResult<Map<String, Object>> h5Pay(@NonNull String domain, @NonNull String appId, @NonNull String appSecret, CzgPayBaseReq<?> bizData) {
return execPayResult(sendPolyPay(domain.concat(CzgPayEnum.H5_PAY.getUri()), PolyBaseReq.getInstance(appId, appSecret, bizData), CzgH5PayResp.class));
}
/**
@@ -51,8 +52,8 @@ public class CzgPayUtils {
* @param appSecret 应用密钥 tb_shop_merchant 表中的 app_secret
* CzgResult<CzgJsPayResp>
*/
public static CzgResult<Map<String, Object>> jsPay(@NonNull String domain, @NonNull String appId, @NonNull String appSecret, CzgJsPayReq bizData) {
return execPayResult(sendCzg(domain.concat(CzgPayEnum.JSPAY.getUri()), CzgBaseReqParams.getInstance(appId, appSecret, bizData), CzgJsPayResp.class));
public static CzgResult<Map<String, Object>> jsPay(@NonNull String domain, @NonNull String appId, @NonNull String appSecret, CzgPayBaseReq<?> bizData) {
return execPayResult(sendPolyPay(domain.concat(CzgPayEnum.JS_PAY.getUri()), PolyBaseReq.getInstance(appId, appSecret, bizData), CzgJsPayResp.class));
}
/**
@@ -63,8 +64,8 @@ public class CzgPayUtils {
* @param appSecret 应用密钥 tb_shop_merchant 表中的 app_secret
* CzgResult<CzgLtPayResp>
*/
public static CzgResult<Map<String, Object>> ltPay(@NonNull String domain, @NonNull String appId, @NonNull String appSecret, CzgLtPayReq bizData) {
return execPayResult(sendCzg(domain.concat(CzgPayEnum.LTPAY.getUri()), CzgBaseReqParams.getInstance(appId, appSecret, bizData), CzgLtPayResp.class));
public static CzgResult<Map<String, Object>> ltPay(@NonNull String domain, @NonNull String appId, @NonNull String appSecret, CzgPayBaseReq<?> bizData) {
return execPayResult(sendPolyPay(domain.concat(CzgPayEnum.LT_PAY.getUri()), PolyBaseReq.getInstance(appId, appSecret, bizData), CzgLtPayResp.class));
}
/**
@@ -75,8 +76,8 @@ public class CzgPayUtils {
* @param appSecret 应用密钥 tb_shop_merchant 表中的 app_secret
* CzgResult<CzgScanPayResp>
*/
public static CzgResult<Map<String, Object>> scanPay(@NonNull String domain, @NonNull String appId, @NonNull String appSecret, CzgScanPayReq bizData) {
return execPayResult(sendCzg(domain.concat(CzgPayEnum.SCANPAY.getUri()), CzgBaseReqParams.getInstance(appId, appSecret, bizData), CzgScanPayResp.class));
public static CzgResult<Map<String, Object>> scanPay(@NonNull String domain, @NonNull String appId, @NonNull String appSecret, CzgPayBaseReq<?> bizData) {
return execPayResult(sendPolyPay(domain.concat(CzgPayEnum.SCAN_PAY.getUri()), PolyBaseReq.getInstance(appId, appSecret, bizData), CzgScanPayResp.class));
}
/**
@@ -87,8 +88,8 @@ public class CzgPayUtils {
* @param appSecret 应用密钥 tb_shop_merchant 表中的 app_secret
* CzgResult<CzgMicroPayResp>
*/
public static CzgResult<Map<String, Object>> microPay(@NonNull String domain, @NonNull String appId, @NonNull String appSecret, CzgMicroPayReq bizData) {
return execPayResult(sendCzg(domain.concat(CzgPayEnum.MICROPAY.getUri()), CzgBaseReqParams.getInstance(appId, appSecret, bizData), CzgMicroPayResp.class));
public static CzgResult<Map<String, Object>> microPay(@NonNull String domain, @NonNull String appId, @NonNull String appSecret, CzgPayBaseReq<?> bizData) {
return execPayResult(sendPolyPay(domain.concat(CzgPayEnum.MICRO_PAY.getUri()), PolyBaseReq.getInstance(appId, appSecret, bizData), CzgMicroPayResp.class));
}
/**
@@ -105,7 +106,7 @@ public class CzgPayUtils {
JSONObject queryPayOrder = new JSONObject();
queryPayOrder.put("payOrderId", payOrderId);
queryPayOrder.put("mchOrderNo", mchOrderNo);
return sendCzg(domain.concat(CzgPayEnum.TRADE.getUri()), CzgBaseReqParams.getInstance(appId, appSecret, queryPayOrder), CzgBaseResp.class);
return sendPolyPay(domain.concat(CzgPayEnum.TRADE.getUri()), PolyBaseReq.getInstance(appId, appSecret, queryPayOrder), CzgBaseResp.class);
}
@@ -117,7 +118,7 @@ public class CzgPayUtils {
* @param appSecret 应用密钥 tb_shop_merchant 表中的 app_secret
*/
public static CzgResult<CzgRefundResp> refundOrder(@NonNull String domain, @NonNull String appId, @NonNull String appSecret, CzgRefundReq bizData) {
return sendCzg(domain.concat(CzgPayEnum.REFUND.getUri()), CzgBaseReqParams.getInstance(appId, appSecret, bizData), CzgRefundResp.class);
return sendPolyPay(domain.concat(CzgPayEnum.REFUND.getUri()), PolyBaseReq.getInstance(appId, appSecret, bizData), CzgRefundResp.class);
}
/**
@@ -134,23 +135,23 @@ public class CzgPayUtils {
JSONObject queryPayOrder = new JSONObject();
queryPayOrder.put("mchRefundNo", mchRefundNo);
queryPayOrder.put("refundOrderId", refundOrderId);
return sendCzg(domain.concat(CzgPayEnum.QUERY_REFUND.getUri()), CzgBaseReqParams.getInstance(appId, appSecret, queryPayOrder), CzgRefundResp.class);
return sendPolyPay(domain.concat(CzgPayEnum.QUERY_REFUND.getUri()), PolyBaseReq.getInstance(appId, appSecret, queryPayOrder), CzgRefundResp.class);
}
/**
* 回调数据处理
*/
public static JSONObject getCzg(CzgBaseRespParams respParams) {
AssertUtil.isNull(respParams, "超掌柜交易 回调数据为空");
log.info("超掌柜交易请求响应,{}", respParams);
public static JSONObject getCzg(PolyBaseResp respParams) {
AssertUtil.isNull(respParams, "聚合交易 回调数据为空");
log.info("聚合交易请求响应,{}", respParams);
if (!"000000".equals(respParams.getCode())) {
log.error("超掌柜回调响应失败,{}", respParams);
log.error("聚合回调响应失败,{}", respParams);
return null;
}
// if (StrUtil.isNotBlank(respParams.getSign())) {
// if (validateSign(respParams.getSign(), respParams.getBizData())) {
// log.error("超掌柜回调 验签失败");
// log.error("聚合回调 验签失败");
// }
// }
return JSONObject.parse(respParams.getBizData());
@@ -168,19 +169,19 @@ public class CzgPayUtils {
* "data": "返回Json数据",
* }
*/
private static <T> CzgResult<T> sendCzg(String url, CzgBaseReqParams params, Class<T> clazz) {
private static <T> CzgResult<T> sendPolyPay(String url, PolyBaseReq params, Class<T> clazz) {
CzgResult<T> result = CzgResult.success();
Map<String, Object> reqMap = BeanUtil.beanToMap(params, false, false);
params.setSign(MD5.create().digestHex(sortFields(new TreeMap<>(reqMap))));
log.info("超掌柜交易请求参数,{}", JSONObject.toJSONString(params));
log.info("聚合交易请求参数,{}", JSONObject.toJSONString(params));
try (HttpResponse resp = HttpRequest.post(url).body(JSONObject.toJSONString(params)).execute()) {
if (resp.isOk()) {
// 获取响应体
String respStr = resp.body();
if (StrUtil.isNotEmpty(respStr)) {
log.info("超掌柜交易请求响应元数据,{}", respStr);
CzgBaseRespParams respParams = JSONObject.parseObject(respStr, CzgBaseRespParams.class);
log.info("超掌柜交易请求响应,{}", respParams);
log.info("聚合交易请求响应元数据,{}", respStr);
PolyBaseResp respParams = JSONObject.parseObject(respStr, PolyBaseResp.class);
log.info("聚合交易请求响应,{}", respParams);
result.setCode("000000".equals(respParams.getCode()) ? 200 : Integer.parseInt(respParams.getCode()));
result.setMsg(respParams.getMsg());
@@ -194,15 +195,15 @@ public class CzgPayUtils {
}
} else {
result.setCode(resp.getStatus());
result.setMsg("超掌柜交易请求失败");
log.error("超掌柜交易请求失败,状态码: {}", resp.getStatus());
result.setMsg("聚合交易请求失败");
log.error("聚合交易请求失败,状态码: {}", resp.getStatus());
}
} else {
result.setCode(resp.getStatus());
result.setMsg("超掌柜交易请求失败");
result.setMsg("聚合交易请求失败");
}
} catch (Exception e) {
log.error("超掌柜交易请求异常", e);
log.error("聚合交易请求异常", e);
}
return result;
}
@@ -221,7 +222,7 @@ public class CzgPayUtils {
private static String sortFields(TreeMap<String, Object> map) {
if (CollectionUtil.isEmpty(map)) {
log.error("超掌柜支付参数为空!!!");
log.error("聚合支付参数为空!!!");
throw new RuntimeException("参数为空");
}
String sortParam = map.entrySet().stream()

View File

@@ -12,7 +12,7 @@ import lombok.Data;
* @author ww
*/
@Data
public class CzgBaseReqParams {
public class PolyBaseReq {
/**
* 应用ID tb_shop_merchant 表中的 app_id
@@ -69,7 +69,7 @@ public class CzgBaseReqParams {
* @param appSecret 应用密钥 tb_shop_merchant 表中的 app_secret
* @param bizData JSON 形式的字符串
*/
public CzgBaseReqParams(String appId, String bizData, String appSecret) {
public PolyBaseReq(String appId, String bizData, String appSecret) {
this.appId = appId;
this.bizData = bizData;
this.appSecret = appSecret;
@@ -82,8 +82,8 @@ public class CzgBaseReqParams {
* @param appSecret 应用密钥 tb_shop_merchant 表中的 app_secret
* @param bizData JSON 形式的字符串
*/
public static CzgBaseReqParams getInstance(String appId, String appSecret, Object bizData) {
return new CzgBaseReqParams(appId, ObjectUtil.isNotEmpty(bizData) ? JSONObject.toJSONString(bizData) : "", appSecret);
public static PolyBaseReq getInstance(String appId, String appSecret, Object bizData) {
return new PolyBaseReq(appId, ObjectUtil.isNotEmpty(bizData) ? JSONObject.toJSONString(bizData) : "", appSecret);
}
}

View File

@@ -6,7 +6,7 @@ import lombok.Data;
* @author ww
*/
@Data
public class CzgBaseRespParams {
public class PolyBaseResp {
/**

View File

@@ -8,11 +8,11 @@ import lombok.Getter;
@Getter
public enum CzgPayEnum {
SCANPAY("/api/open/payment/scanpay", "PC扫码支付"),
MICROPAY("/api/open/payment/micropay", "聚合反扫B扫C/ 快捷收款"),
JSPAY("/api/open/payment/jspay", "公众号/生活号/银联js支付"),
LTPAY("/api/open/payment/ltpay", "小程序支付"),
H5PAY("/api/open/payment/h5pay", "手机网页支付"),
SCAN_PAY("/api/open/payment/scanpay", "PC扫码支付"),
MICRO_PAY("/api/open/payment/micropay", "聚合反扫B扫C/ 快捷收款"),
JS_PAY("/api/open/payment/jspay", "公众号/生活号/银联js支付"),
LT_PAY("/api/open/payment/ltpay", "小程序支付"),
H5_PAY("/api/open/payment/h5pay", "手机网页支付"),
TRADE("/api/open/query/trade", "订单状态查询"),
REFUND("/api/open/order/refund", "统一退款 D0退款需要使用平台户退款"),

View File

@@ -12,7 +12,7 @@
<name>third sdk</name>
<description>第三方内容</description>
<modules>
<module>czg-pay</module>
<module>poly-pay</module>
<module>aggregation-pay</module>
</modules>
<artifactId>cash-sdk</artifactId>
@@ -29,5 +29,10 @@
<artifactId>cash-common-tools</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.czg</groupId>
<artifactId>cash-common-service</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@@ -17,6 +17,7 @@ import com.czg.constants.ParamCodeCst;
import com.czg.constants.ShopSwitchTypeEnum;
import com.czg.constants.SystemConstants;
import com.czg.exception.CzgException;
import com.czg.order.service.ShopMerchantService;
import com.czg.resp.CzgResult;
import com.czg.sa.MyStpLogic;
import com.czg.sa.StpKit;
@@ -77,6 +78,8 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
private FreeDineConfigService freeDineConfigService;
@Resource
private ShopConfigService shopConfigService;
@Resource
private ShopMerchantService shopMerchantService;
@DubboReference
private SysParamsService sysParamsService;
@@ -324,16 +327,6 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
return false;
}
@Override
@CacheEvict(key = "#shopId")
public Boolean editEntry(Long shopId, String wechatMerchantId, String alipayMerchantId, String alipayAuthInfo) {
ShopInfo shopInfo = new ShopInfo();
shopInfo.setWechatMerchantId(wechatMerchantId);
shopInfo.setAlipayMerchantId(alipayMerchantId);
shopInfo.setAlipayAuthInfo(alipayAuthInfo);
return update(shopInfo, new QueryWrapper().eq(ShopInfo::getId, shopId));
}
@Override
public ShopDetailDTO detail(Long id) throws CzgException {
ShopInfo shopInfo = queryChain().eq(ShopInfo::getId, id == null ? StpKit.USER.getShopId() : id).one();

View File

@@ -1,55 +0,0 @@
package com.czg.service.account.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.czg.account.dto.merchant.ShopMerchantEditDTO;
import com.czg.account.entity.ShopMerchant;
import com.czg.account.service.ShopMerchantService;
import com.czg.sa.StpKit;
import com.czg.service.account.mapper.ShopMerchantMapper;
import com.czg.utils.AssertUtil;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import java.io.Serializable;
/**
* 第三方商户进件 服务层实现。
*
* @author Administrator
* @since 2025-02-11
*/
@CacheConfig(cacheNames = "shop:merchant")
@DubboService
public class ShopMerchantServiceImpl extends ServiceImpl<ShopMerchantMapper, ShopMerchant> implements ShopMerchantService {
@Override
public ShopMerchant detail(Integer shopId) {
ShopMerchant one = queryChain().eq(ShopMerchant::getShopId, shopId).one();
return one == null ? new ShopMerchant() : one;
}
@CacheEvict(key = "#shopMerchantEditDTO.shopId")
@Override
public Boolean edit(ShopMerchantEditDTO shopMerchantEditDTO) {
ShopMerchant shopMerchant = queryChain().eq(ShopMerchant::getShopId, shopMerchantEditDTO.getShopId()).one();
if (shopMerchant == null) {
shopMerchant = new ShopMerchant();
shopMerchant.setShopId(shopMerchantEditDTO.getShopId());
BeanUtil.copyProperties(shopMerchantEditDTO, shopMerchant);
return save(shopMerchant);
}
BeanUtil.copyProperties(shopMerchantEditDTO, shopMerchant);
return updateById(shopMerchant);
}
@Cacheable(key = "#id")
@Override
public ShopMerchant getById(Serializable id) {
ShopMerchant shopMerchant = getMapper().selectOneById(id);
AssertUtil.isNull(shopMerchant, "暂未开通支付");
return shopMerchant;
}
}

View File

@@ -18,9 +18,8 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.czg</groupId>
<artifactId>pay-service</artifactId>
<version>1.0.0</version>
<groupId>com.github.javen205</groupId>
<artifactId>IJPay-All</artifactId>
</dependency>
<dependency>

View File

@@ -1,12 +1,12 @@
package com.czg.service.market.service.impl;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.constants.ParamCodeCst;
import com.czg.exception.CzgException;
import com.czg.service.RedisService;
import com.czg.system.service.SysParamsService;
import com.ijpay.core.kit.RsaKit;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
@@ -14,7 +14,6 @@ import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.Set;
/**
* 微信支付service
@@ -80,7 +79,7 @@ public class AppWxServiceImpl extends BaseWx {
// api支付证书公钥
config.apiCert = payKeyMap.get(ParamCodeCst.Wechat.Pay.WX_API_CLIENT_CERT);
try {
config.privateKey = RsaKit.loadPrivateKey(config.apiCertKey);
config.privateKey = SecureUtil.rsa(config.apiCertKey, null).getPrivateKey();
} catch (Exception e) {
log.warn("微信加载api证书失败");
}
@@ -98,10 +97,6 @@ public class AppWxServiceImpl extends BaseWx {
config.refundNotifyUrl = "";
config.transferNotifyUrl = payKeyMap.get(ParamCodeCst.System.NATIVE_NOTIFY_URL) + "/wx/transfer";
}
public BaseWx getAppService() {
return this;
}
}

View File

@@ -18,21 +18,16 @@
</properties>
<dependencies>
<dependency>
<groupId>com.czg</groupId>
<artifactId>czg-pay</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.czg</groupId>
<artifactId>aggregation-pay</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.czg</groupId>
<artifactId>market-service</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.czg</groupId>
<artifactId>pay-service</artifactId>
<version>${project.version}</version>
</dependency>
<!-- 订单服务依赖消息队列 从 market 拿 -->
<!-- <dependency>-->
<!-- <groupId>com.czg</groupId>-->

View File

@@ -1,6 +1,6 @@
package com.czg.service.account.mapper;
package com.czg.service.order.mapper;
import com.czg.account.entity.ShopMerchant;
import com.czg.order.entity.ShopMerchant;
import com.mybatisflex.core.BaseMapper;
/**

View File

@@ -1,10 +1,12 @@
package com.czg.service.order.service;
import com.czg.entity.req.*;
import com.czg.entity.resp.CzgBaseResp;
import com.czg.entity.resp.CzgRefundResp;
import com.czg.enums.CzgPayEnum;
import com.czg.order.dto.LtPayOtherDTO;
import com.czg.order.entity.OrderPayment;
import com.czg.pay.CzgPayBaseReq;
import com.czg.pay.CzgRefundReq;
import com.czg.resp.CzgResult;
import lombok.NonNull;
@@ -21,14 +23,10 @@ public interface PayService {
BigDecimal MONEY_RATE = new BigDecimal("100");
Long initOrderPayment(OrderPayment payment);
Long initPayment(OrderPayment payment);
//-----------------------------------------------------------------付款 ----------------------------------------------------------
CzgResult<Map<String, Object>> h5Pay(@NonNull Long shopId, CzgH5PayReq bizData);
CzgResult<Map<String, Object>> jsPay(@NonNull Long shopId, @NonNull String payType, CzgJsPayReq bizData);
CzgResult<Map<String, Object>> ltPay(@NonNull Long shopId, String payType, CzgLtPayReq bizData);
CzgResult<Map<String, Object>> scanPay(@NonNull Long shopId, CzgScanPayReq bizData);
CzgResult<Map<String, Object>> microPay(@NonNull Long shopId, CzgMicroPayReq bizData);
CzgResult<Map<String, Object>> pay(@NonNull Long shopId, CzgPayEnum payType, CzgPayBaseReq<?> bizData);
//-----------------------------------------------------------------积分商品/拼团 付款 ----------------------------------------------------------
/**

View File

@@ -7,13 +7,14 @@ import com.czg.account.service.ShopUserService;
import com.czg.account.service.UserInfoService;
import com.czg.constant.TableValueConstant;
import com.czg.constants.PayTypeConstants;
import com.czg.entity.req.CzgLtPayReq;
import com.czg.enums.CzgPayEnum;
import com.czg.exception.CzgException;
import com.czg.market.service.MkDistributionConfigService;
import com.czg.market.vo.MkDistributionConfigVO;
import com.czg.order.dto.MkDistributionPayDTO;
import com.czg.order.entity.OrderPayment;
import com.czg.order.service.OrderPaymentService;
import com.czg.pay.CzgPayBaseReq;
import com.czg.resp.CzgResult;
import com.czg.service.market.service.impl.WxServiceImpl;
import com.czg.service.order.service.DistributionPayService;
@@ -67,7 +68,7 @@ public class DistributionPayServiceImpl implements DistributionPayService {
ShopUser shopUserInfo = shopUserService.getShopUserInfo(payParam.getShopId(), userId);
OrderPayment orderPayment = new OrderPayment().setShopId(payParam.getShopId()).setSourceId(isRecharge ? payParam.getShopId() : shopUserInfo.getId())
.setSourceType(isRecharge ? PayTypeConstants.SourceType.DISTRIBUTION_RECHARGE : PayTypeConstants.SourceType.DISTRIBUTION )
.setSourceType(isRecharge ? PayTypeConstants.SourceType.DISTRIBUTION_RECHARGE : PayTypeConstants.SourceType.DISTRIBUTION)
.setPayType(PayTypeConstants.PayType.PAY)
.setOrderNo(payParam.getPlatformType() + IdUtil.getSnowflakeNextId())
.setAmount(isRecharge ? payParam.getAmount() : detail.getPayAmount());
@@ -89,12 +90,13 @@ public class DistributionPayServiceImpl implements DistributionPayService {
@Override
public CzgResult<Map<String, Object>> ltPayOrder(String clintIp, MkDistributionPayDTO payParam) {
InitInfo initInfo = initPayment(payParam.getUserId(), payParam, false);
return payService.ltPay(payParam.getShopId(), payParam.getPayType(), new CzgLtPayReq(initInfo.payment.getOrderNo(), initInfo.payment.getAmount().multiply(MONEY_RATE).longValue(),
payParam.getPayType(), "分销员开通", initInfo.getOpenId(), clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
return payService.pay(payParam.getShopId(), CzgPayEnum.LT_PAY,
CzgPayBaseReq.ltPayReq(initInfo.payment.getOrderNo(), "分销员开通", initInfo.payment.getAmount().multiply(MONEY_RATE).longValue(),
payParam.getPayType(), initInfo.getOpenId(), clintIp));
}
@Override
public Map<String, String> mchRecharge(String clientIP, MkDistributionPayDTO payParam) {
public Map<String, String> mchRecharge(MkDistributionPayDTO payParam) {
InitInfo initInfo = initPayment(payParam.getUserId() == null ? payParam.getShopId() : payParam.getUserId(), payParam, true);
return wxService.v3Pay(initInfo.openId, payParam.getAmount(), "商户运营余额充值", initInfo.payment.getOrderNo(), initInfo.payment.getSourceType());
}

View File

@@ -17,8 +17,8 @@ import com.czg.account.service.UserInfoService;
import com.czg.config.RabbitPublisher;
import com.czg.config.RedisCst;
import com.czg.constants.PayTypeConstants;
import com.czg.entity.req.*;
import com.czg.entity.resp.CzgRefundResp;
import com.czg.enums.CzgPayEnum;
import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.exception.CzgException;
import com.czg.exception.PaySuccessException;
@@ -36,6 +36,8 @@ import com.czg.order.service.CreditBuyerOrderService;
import com.czg.order.service.OrderDetailService;
import com.czg.order.service.OrderInfoCustomService;
import com.czg.order.service.OrderPaymentService;
import com.czg.pay.CzgPayBaseReq;
import com.czg.pay.CzgRefundReq;
import com.czg.resp.CzgResult;
import com.czg.service.RedisService;
import com.czg.service.order.dto.OrderPayParamDTO;
@@ -62,6 +64,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author ww
*/
@Slf4j
@Service
public class OrderPayServiceImpl implements OrderPayService {
@@ -227,13 +232,15 @@ public class OrderPayServiceImpl implements OrderPayService {
return CzgResult.failure("支付失败 充值金额必须大雨订单金额");
}
String payOrderNo = orderInfo.getPlatformType() + CzgRandomUtils.snowflake();
Long paymentId = payService.initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), PayTypeConstants.SourceType.MEMBER_IN, PayTypeConstants.PayType.PAY, payOrderNo,
"", rechargeDetail.getAmount(), rechargeDetail.getId()));
Long paymentId = payService.initPayment(OrderPayment.pay(payParam.getShopId(), shopUser.getId(), PayTypeConstants.SourceType.MEMBER_IN,
payOrderNo, rechargeDetail.getAmount(), "", rechargeDetail.getId()));
upOrderPayInfo(orderInfo.getId(), PayEnums.VIP_PAY, paymentId,
payParam.getCheckOrderPay() == null ? null : payParam.getCheckOrderPay().getRemark());
return payService.ltPay(payParam.getShopId(), payParam.getPayType(), new CzgLtPayReq(payOrderNo, rechargeDetail.getAmount().multiply(PayService.MONEY_RATE).longValue(),
payParam.getPayType(), "充值并支付", "wechatPay".equals(payParam.getPayType()) ? userInfo.getWechatOpenId() : userInfo.getAlipayOpenId(),
clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
return payService.pay(payParam.getShopId(), CzgPayEnum.LT_PAY,
CzgPayBaseReq.ltPayReq(
payOrderNo, "充值并支付",
rechargeDetail.getAmount().multiply(PayService.MONEY_RATE).longValue(), payParam.getPayType(),
"wechatPay".equals(payParam.getPayType()) ? userInfo.getWechatOpenId() : userInfo.getAlipayOpenId(), clintIp));
}
@Override
@@ -241,12 +248,10 @@ public class OrderPayServiceImpl implements OrderPayService {
public CzgResult<Map<String, Object>> h5PayOrder(@NonNull String clintIp, OrderPayParamDTO payParam) {
OrderInfo orderInfo = checkPay(payParam.getCheckOrderPay());
String payOrderNo = orderInfo.getPlatformType() + CzgRandomUtils.snowflake();
Long paymentId = payService.initOrderPayment(new OrderPayment(payParam.getShopId(), orderInfo.getId(),
PayTypeConstants.SourceType.ORDER, PayTypeConstants.PayType.PAY, payOrderNo, "", orderInfo.getOrderAmount()));
upOrderPayInfo(orderInfo.getId(), PayEnums.H5_PAY, paymentId,
payParam.getCheckOrderPay() == null ? null : payParam.getCheckOrderPay().getRemark());
return payService.h5Pay(payParam.getShopId(), new CzgH5PayReq(payOrderNo, orderInfo.getOrderAmount().multiply(PayService.MONEY_RATE).longValue(),
"点餐支付", clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
Long paymentId = payService.initPayment(OrderPayment.orderPay(payParam.getShopId(), orderInfo.getId(), payOrderNo, orderInfo.getOrderAmount(), ""));
upOrderPayInfo(orderInfo.getId(), PayEnums.H5_PAY, paymentId, payParam.getCheckOrderPay() == null ? null : payParam.getCheckOrderPay().getRemark());
return payService.pay(payParam.getShopId(), CzgPayEnum.H5_PAY,
CzgPayBaseReq.h5PayReq(payOrderNo, "点餐支付", orderInfo.getOrderAmount().multiply(PayService.MONEY_RATE).longValue(), clintIp));
}
@@ -257,12 +262,12 @@ public class OrderPayServiceImpl implements OrderPayService {
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
String payOrderNo = orderInfo.getPlatformType() + CzgRandomUtils.snowflake();
Long paymentId = payService.initOrderPayment(new OrderPayment(payParam.getShopId(), orderInfo.getId(),
PayTypeConstants.SourceType.ORDER, PayTypeConstants.PayType.PAY, payOrderNo, "", orderInfo.getOrderAmount()));
Long paymentId = payService.initPayment(OrderPayment.orderPay(payParam.getShopId(), orderInfo.getId(), payOrderNo, orderInfo.getOrderAmount(), ""));
upOrderPayInfo(orderInfo.getId(), "aliPay".equals(payParam.getPayType()) ? PayEnums.ALIPAY_MINI : PayEnums.WECHAT_MINI, paymentId,
payParam.getCheckOrderPay() == null ? null : payParam.getCheckOrderPay().getRemark());
return payService.jsPay(payParam.getShopId(), payParam.getPayType(), new CzgJsPayReq(payOrderNo, orderInfo.getOrderAmount().multiply(PayService.MONEY_RATE).longValue(),
"点餐支付", payParam.getOpenId(), clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
return payService.pay(payParam.getShopId(), CzgPayEnum.JS_PAY,
CzgPayBaseReq.jsPayReq(payOrderNo, "点餐支付", orderInfo.getOrderAmount().multiply(PayService.MONEY_RATE).longValue(),
payParam.getPayType(), payParam.getOpenId(), clintIp));
}
@Override
@@ -281,12 +286,12 @@ public class OrderPayServiceImpl implements OrderPayService {
orderInfo = orderInfoService.getById(payParam.getCheckOrderPay().getOrderId());
}
String payOrderNo = orderInfo.getPlatformType() + CzgRandomUtils.snowflake();
Long paymentId = payService.initOrderPayment(new OrderPayment(payParam.getShopId(), orderInfo.getId(),
PayTypeConstants.SourceType.ORDER, PayTypeConstants.PayType.PAY, payOrderNo, "", orderInfo.getOrderAmount()));
Long paymentId = payService.initPayment(OrderPayment.orderPay(payParam.getShopId(), orderInfo.getId(), payOrderNo, orderInfo.getOrderAmount(), ""));
upOrderPayInfo(orderInfo.getId(), "aliPay".equals(payParam.getPayType()) ? PayEnums.ALIPAY_MINI : PayEnums.WECHAT_MINI, paymentId,
payParam.getCheckOrderPay() == null ? null : payParam.getCheckOrderPay().getRemark());
return payService.jsPay(payParam.getShopId(), payParam.getPayType(), new CzgJsPayReq(payOrderNo, orderInfo.getOrderAmount().multiply(PayService.MONEY_RATE).longValue(),
"点餐支付", payParam.getOpenId(), clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
return payService.pay(payParam.getShopId(), CzgPayEnum.JS_PAY,
CzgPayBaseReq.jsPayReq(payOrderNo, "扫码支付", orderInfo.getOrderAmount().multiply(PayService.MONEY_RATE).longValue(),
payParam.getPayType(), payParam.getOpenId(), clintIp));
}
@Override
@@ -296,12 +301,12 @@ public class OrderPayServiceImpl implements OrderPayService {
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
String payOrderNo = orderInfo.getPlatformType() + CzgRandomUtils.snowflake();
Long paymentId = payService.initOrderPayment(new OrderPayment(payParam.getShopId(), orderInfo.getId(),
PayTypeConstants.SourceType.ORDER, PayTypeConstants.PayType.PAY, payOrderNo, "", orderInfo.getOrderAmount()));
Long paymentId = payService.initPayment(OrderPayment.orderPay(payParam.getShopId(), orderInfo.getId(), payOrderNo, orderInfo.getOrderAmount(), ""));
upOrderPayInfo(orderInfo.getId(), "aliPay".equals(payParam.getPayType()) ? PayEnums.ALIPAY_MINI : PayEnums.WECHAT_MINI, paymentId,
payParam.getCheckOrderPay() == null ? null : payParam.getCheckOrderPay().getRemark());
return payService.ltPay(payParam.getShopId(), payParam.getPayType(), new CzgLtPayReq(payOrderNo, orderInfo.getOrderAmount().multiply(PayService.MONEY_RATE).longValue(),
payParam.getPayType(), "点餐支付", payParam.getOpenId(), clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
return payService.pay(payParam.getShopId(), CzgPayEnum.LT_PAY,
CzgPayBaseReq.ltPayReq(payOrderNo, "点餐支付", orderInfo.getOrderAmount().multiply(PayService.MONEY_RATE).longValue(),
payParam.getPayType(), payParam.getOpenId(), clintIp));
}
@Override
@@ -317,12 +322,11 @@ public class OrderPayServiceImpl implements OrderPayService {
BigDecimal amount = shopRechargeService.checkRecharge(mainShopId, payParam.getShopId(), shopUser.getUserId(), payParam.getRechargeDetailId(), payParam.getAmount());
payParam.setAmount(amount);
String payOrderNo = orderInfo.getPlatformType() + CzgRandomUtils.snowflake();
Long paymentId = payService.initOrderPayment(new OrderPayment(payParam.getShopId(), orderInfo.getId(),
PayTypeConstants.SourceType.ORDER, PayTypeConstants.PayType.PAY, payOrderNo, "", orderInfo.getOrderAmount()));
Long paymentId = payService.initPayment(OrderPayment.orderPay(payParam.getShopId(), orderInfo.getId(), payOrderNo, orderInfo.getOrderAmount(), ""));
upOrderPayInfo(orderInfo.getId(), PayEnums.MAIN_SCAN, paymentId,
payParam.getCheckOrderPay() == null ? null : payParam.getCheckOrderPay().getRemark());
return payService.scanPay(payParam.getShopId(), new CzgScanPayReq(payOrderNo, orderInfo.getOrderAmount().multiply(PayService.MONEY_RATE).longValue(),
"点餐支付", clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
return payService.pay(payParam.getShopId(), CzgPayEnum.SCAN_PAY,
CzgPayBaseReq.scanPayReq(payOrderNo, "点餐支付", orderInfo.getOrderAmount().multiply(PayService.MONEY_RATE).longValue(), clintIp));
}
@Override
@@ -344,10 +348,9 @@ public class OrderPayServiceImpl implements OrderPayService {
}
String payOrderNo = orderInfo.getPlatformType() + CzgRandomUtils.snowflake();
Long paymentId = payService.initOrderPayment(new OrderPayment(payParam.getShopId(), orderInfo.getId(),
PayTypeConstants.SourceType.ORDER, PayTypeConstants.PayType.PAY, payOrderNo, payParam.getAuthCode(), orderInfo.getOrderAmount()));
CzgResult<Map<String, Object>> mapCzgResult = payService.microPay(payParam.getShopId(), new CzgMicroPayReq(payOrderNo, orderInfo.getOrderAmount().multiply(PayService.MONEY_RATE).longValue(),
"点餐支付", payParam.getAuthCode(), payParam.getBuyerRemark(), ""));
Long paymentId = payService.initPayment(OrderPayment.orderPay(payParam.getShopId(), orderInfo.getId(), payOrderNo, orderInfo.getOrderAmount(), payParam.getAuthCode()));
CzgResult<Map<String, Object>> mapCzgResult = payService.pay(payParam.getShopId(), CzgPayEnum.MICRO_PAY,
CzgPayBaseReq.microPay(payOrderNo, "点餐支付", orderInfo.getOrderAmount().multiply(PayService.MONEY_RATE).longValue(), payParam.getAuthCode()));
if (mapCzgResult.getCode() == 200) {
orderInfoCustomService.upOrderInfo(orderInfo, orderInfo.getOrderAmount(),
LocalDateTime.now(), paymentId, PayEnums.BACK_SCAN);
@@ -508,8 +511,11 @@ public class OrderPayServiceImpl implements OrderPayService {
@NonNull String refundReason, @NonNull BigDecimal refundAmount) {
OrderPayment payment = paymentService.getById(payOrderId);
AssertUtil.isNull(payment, "退款失败支付记录不存在");
Long refundId = payService.initOrderPayment(new OrderPayment(shopId, orderId, PayTypeConstants.SourceType.ORDER, PayTypeConstants.PayType.REFUND, refPayOrderNo, null, refundAmount, payment.getId()));
CzgResult<CzgRefundResp> refund = payService.refund(shopId, new CzgRefundReq(refPayOrderNo, refundReason, refundAmount.multiply(PayService.MONEY_RATE).longValue(), payment.getOrderNo(), ""));
Long refundId = payService.initPayment(OrderPayment.refund(shopId, orderId, PayTypeConstants.SourceType.ORDER,
refPayOrderNo, refundAmount, payment.getId()));
CzgResult<CzgRefundResp> refund = payService.refund(shopId, new CzgRefundReq(refPayOrderNo, refundReason, refundAmount.multiply(PayService.MONEY_RATE).longValue(),
payment.getAmount().multiply(PayService.MONEY_RATE).longValue(), payment.getOrderNo(), ""));
if (refund.getCode() != 200 || refund.getData() == null || !"SUCCESS".equals(refund.getData().getState())) {
if (refund.getData() != null && refund.getData().getNote() != null) {
throw new CzgException(refund.getData().getNote());

View File

@@ -2,19 +2,24 @@ package com.czg.service.order.service.impl;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.CzgPayUtils;
import com.czg.account.entity.ShopMerchant;
import com.czg.account.service.ShopMerchantService;
import com.czg.PayAdapter;
import com.czg.PayAdapterFactory;
import com.czg.order.entity.ShopMerchant;
import com.czg.order.service.ShopMerchantService;
import com.czg.constant.PayChannelCst;
import com.czg.constants.ParamCodeCst;
import com.czg.constants.PayTypeConstants;
import com.czg.entity.req.*;
import com.czg.entity.resp.CzgBaseResp;
import com.czg.entity.resp.CzgRefundResp;
import com.czg.enums.CzgPayEnum;
import com.czg.exception.CzgException;
import com.czg.order.dto.LtPayOtherDTO;
import com.czg.order.entity.OrderPayment;
import com.czg.order.service.OrderPaymentService;
import com.czg.pay.CzgPayBaseReq;
import com.czg.pay.CzgRefundReq;
import com.czg.resp.CzgResult;
import com.czg.service.order.mapper.OrderPaymentMapper;
import com.czg.service.order.service.PayService;
@@ -49,66 +54,16 @@ public class PayServiceImpl implements PayService {
private OrderPaymentMapper paymentMapper;
@Override
public CzgResult<Map<String, Object>> h5Pay(@NonNull Long shopId, CzgH5PayReq bizData) {
public CzgResult<Map<String, Object>> pay(@NonNull Long shopId, CzgPayEnum payType, CzgPayBaseReq<?> bizData) {
ShopMerchant shopMerchant = getMerchant(shopId);
bizData.assignMerchant(shopMerchant.getStoreId(), shopMerchant.getMerchantName(),
getNotifyUrl());
return CzgPayUtils.h5Pay(getDomain(), shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
}
@Override
public CzgResult<Map<String, Object>> jsPay(@NonNull Long shopId, @NonNull String payType, CzgJsPayReq bizData) {
ShopMerchant shopMerchant = getMerchant(shopId);
bizData.setSubAppid("aliPay".equals(payType) ? shopMerchant.getAlipaySmallAppid() : shopMerchant.getWechatSmallAppid());
AssertUtil.isBlank(bizData.getSubAppid(), "暂不可用,请联系商家配置" + ("aliPay".equals(payType) ? "支付宝" : "微信") + "小程序");
bizData.assignMerchant(shopMerchant.getStoreId(), shopMerchant.getMerchantName(),
getNotifyUrl());
bizData.setPayType("aliPay".equals(payType) ? "ALIPAY" : "WECHAT");
return CzgPayUtils.jsPay(getDomain(), shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
}
@Override
public CzgResult<Map<String, Object>> ltPay(@NonNull Long shopId, String payType, CzgLtPayReq bizData) {
ShopMerchant shopMerchant = getMerchant(shopId);
bizData.setSubAppid("aliPay".equals(payType) ? shopMerchant.getAlipaySmallAppid() : shopMerchant.getWechatSmallAppid());
AssertUtil.isBlank(bizData.getSubAppid(), "暂不可用,请联系商家配置" + ("aliPay".equals(payType) ? "支付宝" : "微信") + "小程序");
bizData.assignMerchant(shopMerchant.getStoreId(), shopMerchant.getMerchantName(),
getNotifyUrl());
return CzgPayUtils.ltPay(getDomain(), shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
}
@Override
public CzgResult<Map<String, Object>> scanPay(@NonNull Long shopId, CzgScanPayReq bizData) {
ShopMerchant shopMerchant = getMerchant(shopId);
bizData.assignMerchant(shopMerchant.getStoreId(), shopMerchant.getMerchantName(),
getNotifyUrl());
return CzgPayUtils.scanPay(getDomain(), shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
}
@Override
public CzgResult<Map<String, Object>> microPay(@NonNull Long shopId, CzgMicroPayReq bizData) {
AssertUtil.isBlank(bizData.getAuthCode(), "扫码失败,请重试");
if (bizData.getAuthCode().length() > 26) {
throw new CzgException("支付失败,不支持的条码");
PayAdapter adapter = PayAdapterFactory.getAdapter(shopMerchant.getChannel());
String payData = null;
if (shopMerchant.getChannel().equals(PayChannelCst.NATIVE)) {
payData = shopMerchant.getNativePayJson();
} else if (shopMerchant.getChannel().equals(PayChannelCst.POLY)) {
payData = shopMerchant.getPolyPayJson();
}
ShopMerchant shopMerchant = getMerchant(shopId);
bizData.assignMerchant(shopMerchant.getStoreId(), shopMerchant.getMerchantName(),
getNotifyUrl());
String firstTwoDigitsStr = bizData.getAuthCode().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 CzgPayUtils.microPay(getDomain(), shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
return adapter.pay(payType, payData, getDomain(), getNotifyUrl(shopMerchant.getChannel()), bizData);
}
@Override
@@ -117,17 +72,25 @@ public class PayServiceImpl implements PayService {
AssertUtil.isBlank(param.getOpenId(), "用户小程序ID不能为空");
AssertUtil.isBlank(param.getPayType(), "支付方式不能为空");
String payOrderNo = "LT" + IdUtil.getSnowflakeNextId();
initOrderPayment(new OrderPayment(param.getShopId(), param.getRecordId(), payType, PayTypeConstants.PayType.PAY, payOrderNo,
"", param.getPrice(), null));
return ltPay(param.getShopId(), param.getPayType(), new CzgLtPayReq(payOrderNo, param.getPrice().multiply(MONEY_RATE).longValue(),
param.getPayType(), detail, param.getOpenId(), param.getIp(), "", "", ""));
initPayment(OrderPayment.pay(param.getShopId(), param.getRecordId(), payType, payOrderNo,
param.getPrice(), "", null));
return pay(param.getShopId(), CzgPayEnum.LT_PAY,
CzgPayBaseReq.ltPayReq(payOrderNo, detail, param.getPrice().multiply(MONEY_RATE).longValue(),
param.getPayType(), param.getOpenId(), param.getIp()));
}
@Override
public CzgResult<CzgRefundResp> refund(@NonNull Long shopId, CzgRefundReq bizData) {
ShopMerchant shopMerchant = getMerchant(shopId);
bizData.setNotifyUrl(sysParamsService.getSysParamValue(ParamCodeCst.System.PAY_CZG_REFUND_NOTIFY_URL));
return CzgPayUtils.refundOrder(getDomain(), shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
PayAdapter adapter = PayAdapterFactory.getAdapter(shopMerchant.getChannel());
String payData = null;
if (shopMerchant.getChannel().equals(PayChannelCst.NATIVE)) {
payData = shopMerchant.getNativePayJson();
} else if (shopMerchant.getChannel().equals(PayChannelCst.POLY)) {
payData = shopMerchant.getPolyPayJson();
}
// bizData.setNotifyUrl(sysParamsService.getSysParamValue(ParamCodeCst.System.PAY_CZG_REFUND_NOTIFY_URL));
return adapter.refund(getDomain(), payData, "", bizData);
}
@Override
@@ -136,9 +99,9 @@ public class PayServiceImpl implements PayService {
@NonNull String refundReason, @NonNull BigDecimal refundAmount) {
OrderPayment payment = paymentService.getById(payOrderId);
AssertUtil.isNull(payment, "退款失败,支付记录不存在");
Long refundId = initOrderPayment(new OrderPayment(shopId, sourceId, payment.getSourceType(), PayTypeConstants.PayType.REFUND, refPayOrderNo, null, refundAmount, payment.getId()));
Long refundId = initPayment(OrderPayment.refund(shopId, sourceId, payment.getSourceType(), refPayOrderNo, refundAmount, payment.getId()));
CzgResult<CzgRefundResp> refund = refund(shopId, new CzgRefundReq(refPayOrderNo, refundReason, refundAmount.multiply(MONEY_RATE).longValue(),
payment.getOrderNo(), ""));
payment.getAmount().multiply(PayService.MONEY_RATE).longValue(), payment.getOrderNo(), ""));
OrderPayment uOrderPayment = new OrderPayment();
uOrderPayment.setRespJson(JSONObject.toJSONString(refund.getData()));
if (refund.getCode() != 200 || refund.getData() == null || !"SUCCESS".equals(refund.getData().getState())) {
@@ -157,10 +120,10 @@ public class PayServiceImpl implements PayService {
//支付的 订单
OrderPayment payment = paymentService.getById(refundPayment.getRelatedId());
AssertUtil.isNull(payment, "退款失败,支付记录不存在");
Long refundCompensate = initOrderPayment(new OrderPayment(refundPayment.getShopId(), refundPayment.getSourceId(), payment.getSourceType(), PayTypeConstants.PayType.REFUND_COMPENSATE,
refPayOrderNo, null, refundPayment.getAmount(), refundPayment.getId()));
Long refundCompensate = initPayment(OrderPayment.refundCompensate(refundPayment.getShopId(), refundPayment.getSourceId(),
payment.getSourceType(), refPayOrderNo, refundPayment.getAmount(), refundPayment.getId()));
CzgResult<CzgRefundResp> refund = refund(payment.getShopId(), new CzgRefundReq(refPayOrderNo, "退款补偿", refundPayment.getAmount().multiply(MONEY_RATE).longValue(),
payment.getOrderNo(), ""));
payment.getAmount().multiply(PayService.MONEY_RATE).longValue(), payment.getOrderNo(), ""));
OrderPayment uOrderPayment = new OrderPayment();
uOrderPayment.setTradeNumber(refund.getData().getRefundOrderId());
uOrderPayment.setRespJson(JSONObject.toJSONString(refund.getData()));
@@ -178,26 +141,55 @@ public class PayServiceImpl implements PayService {
@Transactional
public CzgResult<CzgBaseResp> queryPayOrder(@NonNull Long shopId, String payOrderId, String mchOrderNo) {
ShopMerchant shopMerchant = getMerchant(shopId);
return CzgPayUtils.queryPayOrder(getDomain(), shopMerchant.getAppId(), shopMerchant.getAppSecret(), payOrderId, mchOrderNo);
PayAdapter adapter = PayAdapterFactory.getAdapter(shopMerchant.getChannel());
String payData = null;
if (shopMerchant.getChannel().equals(PayChannelCst.NATIVE)) {
payData = shopMerchant.getNativePayJson();
} else if (shopMerchant.getChannel().equals(PayChannelCst.POLY)) {
payData = shopMerchant.getPolyPayJson();
}
return adapter.queryPayOrder(getDomain(), payData, payOrderId, mchOrderNo);
}
@Override
@Transactional
public CzgResult<CzgRefundResp> queryRefund(@NonNull Long shopId, String mchRefundNo, String refundOrderId) {
ShopMerchant shopMerchant = getMerchant(shopId);
return CzgPayUtils.queryRefundOrder(getDomain(), shopMerchant.getAppId(), shopMerchant.getAppSecret(), mchRefundNo, refundOrderId);
PayAdapter adapter = PayAdapterFactory.getAdapter(shopMerchant.getChannel());
String payData = null;
if (shopMerchant.getChannel().equals(PayChannelCst.NATIVE)) {
payData = shopMerchant.getNativePayJson();
} else if (shopMerchant.getChannel().equals(PayChannelCst.POLY)) {
payData = shopMerchant.getPolyPayJson();
}
return adapter.queryRefund(getDomain(), payData, mchRefundNo, refundOrderId);
}
@Override
public Long initOrderPayment(OrderPayment payment) {
public Long initPayment(OrderPayment payment) {
paymentMapper.insert(payment);
return payment.getId();
}
private ShopMerchant getMerchant(Long shopId) {
try {
return shopMerchantService.getById(shopId);
ShopMerchant shopMerchant = shopMerchantService.getById(shopId);
if (shopMerchant == null || StrUtil.isBlank(shopMerchant.getChannel())) {
throw new CzgException("暂未开通支付");
}
if (shopMerchant.getChannel().equals(PayChannelCst.NATIVE)) {
if (StrUtil.isNotBlank(shopMerchant.getNativePayJson())) {
throw new CzgException("原生支付未开通");
}
} else if (shopMerchant.getChannel().equals(PayChannelCst.POLY)) {
if (StrUtil.isNotBlank(shopMerchant.getPolyPayJson())) {
throw new CzgException("聚合支付未开通");
}
} else {
throw new CzgException("暂不支持的支付渠道");
}
return shopMerchant;
} catch (Exception e) {
throw new CzgException("暂未开通支付");
}
@@ -207,7 +199,16 @@ public class PayServiceImpl implements PayService {
return sysParamsService.getSysParamValue(ParamCodeCst.System.PAY_CZG_DOMAIN);
}
private String getNotifyUrl() {
return sysParamsService.getSysParamValue(ParamCodeCst.System.PAY_CZG_NOTIFY_URL);
private String getNotifyUrl(String channel) {
String notifyUrl = "";
if (channel.equals(PayChannelCst.NATIVE)) {
notifyUrl = sysParamsService.getSysParamValue(ParamCodeCst.System.NATIVE_PAY_NOTIFY_URL);
} else if (channel.equals(PayChannelCst.POLY)) {
notifyUrl = sysParamsService.getSysParamValue(ParamCodeCst.System.POLY_PAY_NOTIFY_URL);
}
if (StrUtil.isBlank(notifyUrl)) {
throw new CzgException(channel.equals(PayChannelCst.NATIVE) ? "原生支付回调地址未配置" : "聚合支付回调地址未配置");
}
return notifyUrl;
}
}

View File

@@ -0,0 +1,121 @@
package com.czg.service.order.service.impl;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.account.service.ShopInfoService;
import com.czg.constant.PayChannelCst;
import com.czg.order.dto.ShopMerchantDTO;
import com.czg.order.entity.ShopDirectMerchant;
import com.czg.order.entity.ShopMerchant;
import com.czg.order.service.ShopMerchantService;
import com.czg.pay.NativeMerchantDTO;
import com.czg.pay.PolyMerchantDTO;
import com.czg.service.order.mapper.ShopMerchantMapper;
import com.czg.service.order.service.ShopDirectMerchantService;
import com.czg.utils.AssertUtil;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.io.Serializable;
/**
* 第三方商户进件 服务层实现。
*
* @author Administrator
* @since 2025-02-11
*/
@CacheConfig(cacheNames = "shop:merchant")
@Service
public class ShopMerchantServiceImpl extends ServiceImpl<ShopMerchantMapper, ShopMerchant> implements ShopMerchantService {
@Resource
private ShopDirectMerchantService shopDirectMerchantService;
@DubboReference
private ShopInfoService shopInfoService;
@Override
public ShopMerchantDTO detail(Long shopId) {
ShopMerchantDTO shopMerchantVO = new ShopMerchantDTO();
ShopMerchant one = queryChain().eq(ShopMerchant::getShopId, shopId).one();
if (one == null) {
return null;
}
shopMerchantVO.setShopId(shopId);
shopMerchantVO.setChannel(one.getChannel());
shopMerchantVO.setRelatedLicenceNo(one.getRelatedLicenceNo());
if (StrUtil.isNotBlank(one.getNativePayJson())) {
shopMerchantVO.setNativeMerchantDTO(JSONObject.parseObject(one.getNativePayJson(), NativeMerchantDTO.class));
}
if (StrUtil.isNotBlank(one.getPolyPayJson())) {
shopMerchantVO.setPolyMerchantDTO(JSONObject.parseObject(one.getPolyPayJson(), PolyMerchantDTO.class));
}
if (StrUtil.isNotBlank(one.getRelatedLicenceNo())) {
shopMerchantVO.setShopDirectMerchant(shopDirectMerchantService.getOne(query().eq(ShopDirectMerchant::getLicenceNo, one.getRelatedLicenceNo())));
}
return shopMerchantVO;
}
/**
* * shopId 修改的店铺Id
* * relatedLicenceNo 关联值 原生native必填 对应 tb_shop_direct_merchant 的 licence_no营业执照
* * channel {@link com.czg.constant.PayChannelCst}
* * jsonObject 支付参数 详情
* * isUp 是否要修改 传否时 如果存在支付数据 且与当前渠道不一致 则不修改
*/
@Override
@CacheEvict(key = "#shopMerchantParam.shopId")
public Boolean editEntry(ShopMerchantDTO shopMerchantParam, boolean isUp) {
ShopMerchant shopMerchant = getOne(query().eq(ShopMerchant::getShopId, shopMerchantParam.getShopId()));
if (shopMerchant == null) {
shopMerchant = new ShopMerchant();
shopMerchant.setChannel(shopMerchantParam.getChannel());
shopMerchant.setRelatedLicenceNo(shopMerchantParam.getRelatedLicenceNo());
if (PayChannelCst.NATIVE.equals(shopMerchantParam.getChannel()) && shopMerchantParam.getNativeMerchantDTO() != null) {
shopMerchant.setNativePayJson(JSONObject.toJSONString(shopMerchantParam.getNativeMerchantDTO()));
} else if (PayChannelCst.POLY.equals(shopMerchantParam.getChannel()) && shopMerchantParam.getPolyMerchantDTO() != null) {
shopMerchant.setPolyPayJson(JSONObject.toJSONString(shopMerchantParam.getPolyMerchantDTO()));
}
} else if (isUp) {
shopMerchant.setChannel(shopMerchantParam.getChannel());
shopMerchant.setShopId(shopMerchantParam.getShopId());
shopMerchant.setRelatedLicenceNo(shopMerchantParam.getRelatedLicenceNo());
if (PayChannelCst.NATIVE.equals(shopMerchantParam.getChannel()) && shopMerchantParam.getNativeMerchantDTO() != null) {
shopMerchant.setNativePayJson(JSONObject.toJSONString(shopMerchantParam.getNativeMerchantDTO()));
} else if (PayChannelCst.POLY.equals(shopMerchantParam.getChannel()) && shopMerchantParam.getPolyMerchantDTO() != null) {
shopMerchant.setPolyPayJson(JSONObject.toJSONString(shopMerchantParam.getPolyMerchantDTO()));
}
} else {
//不是新增且不是修改 只有进件完成会进入这里
if (StrUtil.isBlank(shopMerchant.getRelatedLicenceNo())) {
shopMerchant.setRelatedLicenceNo(shopMerchantParam.getRelatedLicenceNo());
}
if (StrUtil.isBlank(shopMerchant.getNativePayJson()) && shopMerchantParam.getNativeMerchantDTO() != null) {
shopMerchant.setNativePayJson(JSONObject.toJSONString(shopMerchantParam.getNativeMerchantDTO()));
}
}
return saveOrUpdate(shopMerchant);
}
@Cacheable(key = "#id")
@Override
public ShopMerchant getById(Serializable id) {
ShopMerchant shopMerchant = getMapper().selectOneById(id);
AssertUtil.isNull(shopMerchant, "暂未开通支付");
return shopMerchant;
}
@Override
public ShopDirectMerchant getMainMerchant(Long shopId) {
Long mainIdByShopId = shopInfoService.getMainIdByShopId(shopId);
if (mainIdByShopId != null) {
return shopDirectMerchantService.getOne(query().eq(ShopDirectMerchant::getShopId, mainIdByShopId));
}
return null;
}
}

View File

@@ -7,8 +7,8 @@ import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
import com.czg.account.entity.*;
import com.czg.account.service.*;
import com.czg.constants.PayTypeConstants;
import com.czg.entity.req.*;
import com.czg.entity.resp.CzgRefundResp;
import com.czg.enums.CzgPayEnum;
import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.exception.CzgException;
import com.czg.market.dto.MemberOrderDTO;
@@ -24,6 +24,8 @@ import com.czg.order.entity.OrderInfo;
import com.czg.order.entity.OrderPayment;
import com.czg.order.service.OrderInfoCustomService;
import com.czg.order.service.OrderPaymentService;
import com.czg.pay.CzgPayBaseReq;
import com.czg.pay.CzgRefundReq;
import com.czg.resp.CzgResult;
import com.czg.service.order.dto.VipMemberPayParamDTO;
import com.czg.service.order.dto.VipPayParamDTO;
@@ -131,15 +133,16 @@ public class ShopUserServiceImpl implements ShopUserPayService {
AssertUtil.isBlank(payParam.getPayType(), "支付方式不能为空");
String payOrderNo = payParam.getPlatformType() + CzgRandomUtils.snowflake();
String payType = isFree ? PayTypeConstants.SourceType.FREE : PayTypeConstants.SourceType.MEMBER_IN;
payService.initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), payType, PayTypeConstants.PayType.PAY, payOrderNo,
"", payParam.getAmount(), isFree ? payParam.getOrderId() : payParam.getActivateId()));
return payService.jsPay(payParam.getShopId(), payParam.getPayType(), new CzgJsPayReq(payOrderNo, payParam.getAmount().multiply(PayService.MONEY_RATE).longValue(),
"会员充值", payParam.getOpenId(), clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
payService.initPayment(OrderPayment.pay(payParam.getShopId(), shopUser.getId(), payType, payOrderNo,
payParam.getAmount(), "", isFree ? payParam.getOrderId() : payParam.getActivateId()));
return payService.pay(payParam.getShopId(), CzgPayEnum.JS_PAY,
CzgPayBaseReq.jsPayReq(payOrderNo, "会员充值", payParam.getAmount().multiply(PayService.MONEY_RATE).longValue(),
payParam.getPayType(), payParam.getOpenId(), clintIp));
}
@Override
@Transactional(rollbackFor = Exception.class)
public CzgResult<Map<String, Object>> ltPayMember(String clientIP, VipMemberPayParamDTO payParam) {
public CzgResult<Map<String, Object>> ltPayMember(String clientIp, VipMemberPayParamDTO payParam) {
ShopUser shopUser = shopUserService.getOne(new QueryWrapper().eq(ShopUser::getMainShopId, shopInfoService.getMainIdByShopId(payParam.getShopId())).eq(ShopUser::getId, payParam.getShopUserId()));
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
MemberOrder memberOrder = memberOrderService.createMemberOrder(new MemberOrderDTO().setName(payParam.getName())
@@ -155,7 +158,7 @@ public class ShopUserServiceImpl implements ShopUserPayService {
.setShopId(payParam.getShopId())
.setRecordId(shopUser.getId())
.setPrice(memberOrder.getAmount())
.setIp(clientIP);
.setIp(clientIp);
return payService.ltPayOther(payParam1, PayTypeConstants.SourceType.MEMBER_PAY, "会员充值");
}
@@ -191,7 +194,7 @@ public class ShopUserServiceImpl implements ShopUserPayService {
}
@Override
public CzgResult<Map<String, Object>> recharge(String clientIP, VipPayParamDTO rechargeDTO, Long shopUserId) {
public CzgResult<Map<String, Object>> recharge(String clientIp, VipPayParamDTO rechargeDTO, Long shopUserId) {
boolean isFree = checkPayVip(rechargeDTO);
Long mainShopId = shopInfoService.getMainIdByShopId(rechargeDTO.getShopId());
@@ -212,7 +215,7 @@ public class ShopUserServiceImpl implements ShopUserPayService {
.setShopId(rechargeDTO.getShopId())
.setRecordId(shopUser.getId())
.setPrice(amount)
.setIp(clientIP);
.setIp(clientIp);
return payService.ltPayOther(payParam, payType, "会员充值");
}
@@ -224,10 +227,10 @@ public class ShopUserServiceImpl implements ShopUserPayService {
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
String payOrderNo = payParam.getPlatformType() + CzgRandomUtils.snowflake();
String payType = isFree ? PayTypeConstants.SourceType.FREE : PayTypeConstants.SourceType.MEMBER_IN;
payService.initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), payType, PayTypeConstants.PayType.PAY, payOrderNo,
"", payParam.getAmount(), isFree ? payParam.getOrderId() : payParam.getActivateId()));
return payService.scanPay(payParam.getShopId(), new CzgScanPayReq(payOrderNo, payParam.getAmount().multiply(PayService.MONEY_RATE).longValue(),
"会员充值", clintIp, payParam.getReturnUrl(), payParam.getBuyerRemark(), ""));
payService.initPayment(OrderPayment.pay(payParam.getShopId(), shopUser.getId(), payType, payOrderNo,
payParam.getAmount(), "", isFree ? payParam.getOrderId() : payParam.getActivateId()));
return payService.pay(payParam.getShopId(), CzgPayEnum.SCAN_PAY,
CzgPayBaseReq.scanPayReq(payOrderNo, "会员充值", payParam.getAmount().multiply(PayService.MONEY_RATE).longValue(), clintIp));
}
@Override
@@ -239,10 +242,9 @@ public class ShopUserServiceImpl implements ShopUserPayService {
AssertUtil.isNull(shopUser, "充值失败 该店铺用户不存在");
String payOrderNo = payParam.getPlatformType() + CzgRandomUtils.snowflake();
String payType = isFree ? PayTypeConstants.SourceType.FREE : PayTypeConstants.SourceType.MEMBER_IN;
payService.initOrderPayment(new OrderPayment(payParam.getShopId(), shopUser.getId(), payType, PayTypeConstants.PayType.PAY, payOrderNo,
payParam.getAuthCode(), payParam.getAmount(), isFree ? payParam.getOrderId() : payParam.getActivateId()));
CzgResult<Map<String, Object>> mapCzgResult = payService.microPay(payParam.getShopId(), new CzgMicroPayReq(payOrderNo, payParam.getAmount().multiply(PayService.MONEY_RATE).longValue(),
"会员充值", payParam.getAuthCode(), payParam.getBuyerRemark(), ""));
payService.initPayment(OrderPayment.pay(payParam.getShopId(), shopUser.getId(), payType, payOrderNo, payParam.getAmount(), "", isFree ? payParam.getOrderId() : payParam.getActivateId()));
CzgResult<Map<String, Object>> mapCzgResult = payService.pay(payParam.getShopId(), CzgPayEnum.MICRO_PAY,
CzgPayBaseReq.microPay(payOrderNo, "会员充值", payParam.getAmount().multiply(PayService.MONEY_RATE).longValue(), payParam.getAuthCode()));
mapCzgResult.setData(Map.of("payOrderNo", payOrderNo));
return mapCzgResult;
}
@@ -309,10 +311,11 @@ public class ShopUserServiceImpl implements ShopUserPayService {
return CzgResult.failure("退款失败,该充值记录不存在");
}
String refPayOrderNo = "REFVIP" + IdUtil.getSnowflakeNextId();
refPaymentId = payService.initOrderPayment(new OrderPayment(refPayParam.getShopId(), shopUser.getId(),
PayTypeConstants.SourceType.MEMBER_IN, PayTypeConstants.PayType.REFUND, refPayOrderNo, null, refPayParam.getRefAmount()));
refPaymentId = payService.initPayment(OrderPayment.refund(refPayParam.getShopId(), shopUser.getId(), PayTypeConstants.SourceType.MEMBER_IN,
refPayOrderNo, refPayParam.getRefAmount(), inFlow.getId()));
CzgResult<CzgRefundResp> refund = payService.refund(refPayParam.getShopId(), new CzgRefundReq(refPayOrderNo, refPayParam.getRemark(),
refPayParam.getRefAmount().multiply(PayService.MONEY_RATE).longValue(), payment.getOrderNo(), ""));
refPayParam.getRefAmount().multiply(PayService.MONEY_RATE).longValue(), payment.getAmount().multiply(PayService.MONEY_RATE).longValue(),
payment.getOrderNo(), ""));
if (refund.getCode() != 200 || refund.getData() == null || !"SUCCESS".equals(refund.getData().getState())) {
throw new CzgException(refund.getMsg());
} else {

View File

@@ -2,6 +2,6 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.czg.service.account.mapper.ShopMerchantMapper">
<mapper namespace="com.czg.service.order.mapper.ShopMerchantMapper">
</mapper>

View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.czg</groupId>
<artifactId>cash</artifactId>
<version>1.0.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>pay-service</artifactId>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.czg</groupId>
<artifactId>cash-common-tools</artifactId>
</dependency>
<dependency>
<groupId>com.czg</groupId>
<artifactId>poly-pay</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.czg</groupId>
<artifactId>aggregation-pay</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,50 @@
package com.czg;
import com.czg.pay.CzgPayBaseReq;
import com.czg.pay.CzgRefundReq;
import com.czg.entity.resp.CzgBaseResp;
import com.czg.entity.resp.CzgRefundResp;
import com.czg.enums.CzgPayEnum;
import com.czg.pay.NativeMerchantDTO;
import com.czg.pay.PolyMerchantDTO;
import com.czg.resp.CzgResult;
import jakarta.validation.constraints.NotBlank;
import lombok.NonNull;
import java.util.Map;
/**
* 支付适配器接口
*
* @author ww
*
*/
public interface PayAdapter {
/**
* 支付渠道
* {@link com.czg.constant.PayChannelCst}
*/
String getChannel();
/**
* 统一支付接口
*
* @param payType 支付类型
* @param payData 支付数据 Json类型
* 对应 聚合支付参数 {@link PolyMerchantDTO}
* 对应 原生支付参数 {@link NativeMerchantDTO}
* @param domain 域名 请求地址
* @param notifyUrl 通知地址
* @param bizData 业务数据
*/
CzgResult<Map<String, Object>> pay(@NonNull CzgPayEnum payType, @NotBlank String payData, @NotBlank String domain,
@NotBlank String notifyUrl, CzgPayBaseReq<?> bizData);
CzgResult<CzgRefundResp> refund(@NotBlank String domain, @NotBlank String payData, String notifyUrl, CzgRefundReq bizData);
CzgResult<CzgBaseResp> queryPayOrder(@NotBlank String domain, @NotBlank String payData, String payOrderId, String mchOrderNo);
CzgResult<CzgRefundResp> queryRefund(@NotBlank String domain, @NotBlank String payData, String mchRefundNo, String refundOrderId);
}

View File

@@ -0,0 +1,39 @@
package com.czg;
import com.czg.constant.PayChannelCst;
import com.czg.impl.NativePayAdapter;
import com.czg.impl.PolyPayAdapter;
import java.util.HashMap;
import java.util.Map;
/**
* 支付适配器工厂
*
* @author ww
*/
public class PayAdapterFactory {
private static final Map<String, PayAdapter> ADAPTER_MAP = new HashMap<>();
static {
ADAPTER_MAP.put(PayChannelCst.POLY, new PolyPayAdapter());
ADAPTER_MAP.put(PayChannelCst.NATIVE, new NativePayAdapter());
}
/**
* 获取支付适配器
*
* @param channel 支付渠道,仅支持 {@link PayChannelCst}
*/
public static PayAdapter getAdapter(String channel) {
PayAdapter adapter = ADAPTER_MAP.get(channel);
if (adapter == null) {
throw new IllegalStateException("支付渠道未注册适配器: " + channel);
}
return adapter;
}
}

View File

@@ -0,0 +1,73 @@
package com.czg.impl;
import com.alibaba.fastjson2.JSONObject;
import com.czg.PayAdapter;
import com.czg.constant.PayChannelCst;
import com.czg.entity.resp.CzgBaseResp;
import com.czg.entity.resp.CzgRefundResp;
import com.czg.enums.CzgPayEnum;
import com.czg.exception.CzgException;
import com.czg.pay.CzgPayBaseReq;
import com.czg.pay.CzgRefundReq;
import com.czg.pay.NativeMerchantDTO;
import com.czg.resp.CzgResult;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import java.util.Map;
/**
* 原生支付适配器
*
* @author ww
* @date 2023/10/20 14:20
*/
@Slf4j
public class NativePayAdapter implements PayAdapter {
@Override
public String getChannel() {
return PayChannelCst.NATIVE;
}
@Override
public CzgResult<Map<String, Object>> pay(@NonNull CzgPayEnum payType, String payData, String domain, String notifyUrl, CzgPayBaseReq<?> bizData) {
try {
NativeMerchantDTO polyMerchantDTO = JSONObject.parseObject(payData, NativeMerchantDTO.class);
switch (payType) {
// case H5_PAY:
// return h5Pay(polyMerchantDTO, domain, notifyUrl, bizData);
// case JS_PAY:
// return jsPay(polyMerchantDTO, domain, notifyUrl, bizData);
// case LT_PAY:
// return ltPay(polyMerchantDTO, domain, notifyUrl, bizData);
// case SCAN_PAY:
// return scanPay(polyMerchantDTO, domain, notifyUrl, bizData);
// case MICRO_PAY:
// //扫码支付 扫描码
// return microPay(polyMerchantDTO, domain, notifyUrl, (CzgPayBaseReq<String>) bizData);
default:
throw new CzgException("原生支付不支持该支付方式: " + bizData.getPayType());
}
} catch (Exception e) {
log.error("聚合支付处理失败: {}", e.getMessage(), e);
return CzgResult.failure("聚合支付处理失败: " + e.getMessage());
}
}
@Override
public CzgResult<CzgRefundResp> refund(String domain, String payData, String notifyUrl, CzgRefundReq bizData) {
return null;
}
@Override
public CzgResult<CzgBaseResp> queryPayOrder(String domain, String payData, String payOrderId, String mchOrderNo) {
return null;
}
@Override
public CzgResult<CzgRefundResp> queryRefund(String domain, String payData, String mchRefundNo, String refundOrderId) {
return null;
}
}

View File

@@ -0,0 +1,120 @@
package com.czg.impl;
import com.alibaba.fastjson2.JSONObject;
import com.czg.PayAdapter;
import com.czg.PolyPayUtils;
import com.czg.constant.PayChannelCst;
import com.czg.entity.resp.CzgBaseResp;
import com.czg.entity.resp.CzgRefundResp;
import com.czg.enums.CzgPayEnum;
import com.czg.exception.CzgException;
import com.czg.pay.CzgPayBaseReq;
import com.czg.pay.CzgRefundReq;
import com.czg.pay.PolyMerchantDTO;
import com.czg.resp.CzgResult;
import com.czg.utils.AssertUtil;
import jakarta.validation.constraints.NotBlank;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import java.util.Map;
/**
* @author ww
*/
@Slf4j
public class PolyPayAdapter implements PayAdapter {
@Override
public String getChannel() {
return PayChannelCst.POLY;
}
@Override
public CzgResult<Map<String, Object>> pay(@NonNull CzgPayEnum payType, @NotBlank String payData, @NotBlank String domain,
@NotBlank String notifyUrl, CzgPayBaseReq<?> bizData) {
try {
PolyMerchantDTO polyMerchantDTO = JSONObject.parseObject(payData, PolyMerchantDTO.class);
return switch (payType) {
case H5_PAY -> h5Pay(polyMerchantDTO, domain, notifyUrl, bizData);
case JS_PAY -> jsPay(polyMerchantDTO, domain, notifyUrl, bizData);
case LT_PAY -> ltPay(polyMerchantDTO, domain, notifyUrl, bizData);
case SCAN_PAY -> scanPay(polyMerchantDTO, domain, notifyUrl, bizData);
case MICRO_PAY -> microPay(polyMerchantDTO, domain, notifyUrl, (CzgPayBaseReq<String>) bizData);
default -> throw new CzgException("聚合支付不支持该支付方式: " + bizData.getPayType());
};
} catch (Exception e) {
log.error("聚合支付处理失败: {}", e.getMessage(), e);
return CzgResult.failure("聚合支付处理失败: " + e.getMessage());
}
}
@Override
public CzgResult<CzgRefundResp> refund(@NotBlank String domain, @NotBlank String payData, String notifyUrl, CzgRefundReq bizData) {
PolyMerchantDTO shopMerchant = JSONObject.parseObject(payData, PolyMerchantDTO.class);
bizData.setNotifyUrl(notifyUrl);
return PolyPayUtils.refundOrder(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
}
@Override
public CzgResult<CzgBaseResp> queryPayOrder(@NotBlank String payData, @NotBlank String domain, String payOrderId, String mchOrderNo) {
PolyMerchantDTO shopMerchant = JSONObject.parseObject(payData, PolyMerchantDTO.class);
PolyPayUtils.queryPayOrder(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), payOrderId, mchOrderNo);
return null;
}
@Override
public CzgResult<CzgRefundResp> queryRefund(@NotBlank String payData, @NotBlank String domain, String mchRefundNo, String refundOrderId) {
PolyMerchantDTO shopMerchant = JSONObject.parseObject(payData, PolyMerchantDTO.class);
return PolyPayUtils.queryRefundOrder(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), mchRefundNo, refundOrderId);
}
private CzgResult<Map<String, Object>> h5Pay(PolyMerchantDTO shopMerchant, String domain, String notifyUrl, CzgPayBaseReq<?> bizData) {
bizData.polyBase(shopMerchant.getStoreId(), notifyUrl);
return PolyPayUtils.h5Pay(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), 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(), "暂不可用,请联系商家配置" + ("aliPay".equals(bizData.getPayType()) ? "支付宝" : "微信") + "小程序");
bizData.setPayType("aliPay".equals(bizData.getPayType()) ? "ALIPAY" : "WECHAT");
bizData.polyBase(shopMerchant.getStoreId(), notifyUrl);
return PolyPayUtils.jsPay(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), 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()) ? "支付宝" : "微信") + "小程序");
bizData.polyBase(shopMerchant.getStoreId(), notifyUrl);
return PolyPayUtils.ltPay(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
}
private CzgResult<Map<String, Object>> scanPay(PolyMerchantDTO shopMerchant, String domain, String notifyUrl, CzgPayBaseReq<?> bizData) {
bizData.polyBase(shopMerchant.getStoreId(), notifyUrl);
return PolyPayUtils.scanPay(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), 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);
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);
}
}

View File

@@ -27,6 +27,7 @@
<module>cash-sdk</module>
<module>cash-dependencies</module>
<module>cash-api/market-server</module>
<module>cash-service/pay-service</module>
</modules>
<properties>