mirror of
https://gitee.com/dromara/dax-pay.git
synced 2025-09-02 02:34:34 +00:00
feat 集成统一支付SDK代码结构调整
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package org.dromara.daxpay.channel.union.code;
|
||||
|
||||
import org.dromara.daxpay.channel.union.sdk.bean.SDKConstants;
|
||||
|
||||
/**
|
||||
* 云闪付常量编码
|
||||
* @author xxm
|
||||
@@ -7,6 +9,69 @@ package org.dromara.daxpay.channel.union.code;
|
||||
*/
|
||||
public interface UnionPayCode {
|
||||
|
||||
/** 应答码 00表示成功 */
|
||||
String RESP_CODE = SDKConstants.param_respCode;
|
||||
|
||||
/** 原交易应答码 00表示成功 */
|
||||
String RESP_ORIG_CODE = SDKConstants.param_origRespCode;
|
||||
|
||||
/** 应答码信息 */
|
||||
String RESP_MSG = SDKConstants.param_respMsg;
|
||||
|
||||
/** 业务结果 00表示成功 */
|
||||
String RESP_SUCCESS = SDKConstants.OK_RESP_CODE;
|
||||
|
||||
/** 交易类型 */
|
||||
String TXN_TYPE = "txnType";
|
||||
|
||||
/** 网关订单号 */
|
||||
String QUERY_ID = "queryId";
|
||||
|
||||
/** 第三方订单号(本地订单号) */
|
||||
String ORDER_ID = "orderId";
|
||||
|
||||
/** APP支付 银联订单号 */
|
||||
String PAY_APP_TN = SDKConstants.param_tn;
|
||||
|
||||
/** 交易类型 支付 */
|
||||
String TXN_TYPE_PAY = "01";
|
||||
|
||||
/** 交易类型 退款 */
|
||||
String TXN_TYPE_REFUND = "04";
|
||||
|
||||
/**
|
||||
* 订单发送时间
|
||||
* 格式: yyyyMMddHHmmss
|
||||
*/
|
||||
String TXN_TIME = "txnTime";
|
||||
|
||||
|
||||
/** 退款金额 */
|
||||
String TXN_AMT = "txnAmt";
|
||||
|
||||
/** 总金额 */
|
||||
String TOTAL_FEE = "settleAmt";
|
||||
|
||||
/** 对账单下载类型编码 */
|
||||
String RECONCILE_BILL_TYPE = "00";
|
||||
|
||||
/** 文件内容 */
|
||||
String FILE_CONTENT = "fileContent";
|
||||
|
||||
/** 明细对账单文件前缀 */
|
||||
String RECONCILE_FILE_PREFIX = "INN";
|
||||
|
||||
/* 对账单交易代码 */
|
||||
/** 消费 */
|
||||
String RECONCILE_TYPE_PAY = "S22";
|
||||
|
||||
/** 退款 */
|
||||
String RECONCILE_TYPE_REFUND = "S30 ";
|
||||
|
||||
|
||||
/** 对账各字段位数游标 */
|
||||
int[] RECONCILE_BILL_SPLIT = {3,11,11,6,10,19,12,4,2,21,2,32,2,6,10,13,13,4,15,2,2,6,2,4,32,1,21,15,1,15,32,13,13,8,32,13,13,12,2,1,32,13,2,1,12,67};
|
||||
|
||||
/**
|
||||
* 签名类型
|
||||
*/
|
||||
|
@@ -149,11 +149,6 @@ public class UnionPayConfigStorage extends BasePayConfigStorage {
|
||||
this.keyPrivateCertPwd = keyPrivateCertPwd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAppid() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用id
|
||||
* 纠正名称
|
||||
@@ -165,26 +160,6 @@ public class UnionPayConfigStorage extends BasePayConfigStorage {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 合作者id
|
||||
* @see #getPid()
|
||||
*/
|
||||
@Deprecated
|
||||
public String getPartner() {
|
||||
return merId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置合作者id
|
||||
*
|
||||
* @param partner 合作者id
|
||||
* @see #setPid(String)
|
||||
*/
|
||||
@Deprecated
|
||||
public void setPartner(String partner) {
|
||||
this.merId = partner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPid() {
|
||||
|
@@ -1,6 +1,8 @@
|
||||
package org.dromara.daxpay.channel.union.sdk.api;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.daxpay.channel.union.sdk.bean.*;
|
||||
import org.dromara.daxpay.unisdk.common.bean.*;
|
||||
import org.dromara.daxpay.unisdk.common.bean.outbuilder.PayTextOutMessage;
|
||||
@@ -30,6 +32,7 @@ import java.util.*;
|
||||
* @author xxm
|
||||
* @since 2024/3/8
|
||||
*/
|
||||
@Slf4j
|
||||
public class UnionPayKit extends UnionPayService {
|
||||
/**
|
||||
* 测试域名
|
||||
@@ -90,7 +93,7 @@ public class UnionPayKit extends UnionPayService {
|
||||
certDescriptor.initRootCert(payConfigStorage.getAcpRootCertInputStream());
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.error("", e);
|
||||
log.error("", e);
|
||||
}
|
||||
|
||||
|
||||
@@ -182,18 +185,6 @@ public class UnionPayKit extends UnionPayService {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 回调校验
|
||||
*
|
||||
* @param result 回调回来的参数集
|
||||
* @return 签名校验 true通过
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public boolean verify(Map<String, Object> result) {
|
||||
return verify(new NoticeParams(result));
|
||||
}
|
||||
|
||||
/**
|
||||
* 回调校验
|
||||
*
|
||||
@@ -204,7 +195,7 @@ public class UnionPayKit extends UnionPayService {
|
||||
public boolean verify(NoticeParams noticeParams) {
|
||||
final Map<String, Object> result = noticeParams.getBody();
|
||||
if (null == result || result.get(SDKConstants.param_signature) == null) {
|
||||
LOG.debug("银联支付验签异常:params:" + result);
|
||||
log.debug("银联支付验签异常:params:" + result);
|
||||
return false;
|
||||
}
|
||||
return this.signVerify(result, (String) result.get(SDKConstants.param_signature));
|
||||
@@ -275,7 +266,7 @@ public class UnionPayKit extends UnionPayService {
|
||||
|
||||
params.put(SDKConstants.param_orderId, order.getOutTradeNo());
|
||||
|
||||
if (StringUtils.isNotEmpty(order.getAddition())) {
|
||||
if (StrUtil.isNotEmpty(order.getAddition())) {
|
||||
params.put(SDKConstants.param_reqReserved, order.getAddition());
|
||||
}
|
||||
switch (type) {
|
||||
@@ -303,7 +294,6 @@ public class UnionPayKit extends UnionPayService {
|
||||
params.put("orderDesc", order.getSubject());
|
||||
}
|
||||
params.putAll(order.getAttrs());
|
||||
params = preOrderHandler(params, order);
|
||||
return setSign(params);
|
||||
}
|
||||
|
||||
@@ -384,10 +374,10 @@ public class UnionPayKit extends UnionPayService {
|
||||
return cert;
|
||||
}
|
||||
catch (CertPathBuilderException e) {
|
||||
LOG.error("verify certificate chain fail.", e);
|
||||
log.error("verify certificate chain fail.", e);
|
||||
}
|
||||
catch (GeneralSecurityException e) {
|
||||
LOG.error("", e);
|
||||
log.error("", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -432,7 +422,7 @@ public class UnionPayKit extends UnionPayService {
|
||||
public String getQrPay(PayOrder order) {
|
||||
order.setTransactionType(UnionTransactionType.APPLY_QR_CODE);
|
||||
JSONObject response = postOrder(order, getBackTransUrl());
|
||||
if (this.verify(response)) {
|
||||
if (this.verify(new NoticeParams(response))) {
|
||||
if (SDKConstants.OK_RESP_CODE.equals(response.get(SDKConstants.param_respCode))) {
|
||||
//成功
|
||||
return (String) response.get(SDKConstants.param_qrCode);
|
||||
@@ -545,7 +535,7 @@ public class UnionPayKit extends UnionPayService {
|
||||
order.setTransactionType(UnionTransactionType.APP);
|
||||
}
|
||||
JSONObject response = postOrder(order, getAppTransUrl());
|
||||
if (this.verify(response)) {
|
||||
if (this.verify(new NoticeParams(response))) {
|
||||
if (SDKConstants.OK_RESP_CODE.equals(response.get(SDKConstants.param_respCode))) {
|
||||
// //成功,获取tn号
|
||||
// String tn = (String)response.get(SDKConstants.param_tn);
|
||||
@@ -556,19 +546,6 @@ public class UnionPayKit extends UnionPayService {
|
||||
throw new PayErrorException(new PayException("failure", "验证签名失败", response.toJSONString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 交易查询接口
|
||||
*
|
||||
* @param tradeNo 支付平台订单号
|
||||
* @param outTradeNo 商户单号
|
||||
* @return 返回查询回来的结果集,支付方原值返回
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> query(String tradeNo, String outTradeNo) {
|
||||
return query(new AssistOrder(tradeNo, outTradeNo));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 交易查询接口
|
||||
*
|
||||
@@ -629,19 +606,6 @@ public class UnionPayKit extends UnionPayService {
|
||||
throw new PayErrorException(new PayException("failure", "验证签名失败", response.toJSONString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 交易关闭接口
|
||||
* 使用冲正接口
|
||||
*
|
||||
* @param tradeNo 支付平台订单号
|
||||
* @param outTradeNo 商户单号
|
||||
* @return 返回支付方交易关闭后的结果
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> close(String tradeNo, String outTradeNo) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* 交易关闭接口
|
||||
* TODO 这个是冲正接口, 后续进行迁移
|
||||
|
@@ -184,20 +184,6 @@ public class UnionPayService extends BasePayService<UnionPayConfigStorage> {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 回调校验
|
||||
*
|
||||
* @param result 回调回来的参数集
|
||||
* @return 签名校验 true通过
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public boolean verify(Map<String, Object> result) {
|
||||
|
||||
|
||||
return verify(new NoticeParams(result));
|
||||
}
|
||||
|
||||
/**
|
||||
* 回调校验
|
||||
*
|
||||
@@ -309,7 +295,6 @@ public class UnionPayService extends BasePayService<UnionPayConfigStorage> {
|
||||
params.put("orderDesc", order.getSubject());
|
||||
}
|
||||
params.putAll(order.getAttrs());
|
||||
params = preOrderHandler(params, order);
|
||||
return setSign(params);
|
||||
}
|
||||
|
||||
@@ -441,7 +426,7 @@ public class UnionPayService extends BasePayService<UnionPayConfigStorage> {
|
||||
public String getQrPay(PayOrder order) {
|
||||
order.setTransactionType(UnionTransactionType.APPLY_QR_CODE);
|
||||
JSONObject response = postOrder(order, getBackTransUrl());
|
||||
if (this.verify(response)) {
|
||||
if (this.verify(new NoticeParams(response))) {
|
||||
if (SDKConstants.OK_RESP_CODE.equals(response.get(SDKConstants.param_respCode))) {
|
||||
//成功
|
||||
return (String) response.get(SDKConstants.param_qrCode);
|
||||
@@ -550,7 +535,7 @@ public class UnionPayService extends BasePayService<UnionPayConfigStorage> {
|
||||
order.setTransactionType(UnionTransactionType.APP);
|
||||
}
|
||||
JSONObject response = postOrder(order, getAppTransUrl());
|
||||
if (this.verify(response)) {
|
||||
if (this.verify(new NoticeParams(response))) {
|
||||
if (SDKConstants.OK_RESP_CODE.equals(response.get(SDKConstants.param_respCode))) {
|
||||
// //成功,获取tn号
|
||||
// String tn = (String)response.get(SDKConstants.param_tn);
|
||||
@@ -562,19 +547,6 @@ public class UnionPayService extends BasePayService<UnionPayConfigStorage> {
|
||||
throw new PayErrorException(new PayException("failure", "验证签名失败", response.toJSONString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 交易查询接口
|
||||
*
|
||||
* @param tradeNo 支付平台订单号
|
||||
* @param outTradeNo 商户单号
|
||||
* @return 返回查询回来的结果集,支付方原值返回
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> query(String tradeNo, String outTradeNo) {
|
||||
return query(new AssistOrder(tradeNo, outTradeNo));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 交易查询接口
|
||||
*
|
||||
@@ -646,18 +618,6 @@ public class UnionPayService extends BasePayService<UnionPayConfigStorage> {
|
||||
throw new PayErrorException(new PayException("failure", "验证签名失败", response.toJSONString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 交易关闭接口
|
||||
*
|
||||
* @param tradeNo 支付平台订单号
|
||||
* @param outTradeNo 商户单号
|
||||
* @return 返回支付方交易关闭后的结果
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> close(String tradeNo, String outTradeNo) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* 交易关闭接口
|
||||
*
|
||||
@@ -718,7 +678,7 @@ public class UnionPayService extends BasePayService<UnionPayConfigStorage> {
|
||||
this.setSign(params);
|
||||
String responseStr = getHttpRequestTemplate().postForObject(this.getFileTransUrl(), params, String.class);
|
||||
JSONObject response = UriVariables.getParametersToMap(responseStr);
|
||||
if (this.verify(response)) {
|
||||
if (this.verify(new NoticeParams(response))) {
|
||||
if (SDKConstants.OK_RESP_CODE.equals(response.get(SDKConstants.param_respCode))) {
|
||||
return response;
|
||||
|
||||
|
@@ -0,0 +1,12 @@
|
||||
package org.dromara.daxpay.channel.union.sdk.bean;
|
||||
|
||||
|
||||
import org.dromara.daxpay.unisdk.common.bean.PayOrder;
|
||||
|
||||
/**
|
||||
* 继承SDK中的类, 防止与系统中的类名称冲突
|
||||
* @author xxm
|
||||
* @since 2024/3/8
|
||||
*/
|
||||
public class UnionPayOrder extends PayOrder {
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
package org.dromara.daxpay.channel.union.sdk.bean;
|
||||
|
||||
|
||||
import org.dromara.daxpay.unisdk.common.bean.RefundOrder;
|
||||
|
||||
/**
|
||||
* 继承SDK中的类, 防止与系统中的类名称冲突
|
||||
* @author xxm
|
||||
* @since 2024/3/8
|
||||
*/
|
||||
public class UnionRefundOrder extends RefundOrder {
|
||||
}
|
@@ -14,6 +14,7 @@ import org.dromara.daxpay.channel.union.result.UnionPayConfigResult;
|
||||
import org.dromara.daxpay.channel.union.sdk.api.UnionPayConfigStorage;
|
||||
import org.dromara.daxpay.channel.union.sdk.api.UnionPayKit;
|
||||
import org.dromara.daxpay.core.enums.ChannelEnum;
|
||||
import org.dromara.daxpay.core.exception.ChannelNotEnableException;
|
||||
import org.dromara.daxpay.core.exception.ConfigNotEnableException;
|
||||
import org.dromara.daxpay.core.exception.DataErrorException;
|
||||
import org.dromara.daxpay.service.common.cache.ChannelConfigCacheService;
|
||||
@@ -95,7 +96,18 @@ public class UnionPayConfigService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取支付宝支付配置
|
||||
* 获取并检查支付配置
|
||||
*/
|
||||
public UnionPayConfig getAndCheckConfig() {
|
||||
UnionPayConfig unionPayConfig = this.getUnionPayConfig();
|
||||
if (!unionPayConfig.getEnable()){
|
||||
throw new ChannelNotEnableException("云闪付支付未启用");
|
||||
}
|
||||
return unionPayConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取云闪付支付配置
|
||||
*/
|
||||
public UnionPayConfig getUnionPayConfig(){
|
||||
MchAppLocal mchAppInfo = PaymentContextLocal.get().getMchAppInfo();
|
||||
|
@@ -0,0 +1,181 @@
|
||||
package org.dromara.daxpay.channel.union.service.pay;
|
||||
|
||||
import cn.bootx.platform.core.exception.ValidationFailedException;
|
||||
import cn.bootx.platform.core.util.BigDecimalUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.daxpay.channel.union.code.UnionPayCode;
|
||||
import org.dromara.daxpay.channel.union.entity.config.UnionPayConfig;
|
||||
import org.dromara.daxpay.channel.union.param.pay.UnionPayParam;
|
||||
import org.dromara.daxpay.channel.union.sdk.api.UnionPayKit;
|
||||
import org.dromara.daxpay.channel.union.sdk.bean.UnionPayOrder;
|
||||
import org.dromara.daxpay.channel.union.sdk.bean.UnionTransactionType;
|
||||
import org.dromara.daxpay.core.enums.PayMethodEnum;
|
||||
import org.dromara.daxpay.core.exception.AmountExceedLimitException;
|
||||
import org.dromara.daxpay.core.exception.TradeFailException;
|
||||
import org.dromara.daxpay.core.param.trade.pay.PayParam;
|
||||
import org.dromara.daxpay.service.bo.trade.PayResultBo;
|
||||
import org.dromara.daxpay.service.entity.order.pay.PayOrder;
|
||||
import org.dromara.daxpay.unisdk.common.bean.NoticeParams;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 云闪付支付
|
||||
* @author xxm
|
||||
* @since 2022/3/11
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class UnionPayService {
|
||||
|
||||
/**
|
||||
* 支付前检查支付方式是否可用
|
||||
*/
|
||||
public void validation(PayParam payParam, UnionPayConfig unionPayConfig) {
|
||||
|
||||
// 支付金额是否超限
|
||||
if (BigDecimalUtil.isGreaterThan(payParam.getAmount(),unionPayConfig.getLimitAmount())) {
|
||||
throw new AmountExceedLimitException("微信支付金额超限");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付接口
|
||||
*/
|
||||
public PayResultBo pay(PayOrder payOrder, UnionPayParam unionPayParam, UnionPayKit unionPayKit){
|
||||
BigDecimal totalFee = payOrder.getAmount();
|
||||
String payBody = null;
|
||||
PayMethodEnum payMethodEnum = PayMethodEnum.findByCode(payOrder.getMethod());
|
||||
|
||||
// 二维码支付
|
||||
if (payMethodEnum == PayMethodEnum.QRCODE) {
|
||||
payBody = this.qrCodePay(totalFee, payOrder, unionPayKit);
|
||||
}
|
||||
// 付款码支付
|
||||
else if (payMethodEnum == PayMethodEnum.BARCODE) {
|
||||
this.barCodePay(totalFee, payOrder, unionPayParam.getAuthCode(), unionPayKit);
|
||||
}
|
||||
// APP支付
|
||||
else if (payMethodEnum == PayMethodEnum.APP) {
|
||||
payBody = this.appPay(totalFee, payOrder, unionPayParam, unionPayKit);
|
||||
}
|
||||
// web支付
|
||||
else if (payMethodEnum == PayMethodEnum.WEB) {
|
||||
payBody = this.formPay(totalFee, payOrder, unionPayKit, UnionTransactionType.WEB);
|
||||
}
|
||||
// wap支付
|
||||
else if (payMethodEnum == PayMethodEnum.WAP) {
|
||||
payBody = this.formPay(totalFee, payOrder, unionPayKit, UnionTransactionType.WAP );
|
||||
}
|
||||
|
||||
return new PayResultBo().setPayBody(payBody);
|
||||
}
|
||||
|
||||
/**
|
||||
* jsapi支付
|
||||
*/
|
||||
private String formPay(BigDecimal amount, PayOrder payOrder, UnionPayKit unionPayKit, UnionTransactionType type) {
|
||||
Date expiredTime = DateUtil.date(payOrder.getExpiredTime());
|
||||
|
||||
UnionPayOrder unionPayOrder = new UnionPayOrder();
|
||||
unionPayOrder.setOutTradeNo(payOrder.getOrderNo());
|
||||
unionPayOrder.setSubject(payOrder.getTitle());
|
||||
unionPayOrder.setPrice(amount);
|
||||
unionPayOrder.setExpirationTime(expiredTime);
|
||||
unionPayOrder.setTransactionType(type);
|
||||
return unionPayKit.toPay(unionPayOrder);
|
||||
}
|
||||
|
||||
/**
|
||||
* jsapi支付
|
||||
*/
|
||||
private String b2bPay(BigDecimal amount, PayOrder payOrder, UnionPayKit unionPayKit) {
|
||||
Date expiredTime = DateUtil.date(payOrder.getExpiredTime());
|
||||
|
||||
UnionPayOrder unionPayOrder = new UnionPayOrder();
|
||||
unionPayOrder.setOutTradeNo(payOrder.getOrderNo());
|
||||
unionPayOrder.setSubject(payOrder.getTitle());
|
||||
unionPayOrder.setPrice(amount);
|
||||
unionPayOrder.setExpirationTime(expiredTime);
|
||||
unionPayOrder.setTransactionType(UnionTransactionType.B2B);
|
||||
return unionPayKit.toPay(unionPayOrder);
|
||||
}
|
||||
|
||||
/**
|
||||
* APP支付
|
||||
*/
|
||||
private String appPay(BigDecimal amount, PayOrder payOrder, UnionPayParam unionPayParam, UnionPayKit unionPayKit) {
|
||||
|
||||
Date expiredTime = DateUtil.date(payOrder.getExpiredTime());
|
||||
|
||||
|
||||
UnionPayOrder unionPayOrder = new UnionPayOrder();
|
||||
unionPayOrder.setOutTradeNo(payOrder.getOrderNo());
|
||||
unionPayOrder.setSubject(payOrder.getTitle());
|
||||
unionPayOrder.setPrice(amount);
|
||||
unionPayOrder.setExpirationTime(expiredTime);
|
||||
|
||||
Map<String, Object> result = unionPayKit.app(unionPayOrder);
|
||||
String resultCode = MapUtil.getStr(result, UnionPayCode.RESP_CODE);
|
||||
|
||||
// 支付失败
|
||||
if (!(Objects.equals(resultCode, UnionPayCode.RESP_SUCCESS))) {
|
||||
log.warn("云闪付支付失败:{}", result);
|
||||
String errMsg = MapUtil.getStr(result, UnionPayCode.RESP_MSG);
|
||||
throw new TradeFailException(errMsg);
|
||||
}
|
||||
|
||||
return MapUtil.getStr(result, UnionPayCode.PAY_APP_TN);
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫码支付
|
||||
*/
|
||||
private String qrCodePay(BigDecimal amount, PayOrder payOrder, UnionPayKit unionPayKit){
|
||||
Date expiredTime = DateUtil.date(payOrder.getExpiredTime());
|
||||
|
||||
UnionPayOrder unionPayOrder = new UnionPayOrder();
|
||||
unionPayOrder.setOutTradeNo(payOrder.getOrderNo());
|
||||
unionPayOrder.setSubject(payOrder.getTitle());
|
||||
unionPayOrder.setPrice(amount);
|
||||
unionPayOrder.setExpirationTime(expiredTime);
|
||||
return unionPayKit.getQrPay(unionPayOrder);
|
||||
}
|
||||
|
||||
/**
|
||||
* 付款码支付
|
||||
*/
|
||||
private void barCodePay(BigDecimal amount, PayOrder payOrder, String authCode, UnionPayKit unionPayKit) {
|
||||
Date expiredTime = DateUtil.date(payOrder.getExpiredTime());
|
||||
|
||||
UnionPayOrder unionPayOrder = new UnionPayOrder();
|
||||
unionPayOrder.setAuthCode(authCode);
|
||||
unionPayOrder.setOutTradeNo(payOrder.getOrderNo());
|
||||
unionPayOrder.setSubject(payOrder.getTitle());
|
||||
unionPayOrder.setPrice(amount);
|
||||
unionPayOrder.setExpirationTime(expiredTime);
|
||||
Map<String, Object> result = unionPayKit.microPay(unionPayOrder);
|
||||
|
||||
if (!unionPayKit.verify(new NoticeParams(result))) {
|
||||
log.warn("云闪付支付验签失败:{}", result);
|
||||
throw new ValidationFailedException("云闪付支付验签失败");
|
||||
}
|
||||
|
||||
String resultCode = MapUtil.getStr(result, UnionPayCode.RESP_CODE);
|
||||
|
||||
// 支付失败
|
||||
if (!(Objects.equals(resultCode, UnionPayCode.RESP_SUCCESS))) {
|
||||
log.warn("云闪付支付失败:{}", result);
|
||||
String errMsg = MapUtil.getStr(result, UnionPayCode.RESP_MSG);
|
||||
throw new TradeFailException(errMsg);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
package org.dromara.daxpay.channel.union.service.reconcile;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 云闪付对账
|
||||
* @author xxm
|
||||
* @since 2024/3/7
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class UnionPayReconcileService {
|
||||
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
package org.dromara.daxpay.channel.union.service.refund;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.daxpay.channel.union.code.UnionPayCode;
|
||||
import org.dromara.daxpay.channel.union.sdk.api.UnionPayKit;
|
||||
import org.dromara.daxpay.channel.union.sdk.bean.UnionRefundOrder;
|
||||
import org.dromara.daxpay.channel.union.sdk.bean.UnionRefundResult;
|
||||
import org.dromara.daxpay.core.enums.RefundStatusEnum;
|
||||
import org.dromara.daxpay.service.bo.trade.RefundResultBo;
|
||||
import org.dromara.daxpay.service.entity.order.refund.RefundOrder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 云闪付退款操作
|
||||
* @author xxm
|
||||
* @since 2024/3/7
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class UnionPayRefundService {
|
||||
|
||||
/**
|
||||
* 退款方法
|
||||
*/
|
||||
public RefundResultBo refund(RefundOrder refundOrder, UnionPayKit unionPayKit) {
|
||||
|
||||
// 金额转换
|
||||
BigDecimal refundAmount = refundOrder.getAmount();
|
||||
BigDecimal orderAmount = refundOrder.getOrderAmount();
|
||||
|
||||
UnionRefundOrder unionRefundOrder = new UnionRefundOrder();
|
||||
unionRefundOrder.setRefundNo(refundOrder.getRefundNo());
|
||||
unionRefundOrder.setTradeNo(refundOrder.getOutOrderNo());
|
||||
unionRefundOrder.setRefundAmount(refundAmount);
|
||||
unionRefundOrder.setTotalAmount(orderAmount);
|
||||
UnionRefundResult refund = unionPayKit.refund(unionRefundOrder);
|
||||
|
||||
String outRefundNo = (String) refund.getAttr(UnionPayCode.QUERY_ID);
|
||||
// 云闪付退款是否成功需要查询状态, 所以设置为退款中状态
|
||||
return new RefundResultBo()
|
||||
.setStatus(RefundStatusEnum.PROGRESS)
|
||||
.setOutRefundNo(outRefundNo);
|
||||
}
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
package org.dromara.daxpay.channel.union.service.sync;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 云闪付支付同步
|
||||
* @author xxm
|
||||
* @since 2024/3/7
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class UnionPaySyncService {
|
||||
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
package org.dromara.daxpay.channel.union.strategy;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.daxpay.core.enums.ChannelEnum;
|
||||
import org.dromara.daxpay.service.bo.reconcile.ReconcileResolveResultBo;
|
||||
import org.dromara.daxpay.service.enums.ReconcileFileTypeEnum;
|
||||
import org.dromara.daxpay.service.strategy.AbsReconcileStrategy;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;
|
||||
|
||||
/**
|
||||
* 银联对账
|
||||
* @author xxm
|
||||
* @since 2024/3/8
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@Scope(SCOPE_PROTOTYPE)
|
||||
@RequiredArgsConstructor
|
||||
public class UnionPayReconcileStrategy extends AbsReconcileStrategy {
|
||||
|
||||
@Override
|
||||
public ReconcileResolveResultBo uploadAndResolve(MultipartFile file, ReconcileFileTypeEnum fileType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReconcileResolveResultBo downAndResolve() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getChannel() {
|
||||
return ChannelEnum.UNION_PAY.getCode();
|
||||
}
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
package org.dromara.daxpay.channel.union.strategy;
|
||||
|
||||
import cn.bootx.platform.core.exception.ValidationFailedException;
|
||||
import cn.bootx.platform.core.util.JsonUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONException;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.daxpay.channel.union.entity.config.UnionPayConfig;
|
||||
import org.dromara.daxpay.channel.union.param.pay.UnionPayParam;
|
||||
import org.dromara.daxpay.channel.union.sdk.api.UnionPayKit;
|
||||
import org.dromara.daxpay.channel.union.service.config.UnionPayConfigService;
|
||||
import org.dromara.daxpay.channel.union.service.pay.UnionPayService;
|
||||
import org.dromara.daxpay.core.enums.ChannelEnum;
|
||||
import org.dromara.daxpay.service.bo.trade.PayResultBo;
|
||||
import org.dromara.daxpay.service.strategy.AbsPayStrategy;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;
|
||||
|
||||
/**
|
||||
* 云闪付
|
||||
*
|
||||
* @author xxm
|
||||
* @since 2022/3/8
|
||||
*/
|
||||
@Slf4j
|
||||
@Scope(SCOPE_PROTOTYPE)
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class UnionPayStrategy extends AbsPayStrategy {
|
||||
|
||||
private final UnionPayService unionPayService;
|
||||
|
||||
private final UnionPayConfigService unionPayConfigService;
|
||||
|
||||
private UnionPayParam unionPayParam;
|
||||
|
||||
private UnionPayConfig unionPayConfig;
|
||||
|
||||
@Override
|
||||
public String getChannel() {
|
||||
return ChannelEnum.UNION_PAY.getCode();
|
||||
}
|
||||
/**
|
||||
* 支付前操作
|
||||
*/
|
||||
@Override
|
||||
public void doBeforePayHandler() {
|
||||
try {
|
||||
// 云闪付参数验证
|
||||
var channelParam = this.getPayParam().getExtraParam();
|
||||
if (StrUtil.isNotBlank(channelParam)) {
|
||||
this.unionPayParam = JsonUtil.toBean(channelParam, UnionPayParam.class);
|
||||
}
|
||||
else {
|
||||
this.unionPayParam = new UnionPayParam();
|
||||
}
|
||||
}
|
||||
catch (JSONException e) {
|
||||
throw new ValidationFailedException("支付参数错误");
|
||||
}
|
||||
// 检查并获取云闪付支付配置
|
||||
this.unionPayConfig = unionPayConfigService.getAndCheckConfig();
|
||||
unionPayService.validation(this.getPayParam(), unionPayConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起支付操作
|
||||
*/
|
||||
@Override
|
||||
public PayResultBo doPayHandler() {
|
||||
UnionPayKit unionPayKit = unionPayConfigService.initPayService(unionPayConfig);
|
||||
return unionPayService.pay(this.getOrder(), this.unionPayParam, unionPayKit);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,59 @@
|
||||
package org.dromara.daxpay.channel.union.strategy;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.daxpay.channel.union.entity.config.UnionPayConfig;
|
||||
import org.dromara.daxpay.channel.union.sdk.api.UnionPayKit;
|
||||
import org.dromara.daxpay.channel.union.service.config.UnionPayConfigService;
|
||||
import org.dromara.daxpay.channel.union.service.refund.UnionPayRefundService;
|
||||
import org.dromara.daxpay.core.enums.ChannelEnum;
|
||||
import org.dromara.daxpay.service.bo.trade.RefundResultBo;
|
||||
import org.dromara.daxpay.service.strategy.AbsRefundStrategy;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;
|
||||
|
||||
/**
|
||||
* 云闪付支付退款
|
||||
* @author xxm
|
||||
* @since 2023/7/5
|
||||
*/
|
||||
@Scope(SCOPE_PROTOTYPE)
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class UnionRefundStrategy extends AbsRefundStrategy {
|
||||
|
||||
private final UnionPayRefundService unionPayRefundService;
|
||||
|
||||
private final UnionPayConfigService unionPayConfigService;
|
||||
|
||||
private UnionPayConfig unionPayConfig;
|
||||
|
||||
/**
|
||||
* 策略标识
|
||||
*
|
||||
* @see ChannelEnum
|
||||
*/
|
||||
@Override
|
||||
public String getChannel() {
|
||||
return ChannelEnum.UNION_PAY.getCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款前对处理, 初始化微信支付配置
|
||||
*/
|
||||
@Override
|
||||
public void doBeforeRefundHandler() {
|
||||
this.unionPayConfig = unionPayConfigService.getAndCheckConfig();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 退款操作
|
||||
*/
|
||||
@Override
|
||||
public RefundResultBo doRefundHandler() {
|
||||
UnionPayKit unionPayKit = unionPayConfigService.initPayService(unionPayConfig);
|
||||
return unionPayRefundService.refund(this.getRefundOrder(), unionPayKit);
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package org.dromara.daxpay.channel.union.strategy;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.daxpay.core.enums.ChannelEnum;
|
||||
import org.dromara.daxpay.service.bo.sync.PaySyncResultBo;
|
||||
import org.dromara.daxpay.service.strategy.AbsSyncPayOrderStrategy;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;
|
||||
|
||||
/**
|
||||
* 云闪付支付同步接口
|
||||
* @author xxm
|
||||
* @since 2024/3/7
|
||||
*/
|
||||
@Scope(SCOPE_PROTOTYPE)
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class UnionSyncPayStrategy extends AbsSyncPayOrderStrategy {
|
||||
|
||||
@Override
|
||||
public PaySyncResultBo doSync() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getChannel() {
|
||||
return ChannelEnum.UNION_PAY.getCode();
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
package org.dromara.daxpay.channel.union.strategy;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.daxpay.core.enums.ChannelEnum;
|
||||
import org.dromara.daxpay.service.bo.sync.RefundSyncResultBo;
|
||||
import org.dromara.daxpay.service.strategy.AbsSyncRefundOrderStrategy;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;
|
||||
|
||||
/**
|
||||
* 云闪付退款同步
|
||||
* @author xxm
|
||||
* @since 2024/3/11
|
||||
*/
|
||||
@Scope(SCOPE_PROTOTYPE)
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class UnionSyncRefundStrategy extends AbsSyncRefundOrderStrategy {
|
||||
@Override
|
||||
public RefundSyncResultBo doSync() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getChannel() {
|
||||
return ChannelEnum.UNION_PAY.getCode();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user