mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
完善 AbstractPayClient 的实现
This commit is contained in:
parent
6690b9b120
commit
23d8da7479
@ -1,6 +1,6 @@
|
|||||||
package cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant;
|
package cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant;
|
||||||
|
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.enums.merchant.PayChannelCodeEnum;
|
import cn.iocoder.yudao.framework.sms.core.enums.PayChannelCodeEnum;
|
||||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
@ -3,7 +3,7 @@ package cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.order;
|
|||||||
import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayAppDO;
|
import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayAppDO;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayChannelDO;
|
import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayChannelDO;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayMerchantDO;
|
import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayMerchantDO;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.enums.merchant.PayChannelCodeEnum;
|
import cn.iocoder.yudao.framework.sms.core.enums.PayChannelCodeEnum;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.enums.order.PayOrderStatusEnum;
|
import cn.iocoder.yudao.coreservice.modules.pay.enums.order.PayOrderStatusEnum;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
@ -3,7 +3,7 @@ package cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.order;
|
|||||||
import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayAppDO;
|
import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayAppDO;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayChannelDO;
|
import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayChannelDO;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayMerchantDO;
|
import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayMerchantDO;
|
||||||
import cn.iocoder.yudao.coreservice.modules.pay.enums.merchant.PayChannelCodeEnum;
|
import cn.iocoder.yudao.framework.sms.core.enums.PayChannelCodeEnum;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package cn.iocoder.yudao.coreservice.modules.pay.enums.merchant;
|
package cn.iocoder.yudao.framework.sms.core.enums;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
@ -29,6 +29,11 @@
|
|||||||
<artifactId>hibernate-validator</artifactId>
|
<artifactId>hibernate-validator</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- 三方云服务相关 -->
|
<!-- 三方云服务相关 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.javen205</groupId>
|
<groupId>com.github.javen205</groupId>
|
||||||
|
@ -10,6 +10,13 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.PayOrderUnifiedReqDTO;
|
|||||||
*/
|
*/
|
||||||
public interface PayClient {
|
public interface PayClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得渠道编号
|
||||||
|
*
|
||||||
|
* @return 渠道编号
|
||||||
|
*/
|
||||||
|
Long getId();
|
||||||
|
|
||||||
// TODO 缺少注释
|
// TODO 缺少注释
|
||||||
CommonResult<Object> unifiedOrder(PayOrderUnifiedReqDTO reqDTO);
|
CommonResult<Object> unifiedOrder(PayOrderUnifiedReqDTO reqDTO);
|
||||||
|
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
package cn.iocoder.yudao.framework.pay.core.client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付客户端的工厂接口
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
public interface PayClientFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得支付客户端
|
||||||
|
*
|
||||||
|
* @param channelId 渠道编号
|
||||||
|
* @return 支付客户端
|
||||||
|
*/
|
||||||
|
PayClient getPayClient(Long channelId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建支付客户端
|
||||||
|
*
|
||||||
|
* @param channelId 渠道编号
|
||||||
|
* @param channelCode 渠道编码
|
||||||
|
* @param config 支付配置
|
||||||
|
*/
|
||||||
|
void createOrUpdatePayClient(Long channelId, String channelCode, PayClientConfig config);
|
||||||
|
|
||||||
|
}
|
@ -1,22 +1,73 @@
|
|||||||
package cn.iocoder.yudao.framework.pay.core.client.impl;
|
package cn.iocoder.yudao.framework.pay.core.client.impl;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.pay.core.client.PayClient;
|
import cn.iocoder.yudao.framework.pay.core.client.PayClient;
|
||||||
|
import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig;
|
||||||
import cn.iocoder.yudao.framework.pay.core.client.PayCodeMapping;
|
import cn.iocoder.yudao.framework.pay.core.client.PayCodeMapping;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付客户端的抽象类,提供模板方法,减少子类的冗余代码
|
* 支付客户端的抽象类,提供模板方法,减少子类的冗余代码
|
||||||
*
|
*
|
||||||
* @author 芋道源码
|
* @author 芋道源码
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractPayClient implements PayClient {
|
@Slf4j
|
||||||
|
public abstract class AbstractPayClient<Config extends PayClientConfig> implements PayClient {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渠道编号
|
||||||
|
*/
|
||||||
|
private final Long channelId;
|
||||||
|
/**
|
||||||
|
* 渠道编码
|
||||||
|
*/
|
||||||
|
private final String channelCode;
|
||||||
/**
|
/**
|
||||||
* 错误码枚举类
|
* 错误码枚举类
|
||||||
*/
|
*/
|
||||||
protected PayCodeMapping codeMapping;
|
protected PayCodeMapping codeMapping;
|
||||||
|
/**
|
||||||
|
* 支付配置
|
||||||
|
*/
|
||||||
|
protected Config config;
|
||||||
|
|
||||||
protected Double calculateAmount(Integer amount) {
|
protected Double calculateAmount(Integer amount) {
|
||||||
return amount / 100.0;
|
return amount / 100.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AbstractPayClient(Long channelId, String channelCode, Config config, PayCodeMapping codeMapping) {
|
||||||
|
this.channelId = channelId;
|
||||||
|
this.channelCode = channelCode;
|
||||||
|
this.codeMapping = codeMapping;
|
||||||
|
this.config = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化
|
||||||
|
*/
|
||||||
|
public final void init() {
|
||||||
|
doInit();
|
||||||
|
log.info("[init][配置({}) 初始化完成]", config);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义初始化
|
||||||
|
*/
|
||||||
|
protected abstract void doInit();
|
||||||
|
|
||||||
|
public final void refresh(Config config) {
|
||||||
|
// 判断是否更新
|
||||||
|
if (config.equals(this.config)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log.info("[refresh][配置({})发生变化,重新初始化]", config);
|
||||||
|
this.config = config;
|
||||||
|
// 初始化
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long getId() {
|
||||||
|
return channelId;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
package cn.iocoder.yudao.framework.pay.core.client.impl;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.pay.core.client.PayClient;
|
||||||
|
import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig;
|
||||||
|
import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory;
|
||||||
|
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付客户端的工厂实现类
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
public class PayClientFactoryImpl implements PayClientFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付客户端 Map
|
||||||
|
* key:渠道编号
|
||||||
|
*/
|
||||||
|
private final ConcurrentMap<Long, AbstractPayClient> channelIdClients = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PayClient getPayClient(Long channelId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createOrUpdatePayClient(Long channelId, String channelCode, PayClientConfig config) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package cn.iocoder.yudao.framework.pay.core.client.impl.alipay;
|
package cn.iocoder.yudao.framework.pay.core.client.impl.alipay;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
// TODO 芋艿:参数校验
|
// TODO 芋艿:参数校验
|
||||||
@ -10,7 +11,7 @@ import lombok.Data;
|
|||||||
* @author 芋道源码
|
* @author 芋道源码
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class AlipayPayConfig {
|
public class AlipayPayConfig implements PayClientConfig {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 网关地址 - 线上
|
* 网关地址 - 线上
|
||||||
|
@ -3,8 +3,8 @@ package cn.iocoder.yudao.framework.pay.core.client.impl.alipay;
|
|||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
import cn.iocoder.yudao.framework.pay.core.client.PayCommonResult;
|
import cn.iocoder.yudao.framework.pay.core.client.PayCommonResult;
|
||||||
import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient;
|
|
||||||
import cn.iocoder.yudao.framework.pay.core.client.dto.PayOrderUnifiedReqDTO;
|
import cn.iocoder.yudao.framework.pay.core.client.dto.PayOrderUnifiedReqDTO;
|
||||||
|
import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient;
|
||||||
import com.alipay.api.AlipayApiException;
|
import com.alipay.api.AlipayApiException;
|
||||||
import com.alipay.api.AlipayConfig;
|
import com.alipay.api.AlipayConfig;
|
||||||
import com.alipay.api.DefaultAlipayClient;
|
import com.alipay.api.DefaultAlipayClient;
|
||||||
@ -14,24 +14,27 @@ import com.alipay.api.response.AlipayTradePrecreateResponse;
|
|||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付宝的 PayClient 实现类
|
* 支付宝【扫码支付】的 PayClient 实现类
|
||||||
|
* 文档:https://opendocs.alipay.com/apis/02890k
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
*/
|
*/
|
||||||
public class AlipayPayClient extends AbstractPayClient {
|
public class AlipayQrPayClient extends AbstractPayClient<AlipayPayConfig> {
|
||||||
|
|
||||||
private final DefaultAlipayClient client;
|
private DefaultAlipayClient client;
|
||||||
|
|
||||||
|
public AlipayQrPayClient(Long channelId, String channelCode, AlipayPayConfig config) {
|
||||||
|
super(channelId, channelCode, config, new AlipayPayCodeMapping());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public AlipayPayClient(AlipayPayConfig config) {
|
protected void doInit() {
|
||||||
// 创建 DefaultAlipayClient 对象
|
|
||||||
AlipayConfig alipayConfig = new AlipayConfig();
|
AlipayConfig alipayConfig = new AlipayConfig();
|
||||||
BeanUtil.copyProperties(config, alipayConfig, false);
|
BeanUtil.copyProperties(config, alipayConfig, false);
|
||||||
this.client = new DefaultAlipayClient(alipayConfig);
|
this.client = new DefaultAlipayClient(alipayConfig);
|
||||||
|
|
||||||
// 创建 AlipayPayCodeMapping 对象
|
|
||||||
super.codeMapping = new AlipayPayCodeMapping();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO 芋艿:暂时是扫码支付,需要调整成 wap https://opendocs.alipay.com/apis/api_1/alipay.trade.wap.pay
|
|
||||||
@Override
|
@Override
|
||||||
public CommonResult<Object> unifiedOrder(PayOrderUnifiedReqDTO reqDTO) {
|
public CommonResult<Object> unifiedOrder(PayOrderUnifiedReqDTO reqDTO) {
|
||||||
// 构建 AlipayTradePrecreateModel 请求
|
// 构建 AlipayTradePrecreateModel 请求
|
||||||
@ -46,7 +49,7 @@ public class AlipayPayClient extends AbstractPayClient {
|
|||||||
request.setBizModel(model);
|
request.setBizModel(model);
|
||||||
|
|
||||||
// 执行请求
|
// 执行请求
|
||||||
AlipayTradePrecreateResponse response = null;
|
AlipayTradePrecreateResponse response;
|
||||||
try {
|
try {
|
||||||
response = client.execute(request);
|
response = client.execute(request);
|
||||||
} catch (AlipayApiException e) {
|
} catch (AlipayApiException e) {
|
||||||
@ -67,7 +70,8 @@ public class AlipayPayClient extends AbstractPayClient {
|
|||||||
config.setSignType(AlipayPayConfig.SIGN_TYPE_DEFAULT);
|
config.setSignType(AlipayPayConfig.SIGN_TYPE_DEFAULT);
|
||||||
config.setPrivateKey("MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCHsEV1cDupwJv890x84qbppUtRIfhaKSwSVN0thCcsDCaAsGR5MZslDkO8NCT9V4r2SVXjyY7eJUZlZd1M0C8T01Tg4UOx5LUbic0O3A1uJMy6V1n9IyYwbAW3AEZhBd5bSbPgrqvmv3NeWSTQT6Anxnllf+2iDH6zyA2fPl7cYyQtbZoDJQFGqr4F+cGh2R6akzRKNoBkAeMYwoY6es2lX8sJxCVPWUmxNUoL3tScwlSpd7Bxw0q9c/X01jMwuQ0+Va358zgFiGERTE6yD01eu40OBDXOYO3z++y+TAYHlQQ2toMO63trepo88X3xV3R44/1DH+k2pAm2IF5ixiLrAgMBAAECggEAPx3SoXcseaD7rmcGcE0p4SMfbsUDdkUSmBBbtfF0GzwnqNLkWa+mgE0rWt9SmXngTQH97vByAYmLPl1s3G82ht1V7Sk7yQMe74lhFllr8eEyTjeVx3dTK1EEM4TwN+936DTXdFsr4TELJEcJJdD0KaxcCcfBLRDs2wnitEFZ9N+GoZybVmY8w0e0MI7PLObUZ2l0X4RurQnfG9ZxjXjC7PkeMVv7cGGylpNFi3BbvkRhdhLPDC2E6wqnr9e7zk+hiENivAezXrtxtwKovzCtnWJ1r0IO14Rh47H509Ic0wFnj+o5YyUL4LdmpL7yaaH6fM7zcSLFjNZPHvZCKPwYcQKBgQDQFho98QvnL8ex4v6cry4VitGpjSXm1qP3vmMQk4rTsn8iPWtcxPjqGEqOQJjdi4Mi0VZKQOLFwlH0kl95wNrD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5r8HSuseQIDAQAB");
|
||||||
AlipayPayClient client = new AlipayPayClient(config);
|
AlipayQrPayClient client = new AlipayQrPayClient(1L, "biu", config);
|
||||||
|
client.init();
|
||||||
|
|
||||||
PayOrderUnifiedReqDTO reqDTO = new PayOrderUnifiedReqDTO();
|
PayOrderUnifiedReqDTO reqDTO = new PayOrderUnifiedReqDTO();
|
||||||
reqDTO.setAmount(123);
|
reqDTO.setAmount(123);
|
||||||
@ -75,5 +79,4 @@ public class AlipayPayClient extends AbstractPayClient {
|
|||||||
reqDTO.setMerchantOrderId(String.valueOf(System.currentTimeMillis()));
|
reqDTO.setMerchantOrderId(String.valueOf(System.currentTimeMillis()));
|
||||||
client.unifiedOrder(reqDTO);
|
client.unifiedOrder(reqDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,85 @@
|
|||||||
|
package cn.iocoder.yudao.framework.pay.core.client.impl.alipay;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
|
import cn.iocoder.yudao.framework.pay.core.client.PayCommonResult;
|
||||||
|
import cn.iocoder.yudao.framework.pay.core.client.dto.PayOrderUnifiedReqDTO;
|
||||||
|
import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient;
|
||||||
|
import com.alipay.api.AlipayApiException;
|
||||||
|
import com.alipay.api.AlipayConfig;
|
||||||
|
import com.alipay.api.DefaultAlipayClient;
|
||||||
|
import com.alipay.api.domain.AlipayTradeWapPayModel;
|
||||||
|
import com.alipay.api.request.AlipayTradeWapPayRequest;
|
||||||
|
import com.alipay.api.response.AlipayTradeWapPayResponse;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付宝【手机网站】的 PayClient 实现类
|
||||||
|
* 文档:https://opendocs.alipay.com/apis/api_1/alipay.trade.wap.pay
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
public class AlipayWapPayClient extends AbstractPayClient<AlipayPayConfig> {
|
||||||
|
|
||||||
|
private DefaultAlipayClient client;
|
||||||
|
|
||||||
|
public AlipayWapPayClient(Long channelId, String channelCode, AlipayPayConfig config) {
|
||||||
|
super(channelId, channelCode, config, new AlipayPayCodeMapping());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SneakyThrows
|
||||||
|
protected void doInit() {
|
||||||
|
AlipayConfig alipayConfig = new AlipayConfig();
|
||||||
|
BeanUtil.copyProperties(config, alipayConfig, false);
|
||||||
|
this.client = new DefaultAlipayClient(alipayConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommonResult<Object> unifiedOrder(PayOrderUnifiedReqDTO reqDTO) {
|
||||||
|
// 构建 AlipayTradeWapPayModel 请求
|
||||||
|
AlipayTradeWapPayModel model = new AlipayTradeWapPayModel();
|
||||||
|
model.setOutTradeNo(reqDTO.getMerchantOrderId());
|
||||||
|
model.setSubject(reqDTO.getSubject());
|
||||||
|
model.setBody(reqDTO.getBody());
|
||||||
|
model.setTotalAmount(calculateAmount(reqDTO.getAmount()).toString());
|
||||||
|
model.setProductCode("QUICK_WAP_PAY"); // TODO 芋艿:这里咋整
|
||||||
|
model.setSellerId("2088102147948060"); // TODO 芋艿:这里咋整
|
||||||
|
// TODO 芋艿:clientIp + expireTime
|
||||||
|
// 构建 AlipayTradeWapPayRequest
|
||||||
|
AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
|
||||||
|
request.setBizModel(model);
|
||||||
|
|
||||||
|
// 执行请求
|
||||||
|
AlipayTradeWapPayResponse response;
|
||||||
|
try {
|
||||||
|
response = client.pageExecute(request);
|
||||||
|
} catch (AlipayApiException e) {
|
||||||
|
return PayCommonResult.build(e.getErrCode(), e.getErrMsg(), null, codeMapping);
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(response.getBody());
|
||||||
|
|
||||||
|
// TODO 芋艿:sub Code
|
||||||
|
return PayCommonResult.build(response.getCode(), response.getMsg(), response, codeMapping);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
AlipayPayConfig config = new AlipayPayConfig();
|
||||||
|
config.setAppId("2021000118634035");
|
||||||
|
config.setServerUrl(AlipayPayConfig.SERVER_URL_SANDBOX);
|
||||||
|
config.setSignType(AlipayPayConfig.SIGN_TYPE_DEFAULT);
|
||||||
|
config.setPrivateKey("MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCHsEV1cDupwJv890x84qbppUtRIfhaKSwSVN0thCcsDCaAsGR5MZslDkO8NCT9V4r2SVXjyY7eJUZlZd1M0C8T01Tg4UOx5LUbic0O3A1uJMy6V1n9IyYwbAW3AEZhBd5bSbPgrqvmv3NeWSTQT6Anxnllf+2iDH6zyA2fPl7cYyQtbZoDJQFGqr4F+cGh2R6akzRKNoBkAeMYwoY6es2lX8sJxCVPWUmxNUoL3tScwlSpd7Bxw0q9c/X01jMwuQ0+Va358zgFiGERTE6yD01eu40OBDXOYO3z++y+TAYHlQQ2toMO63trepo88X3xV3R44/1DH+k2pAm2IF5ixiLrAgMBAAECggEAPx3SoXcseaD7rmcGcE0p4SMfbsUDdkUSmBBbtfF0GzwnqNLkWa+mgE0rWt9SmXngTQH97vByAYmLPl1s3G82ht1V7Sk7yQMe74lhFllr8eEyTjeVx3dTK1EEM4TwN+936DTXdFsr4TELJEcJJdD0KaxcCcfBLRDs2wnitEFZ9N+GoZybVmY8w0e0MI7PLObUZ2l0X4RurQnfG9ZxjXjC7PkeMVv7cGGylpNFi3BbvkRhdhLPDC2E6wqnr9e7zk+hiENivAezXrtxtwKovzCtnWJ1r0IO14Rh47H509Ic0wFnj+o5YyUL4LdmpL7yaaH6fM7zcSLFjNZPHvZCKPwYcQKBgQDQFho98QvnL8ex4v6cry4VitGpjSXm1qP3vmMQk4rTsn8iPWtcxPjqGEqOQJjdi4Mi0VZKQOLFwlH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3eXSjP8K54eDJCbeetCZNKWLL3DPahTPB7LZikfYmslb0QUvCgGapD0xkS7eVq70NaL1G57MWABs4tbfWgxike4Daj3EfUrzIVspQxj7w8HEj9WozJPgL88kSJSits0pqD3n5r8HSuseQIDAQAB");
|
||||||
|
AlipayWapPayClient client = new AlipayWapPayClient(1L, "biubiubiu", config);
|
||||||
|
client.init();
|
||||||
|
|
||||||
|
PayOrderUnifiedReqDTO reqDTO = new PayOrderUnifiedReqDTO();
|
||||||
|
reqDTO.setAmount(123);
|
||||||
|
reqDTO.setSubject("IPhone 13");
|
||||||
|
reqDTO.setMerchantOrderId(String.valueOf(System.currentTimeMillis()));
|
||||||
|
client.unifiedOrder(reqDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
<form name="punchout_form" method="post" action="https://openapi.alipaydev.com/gateway.do?charset=UTF8&sign=IxJaAZYjlzTHeogqr2dXsHPhHtjawFe7nTHq8Qbu3JvxWGEcvbVLJiO17LHfR4F45dVGnw74gEUnjQGHm%2FQanmANCIpUnrFTY7yXZmWRJQSRgNdLj3xA%2BaGm2RAprwZEj3wy3P2BAXfzTkgqclxo9BLLgMT%2FUiMQbRXUSRBFV5F5OC222oPOUzGNRM88jJwbMdWIuhpusbwya5BPPZUl%2BDdnipBLUlv3iX6yLxFWmxM%2FSzhrKURmThvBNw5FMwuUWPgfBYPb5Z%2FaJL68g8koGByxaJ%2FZmQcT66XFXJXfxmEUNNZKqeanvFca5M4auBqa7%2BOcoSOMA%2FHnsJOCJRAJ3g%3D%3D&app_id=2021000118634035&sign_type=RSA2×tamp=2021-10-20+08%3A44%3A51&alipay_sdk=alipay-sdk-java-dynamicVersionNo&format=json"> <input type="hidden" name="biz_content" value="{"out_trade_no":"70501111111S001111119","total_amount":"9.00","quit_url":"http://www.taobao.com/product/113714.html","subject":"大乐透","product_code":"QUICK_WAP_PAY","seller_id":"2088102147948060"}"> <input type="submit" value="立即支付" style="display:none" > </form> <script>document.forms[0].submit();</script>
|
@ -3,7 +3,7 @@ package cn.iocoder.yudao.framework.sms.core.client;
|
|||||||
import cn.iocoder.yudao.framework.sms.core.property.SmsChannelProperties;
|
import cn.iocoder.yudao.framework.sms.core.property.SmsChannelProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 短信客户端工厂接口
|
* 短信客户端的工厂接口
|
||||||
*
|
*
|
||||||
* @author zzf
|
* @author zzf
|
||||||
* @date 2021/1/28 14:01
|
* @date 2021/1/28 14:01
|
||||||
|
@ -30,11 +30,6 @@ public abstract class AbstractSmsClient implements SmsClient {
|
|||||||
*/
|
*/
|
||||||
protected final SmsCodeMapping codeMapping;
|
protected final SmsCodeMapping codeMapping;
|
||||||
|
|
||||||
/**
|
|
||||||
* 短信客户端有参构造函数
|
|
||||||
*
|
|
||||||
* @param properties 短信配置
|
|
||||||
*/
|
|
||||||
public AbstractSmsClient(SmsChannelProperties properties, SmsCodeMapping codeMapping) {
|
public AbstractSmsClient(SmsChannelProperties properties, SmsCodeMapping codeMapping) {
|
||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
this.codeMapping = codeMapping;
|
this.codeMapping = codeMapping;
|
||||||
@ -48,6 +43,11 @@ public abstract class AbstractSmsClient implements SmsClient {
|
|||||||
log.info("[init][配置({}) 初始化完成]", properties);
|
log.info("[init][配置({}) 初始化完成]", properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义初始化
|
||||||
|
*/
|
||||||
|
protected abstract void doInit();
|
||||||
|
|
||||||
public final void refresh(SmsChannelProperties properties) {
|
public final void refresh(SmsChannelProperties properties) {
|
||||||
// 判断是否更新
|
// 判断是否更新
|
||||||
if (properties.equals(this.properties)) {
|
if (properties.equals(this.properties)) {
|
||||||
@ -59,11 +59,6 @@ public abstract class AbstractSmsClient implements SmsClient {
|
|||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 自定义初始化
|
|
||||||
*/
|
|
||||||
protected abstract void doInit();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return properties.getId();
|
return properties.getId();
|
||||||
|
Loading…
Reference in New Issue
Block a user