Commit 23d8da74791f134b887a5590a9b439481b082e39
1 parent
6690b9b1
完善 AbstractPayClient 的实现
Showing
15 changed files
with
238 additions
and
30 deletions
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/dal/dataobject/merchant/PayChannelDO.java
| 1 | 1 | package cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.coreservice.modules.pay.enums.merchant.PayChannelCodeEnum; | |
| 3 | +import cn.iocoder.yudao.framework.sms.core.enums.PayChannelCodeEnum; | |
| 4 | 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | 5 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 6 | 6 | import lombok.Data; | ... | ... |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/dal/dataobject/order/PayOrderDO.java
| ... | ... | @@ -3,7 +3,7 @@ package cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.order; |
| 3 | 3 | import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayAppDO; |
| 4 | 4 | import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayChannelDO; |
| 5 | 5 | import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayMerchantDO; |
| 6 | -import cn.iocoder.yudao.coreservice.modules.pay.enums.merchant.PayChannelCodeEnum; | |
| 6 | +import cn.iocoder.yudao.framework.sms.core.enums.PayChannelCodeEnum; | |
| 7 | 7 | import cn.iocoder.yudao.coreservice.modules.pay.enums.order.PayOrderStatusEnum; |
| 8 | 8 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 9 | 9 | import com.baomidou.mybatisplus.annotation.TableName; | ... | ... |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/dal/dataobject/order/PayRefundDO.java
| ... | ... | @@ -3,7 +3,7 @@ package cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.order; |
| 3 | 3 | import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayAppDO; |
| 4 | 4 | import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayChannelDO; |
| 5 | 5 | import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayMerchantDO; |
| 6 | -import cn.iocoder.yudao.coreservice.modules.pay.enums.merchant.PayChannelCodeEnum; | |
| 6 | +import cn.iocoder.yudao.framework.sms.core.enums.PayChannelCodeEnum; | |
| 7 | 7 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 8 | 8 | import lombok.Data; |
| 9 | 9 | ... | ... |
yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/pay/enums/merchant/PayChannelCodeEnum.java renamed to yudao-core-service/src/main/java/cn/iocoder/yudao/framework/sms/core/enums/PayChannelCodeEnum.java
yudao-framework/yudao-spring-boot-starter-biz-pay/pom.xml
| ... | ... | @@ -29,6 +29,11 @@ |
| 29 | 29 | <artifactId>hibernate-validator</artifactId> |
| 30 | 30 | </dependency> |
| 31 | 31 | |
| 32 | + <dependency> | |
| 33 | + <groupId>org.slf4j</groupId> | |
| 34 | + <artifactId>slf4j-api</artifactId> | |
| 35 | + </dependency> | |
| 36 | + | |
| 32 | 37 | <!-- 三方云服务相关 --> |
| 33 | 38 | <dependency> |
| 34 | 39 | <groupId>com.github.javen205</groupId> | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/PayClient.java
| ... | ... | @@ -10,6 +10,13 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.PayOrderUnifiedReqDTO; |
| 10 | 10 | */ |
| 11 | 11 | public interface PayClient { |
| 12 | 12 | |
| 13 | + /** | |
| 14 | + * 获得渠道编号 | |
| 15 | + * | |
| 16 | + * @return 渠道编号 | |
| 17 | + */ | |
| 18 | + Long getId(); | |
| 19 | + | |
| 13 | 20 | // TODO 缺少注释 |
| 14 | 21 | CommonResult<Object> unifiedOrder(PayOrderUnifiedReqDTO reqDTO); |
| 15 | 22 | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/PayClientFactory.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.pay.core.client; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * 支付客户端的工厂接口 | |
| 5 | + * | |
| 6 | + * @author 芋道源码 | |
| 7 | + */ | |
| 8 | +public interface PayClientFactory { | |
| 9 | + | |
| 10 | + /** | |
| 11 | + * 获得支付客户端 | |
| 12 | + * | |
| 13 | + * @param channelId 渠道编号 | |
| 14 | + * @return 支付客户端 | |
| 15 | + */ | |
| 16 | + PayClient getPayClient(Long channelId); | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * 创建支付客户端 | |
| 20 | + * | |
| 21 | + * @param channelId 渠道编号 | |
| 22 | + * @param channelCode 渠道编码 | |
| 23 | + * @param config 支付配置 | |
| 24 | + */ | |
| 25 | + void createOrUpdatePayClient(Long channelId, String channelCode, PayClientConfig config); | |
| 26 | + | |
| 27 | +} | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/AbstractPayClient.java
| 1 | 1 | package cn.iocoder.yudao.framework.pay.core.client.impl; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.pay.core.client.PayClient; |
| 4 | +import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig; | |
| 4 | 5 | import cn.iocoder.yudao.framework.pay.core.client.PayCodeMapping; |
| 6 | +import lombok.extern.slf4j.Slf4j; | |
| 5 | 7 | |
| 6 | 8 | /** |
| 7 | 9 | * 支付客户端的抽象类,提供模板方法,减少子类的冗余代码 |
| 8 | 10 | * |
| 9 | 11 | * @author 芋道源码 |
| 10 | 12 | */ |
| 11 | -public abstract class AbstractPayClient implements PayClient { | |
| 13 | +@Slf4j | |
| 14 | +public abstract class AbstractPayClient<Config extends PayClientConfig> implements PayClient { | |
| 12 | 15 | |
| 13 | 16 | /** |
| 17 | + * 渠道编号 | |
| 18 | + */ | |
| 19 | + private final Long channelId; | |
| 20 | + /** | |
| 21 | + * 渠道编码 | |
| 22 | + */ | |
| 23 | + private final String channelCode; | |
| 24 | + /** | |
| 14 | 25 | * 错误码枚举类 |
| 15 | 26 | */ |
| 16 | 27 | protected PayCodeMapping codeMapping; |
| 28 | + /** | |
| 29 | + * 支付配置 | |
| 30 | + */ | |
| 31 | + protected Config config; | |
| 17 | 32 | |
| 18 | 33 | protected Double calculateAmount(Integer amount) { |
| 19 | 34 | return amount / 100.0; |
| 20 | 35 | } |
| 21 | 36 | |
| 37 | + public AbstractPayClient(Long channelId, String channelCode, Config config, PayCodeMapping codeMapping) { | |
| 38 | + this.channelId = channelId; | |
| 39 | + this.channelCode = channelCode; | |
| 40 | + this.codeMapping = codeMapping; | |
| 41 | + this.config = config; | |
| 42 | + } | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * 初始化 | |
| 46 | + */ | |
| 47 | + public final void init() { | |
| 48 | + doInit(); | |
| 49 | + log.info("[init][配置({}) 初始化完成]", config); | |
| 50 | + } | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * 自定义初始化 | |
| 54 | + */ | |
| 55 | + protected abstract void doInit(); | |
| 56 | + | |
| 57 | + public final void refresh(Config config) { | |
| 58 | + // 判断是否更新 | |
| 59 | + if (config.equals(this.config)) { | |
| 60 | + return; | |
| 61 | + } | |
| 62 | + log.info("[refresh][配置({})发生变化,重新初始化]", config); | |
| 63 | + this.config = config; | |
| 64 | + // 初始化 | |
| 65 | + this.init(); | |
| 66 | + } | |
| 67 | + | |
| 68 | + @Override | |
| 69 | + public Long getId() { | |
| 70 | + return channelId; | |
| 71 | + } | |
| 72 | + | |
| 22 | 73 | } | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.pay.core.client.impl; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.pay.core.client.PayClient; | |
| 4 | +import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig; | |
| 5 | +import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory; | |
| 6 | + | |
| 7 | +import java.util.concurrent.ConcurrentHashMap; | |
| 8 | +import java.util.concurrent.ConcurrentMap; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 支付客户端的工厂实现类 | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +public class PayClientFactoryImpl implements PayClientFactory { | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * 支付客户端 Map | |
| 19 | + * key:渠道编号 | |
| 20 | + */ | |
| 21 | + private final ConcurrentMap<Long, AbstractPayClient> channelIdClients = new ConcurrentHashMap<>(); | |
| 22 | + | |
| 23 | + @Override | |
| 24 | + public PayClient getPayClient(Long channelId) { | |
| 25 | + return null; | |
| 26 | + } | |
| 27 | + | |
| 28 | + @Override | |
| 29 | + public void createOrUpdatePayClient(Long channelId, String channelCode, PayClientConfig config) { | |
| 30 | + | |
| 31 | + } | |
| 32 | + | |
| 33 | +} | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayPayConfig.java
| 1 | 1 | package cn.iocoder.yudao.framework.pay.core.client.impl.alipay; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig; | |
| 3 | 4 | import lombok.Data; |
| 4 | 5 | |
| 5 | 6 | // TODO 芋艿:参数校验 |
| ... | ... | @@ -10,7 +11,7 @@ import lombok.Data; |
| 10 | 11 | * @author 芋道源码 |
| 11 | 12 | */ |
| 12 | 13 | @Data |
| 13 | -public class AlipayPayConfig { | |
| 14 | +public class AlipayPayConfig implements PayClientConfig { | |
| 14 | 15 | |
| 15 | 16 | /** |
| 16 | 17 | * 网关地址 - 线上 | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayPayClient.java renamed to yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayQrPayClient.java
| ... | ... | @@ -3,8 +3,8 @@ package cn.iocoder.yudao.framework.pay.core.client.impl.alipay; |
| 3 | 3 | import cn.hutool.core.bean.BeanUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | 5 | import cn.iocoder.yudao.framework.pay.core.client.PayCommonResult; |
| 6 | -import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient; | |
| 7 | 6 | import cn.iocoder.yudao.framework.pay.core.client.dto.PayOrderUnifiedReqDTO; |
| 7 | +import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient; | |
| 8 | 8 | import com.alipay.api.AlipayApiException; |
| 9 | 9 | import com.alipay.api.AlipayConfig; |
| 10 | 10 | import com.alipay.api.DefaultAlipayClient; |
| ... | ... | @@ -14,24 +14,27 @@ import com.alipay.api.response.AlipayTradePrecreateResponse; |
| 14 | 14 | import lombok.SneakyThrows; |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | - * 支付宝的 PayClient 实现类 | |
| 17 | + * 支付宝【扫码支付】的 PayClient 实现类 | |
| 18 | + * 文档:https://opendocs.alipay.com/apis/02890k | |
| 19 | + * | |
| 20 | + * @author 芋道源码 | |
| 18 | 21 | */ |
| 19 | -public class AlipayPayClient extends AbstractPayClient { | |
| 22 | +public class AlipayQrPayClient extends AbstractPayClient<AlipayPayConfig> { | |
| 20 | 23 | |
| 21 | - private final DefaultAlipayClient client; | |
| 24 | + private DefaultAlipayClient client; | |
| 25 | + | |
| 26 | + public AlipayQrPayClient(Long channelId, String channelCode, AlipayPayConfig config) { | |
| 27 | + super(channelId, channelCode, config, new AlipayPayCodeMapping()); | |
| 28 | + } | |
| 22 | 29 | |
| 30 | + @Override | |
| 23 | 31 | @SneakyThrows |
| 24 | - public AlipayPayClient(AlipayPayConfig config) { | |
| 25 | - // 创建 DefaultAlipayClient 对象 | |
| 32 | + protected void doInit() { | |
| 26 | 33 | AlipayConfig alipayConfig = new AlipayConfig(); |
| 27 | 34 | BeanUtil.copyProperties(config, alipayConfig, false); |
| 28 | 35 | this.client = new DefaultAlipayClient(alipayConfig); |
| 29 | - | |
| 30 | - // 创建 AlipayPayCodeMapping 对象 | |
| 31 | - super.codeMapping = new AlipayPayCodeMapping(); | |
| 32 | 36 | } |
| 33 | 37 | |
| 34 | - // TODO 芋艿:暂时是扫码支付,需要调整成 wap https://opendocs.alipay.com/apis/api_1/alipay.trade.wap.pay | |
| 35 | 38 | @Override |
| 36 | 39 | public CommonResult<Object> unifiedOrder(PayOrderUnifiedReqDTO reqDTO) { |
| 37 | 40 | // 构建 AlipayTradePrecreateModel 请求 |
| ... | ... | @@ -46,7 +49,7 @@ public class AlipayPayClient extends AbstractPayClient { |
| 46 | 49 | request.setBizModel(model); |
| 47 | 50 | |
| 48 | 51 | // 执行请求 |
| 49 | - AlipayTradePrecreateResponse response = null; | |
| 52 | + AlipayTradePrecreateResponse response; | |
| 50 | 53 | try { |
| 51 | 54 | response = client.execute(request); |
| 52 | 55 | } catch (AlipayApiException e) { |
| ... | ... | @@ -67,7 +70,8 @@ public class AlipayPayClient extends AbstractPayClient { |
| 67 | 70 | config.setSignType(AlipayPayConfig.SIGN_TYPE_DEFAULT); |
| 68 | 71 | config.setPrivateKey("MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCHsEV1cDupwJv890x84qbppUtRIfhaKSwSVN0thCcsDCaAsGR5MZslDkO8NCT9V4r2SVXjyY7eJUZlZd1M0C8T01Tg4UOx5LUbic0O3A1uJMy6V1n9IyYwbAW3AEZhBd5bSbPgrqvmv3NeWSTQT6Anxnllf+2iDH6z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AdGgINvGwaJ8vQ0nm/8h8NOoFZ4oNoGc+wU5Ubops7dUM6FjPR5e+OjdJ4E7Xp7d5O4J1TaIZlCEbo5OpdhaTDDcQvrkFu+Z4eN0qzj+YAKjDAOOrXc4tbr5q0FsgXscwtcNfaBuzFVTUrUkCgYEAwzPnMNhWG3zOWLUs2QFA2GP4Y+J8cpUYfj6pbKKzeLwyG9qBwF1NJpN8m+q9q7V9P2LY+9Lp9e1mGsGeqt5HMEA3P6vIpcqLJLqE/4PBLLRzfccTcmqb1m71+erxTRhHBRkGS+I7dZEb3olQfnS1Y1tpMBxiwYwR3LW4oXuJwj8="); |
| 69 | 72 | config.setAlipayPublicKey("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnq90KnF4dTnlzzmxpujbI05OYqi5WxAS6cL0gnZFv2gK51HExF8v/BaP7P979PhFMgWTqmOOI+Dtno5s+yD09XTY1WkshbLk6i4g2Xlr8fyW9ODnkU88RI2w9UdPhQU4cPPwBNlrsYhKkVK2OxwM3kFqjoBBY0CZoZCsSQ3LDH5WeZqPArlsS6xa2zqJBuuoKjMrdpELl3eXSjP8K54eDJCbeetCZNKWLL3DPahTPB7LZikfYmslb0QUvCgGapD0xkS7eVq70NaL1G57MWABs4tbfWgxike4Daj3EfUrzIVspQxj7w8HEj9WozJPgL88kSJSits0pqD3n5r8HSuseQIDAQAB"); |
| 70 | - AlipayPayClient client = new AlipayPayClient(config); | |
| 73 | + AlipayQrPayClient client = new AlipayQrPayClient(1L, "biu", config); | |
| 74 | + client.init(); | |
| 71 | 75 | |
| 72 | 76 | PayOrderUnifiedReqDTO reqDTO = new PayOrderUnifiedReqDTO(); |
| 73 | 77 | reqDTO.setAmount(123); |
| ... | ... | @@ -75,5 +79,4 @@ public class AlipayPayClient extends AbstractPayClient { |
| 75 | 79 | reqDTO.setMerchantOrderId(String.valueOf(System.currentTimeMillis())); |
| 76 | 80 | client.unifiedOrder(reqDTO); |
| 77 | 81 | } |
| 78 | - | |
| 79 | 82 | } | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayWapPayClient.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.pay.core.client.impl.alipay; | |
| 2 | + | |
| 3 | +import cn.hutool.core.bean.BeanUtil; | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 5 | +import cn.iocoder.yudao.framework.pay.core.client.PayCommonResult; | |
| 6 | +import cn.iocoder.yudao.framework.pay.core.client.dto.PayOrderUnifiedReqDTO; | |
| 7 | +import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient; | |
| 8 | +import com.alipay.api.AlipayApiException; | |
| 9 | +import com.alipay.api.AlipayConfig; | |
| 10 | +import com.alipay.api.DefaultAlipayClient; | |
| 11 | +import com.alipay.api.domain.AlipayTradeWapPayModel; | |
| 12 | +import com.alipay.api.request.AlipayTradeWapPayRequest; | |
| 13 | +import com.alipay.api.response.AlipayTradeWapPayResponse; | |
| 14 | +import lombok.SneakyThrows; | |
| 15 | + | |
| 16 | +/** | |
| 17 | + * 支付宝【手机网站】的 PayClient 实现类 | |
| 18 | + * 文档:https://opendocs.alipay.com/apis/api_1/alipay.trade.wap.pay | |
| 19 | + * | |
| 20 | + * @author 芋道源码 | |
| 21 | + */ | |
| 22 | +public class AlipayWapPayClient extends AbstractPayClient<AlipayPayConfig> { | |
| 23 | + | |
| 24 | + private DefaultAlipayClient client; | |
| 25 | + | |
| 26 | + public AlipayWapPayClient(Long channelId, String channelCode, AlipayPayConfig config) { | |
| 27 | + super(channelId, channelCode, config, new AlipayPayCodeMapping()); | |
| 28 | + } | |
| 29 | + | |
| 30 | + @Override | |
| 31 | + @SneakyThrows | |
| 32 | + protected void doInit() { | |
| 33 | + AlipayConfig alipayConfig = new AlipayConfig(); | |
| 34 | + BeanUtil.copyProperties(config, alipayConfig, false); | |
| 35 | + this.client = new DefaultAlipayClient(alipayConfig); | |
| 36 | + } | |
| 37 | + | |
| 38 | + @Override | |
| 39 | + public CommonResult<Object> unifiedOrder(PayOrderUnifiedReqDTO reqDTO) { | |
| 40 | + // 构建 AlipayTradeWapPayModel 请求 | |
| 41 | + AlipayTradeWapPayModel model = new AlipayTradeWapPayModel(); | |
| 42 | + model.setOutTradeNo(reqDTO.getMerchantOrderId()); | |
| 43 | + model.setSubject(reqDTO.getSubject()); | |
| 44 | + model.setBody(reqDTO.getBody()); | |
| 45 | + model.setTotalAmount(calculateAmount(reqDTO.getAmount()).toString()); | |
| 46 | + model.setProductCode("QUICK_WAP_PAY"); // TODO 芋艿:这里咋整 | |
| 47 | + model.setSellerId("2088102147948060"); // TODO 芋艿:这里咋整 | |
| 48 | + // TODO 芋艿:clientIp + expireTime | |
| 49 | + // 构建 AlipayTradeWapPayRequest | |
| 50 | + AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); | |
| 51 | + request.setBizModel(model); | |
| 52 | + | |
| 53 | + // 执行请求 | |
| 54 | + AlipayTradeWapPayResponse response; | |
| 55 | + try { | |
| 56 | + response = client.pageExecute(request); | |
| 57 | + } catch (AlipayApiException e) { | |
| 58 | + return PayCommonResult.build(e.getErrCode(), e.getErrMsg(), null, codeMapping); | |
| 59 | + } | |
| 60 | + | |
| 61 | + System.out.println(response.getBody()); | |
| 62 | + | |
| 63 | +// TODO 芋艿:sub Code | |
| 64 | + return PayCommonResult.build(response.getCode(), response.getMsg(), response, codeMapping); | |
| 65 | + } | |
| 66 | + | |
| 67 | + public static void main(String[] args) { | |
| 68 | + AlipayPayConfig config = new AlipayPayConfig(); | |
| 69 | + config.setAppId("2021000118634035"); | |
| 70 | + config.setServerUrl(AlipayPayConfig.SERVER_URL_SANDBOX); | |
| 71 | + config.setSignType(AlipayPayConfig.SIGN_TYPE_DEFAULT); | |
| 72 | + config.setPrivateKey("MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCHsEV1cDupwJv890x84qbppUtR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YdtA3aVtpLiTwWu22OUUvZZqHDGruYOO4Hvdz23mL5b4ayqImCwoNU4bAZIc9v18p/UNf3/55NNE3oGcf/bev9rH2OjCQ4nM+Ktwhg8CFAoGACSgvbkShzUkv0ZcIf9ppu+ZnJh1AdGgINvGwaJ8vQ0nm/8h8NOoFZ4oNoGc+wU5Ubops7dUM6FjPR5e+OjdJ4E7Xp7d5O4J1TaIZlCEbo5OpdhaTDDcQvrkFu+Z4eN0qzj+YAKjDAOOrXc4tbr5q0FsgXscwtcNfaBuzFVTUrUkCgYEAwzPnMNhWG3zOWLUs2QFA2GP4Y+J8cpUYfj6pbKKzeLwyG9qBwF1NJpN8m+q9q7V9P2LY+9Lp9e1mGsGeqt5HMEA3P6vIpcqLJLqE/4PBLLRzfccTcmqb1m71+erxTRhHBRkGS+I7dZEb3olQfnS1Y1tpMBxiwYwR3LW4oXuJwj8="); | |
| 73 | + config.setAlipayPublicKey("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnq90KnF4dTnlzzmxpujbI05OYqi5WxAS6cL0gnZFv2gK51HExF8v/BaP7P979PhFMgWTqmOOI+Dtno5s+yD09XTY1WkshbLk6i4g2Xlr8fyW9ODnkU88RI2w9UdPhQU4cPPwBNlrsYhKkVK2OxwM3kFqjoBBY0CZoZCsSQ3LDH5WeZqPArlsS6xa2zqJBuuoKjMrdpELl3eXSjP8K54eDJCbeetCZNKWLL3DPahTPB7LZikfYmslb0QUvCgGapD0xkS7eVq70NaL1G57MWABs4tbfWgxike4Daj3EfUrzIVspQxj7w8HEj9WozJPgL88kSJSits0pqD3n5r8HSuseQIDAQAB"); | |
| 74 | + AlipayWapPayClient client = new AlipayWapPayClient(1L, "biubiubiu", config); | |
| 75 | + client.init(); | |
| 76 | + | |
| 77 | + PayOrderUnifiedReqDTO reqDTO = new PayOrderUnifiedReqDTO(); | |
| 78 | + reqDTO.setAmount(123); | |
| 79 | + reqDTO.setSubject("IPhone 13"); | |
| 80 | + reqDTO.setMerchantOrderId(String.valueOf(System.currentTimeMillis())); | |
| 81 | + client.unifiedOrder(reqDTO); | |
| 82 | + } | |
| 83 | + | |
| 84 | + | |
| 85 | +} | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/index.html
0 → 100644
| 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> | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-sms/src/main/java/cn/iocoder/yudao/framework/sms/core/client/SmsClientFactory.java
yudao-framework/yudao-spring-boot-starter-biz-sms/src/main/java/cn/iocoder/yudao/framework/sms/core/client/impl/AbstractSmsClient.java
| ... | ... | @@ -30,11 +30,6 @@ public abstract class AbstractSmsClient implements SmsClient { |
| 30 | 30 | */ |
| 31 | 31 | protected final SmsCodeMapping codeMapping; |
| 32 | 32 | |
| 33 | - /** | |
| 34 | - * 短信客户端有参构造函数 | |
| 35 | - * | |
| 36 | - * @param properties 短信配置 | |
| 37 | - */ | |
| 38 | 33 | public AbstractSmsClient(SmsChannelProperties properties, SmsCodeMapping codeMapping) { |
| 39 | 34 | this.properties = properties; |
| 40 | 35 | this.codeMapping = codeMapping; |
| ... | ... | @@ -48,6 +43,11 @@ public abstract class AbstractSmsClient implements SmsClient { |
| 48 | 43 | log.info("[init][配置({}) 初始化完成]", properties); |
| 49 | 44 | } |
| 50 | 45 | |
| 46 | + /** | |
| 47 | + * 自定义初始化 | |
| 48 | + */ | |
| 49 | + protected abstract void doInit(); | |
| 50 | + | |
| 51 | 51 | public final void refresh(SmsChannelProperties properties) { |
| 52 | 52 | // 判断是否更新 |
| 53 | 53 | if (properties.equals(this.properties)) { |
| ... | ... | @@ -59,11 +59,6 @@ public abstract class AbstractSmsClient implements SmsClient { |
| 59 | 59 | this.init(); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - /** | |
| 63 | - * 自定义初始化 | |
| 64 | - */ | |
| 65 | - protected abstract void doInit(); | |
| 66 | - | |
| 67 | 62 | @Override |
| 68 | 63 | public Long getId() { |
| 69 | 64 | return properties.getId(); | ... | ... |