From 7ca756a2344f16dff39977bfd7479f3361e0dfac Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 19 Oct 2021 09:26:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=95=E5=85=A5=E6=94=AF=E4=BB=98=E5=AE=9D?= =?UTF-8?q?=E7=9A=84=E6=94=AF=E4=BB=98=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sms/impl/SysSmsTemplateServiceImpl.java | 2 +- .../yudao/framework/pay/core/PayClient.java | 14 +++ .../framework/pay/core/PayClientConfig.java | 10 +++ .../framework/pay/core/aop/package-info.java | 8 -- .../pay/core/client/AbstractPayClient.java | 15 ++++ .../core/client/alipay/AlipayPayClient.java | 42 +++++++++ .../core/client/alipay/AlipayPayConfig.java | 88 +++++++++++++++++++ .../pay/core/client/package-info.java | 1 + .../core/gateway/ChannelNoticeService.java | 14 --- .../pay/core/gateway/RefundService.java | 13 --- .../pay/core/gateway/UnifiedOrderService.java | 13 --- .../framework/pay/core/package-info.java | 8 -- .../framework/sms/core/client/SmsClient.java | 2 +- .../core/client/impl/AbstractSmsClient.java | 2 +- 14 files changed, 173 insertions(+), 59 deletions(-) create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/PayClient.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/PayClientConfig.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/aop/package-info.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/AbstractPayClient.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/alipay/AlipayPayClient.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/alipay/AlipayPayConfig.java create mode 100644 yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/package-info.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/gateway/ChannelNoticeService.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/gateway/RefundService.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/gateway/UnifiedOrderService.java delete mode 100644 yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/package-info.java diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/impl/SysSmsTemplateServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/impl/SysSmsTemplateServiceImpl.java index deb76e56e..d8c5b9913 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/impl/SysSmsTemplateServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/impl/SysSmsTemplateServiceImpl.java @@ -33,7 +33,7 @@ import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeCons import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; /** - * 短信模板Service实现类 + * 短信模板 Service 实现类 * * @author zzf * @date 2021/1/25 9:25 diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/PayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/PayClient.java new file mode 100644 index 000000000..42004ec78 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/PayClient.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.framework.pay.core; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; + +/** + * 支付客户端,用于对接各支付渠道的 SDK,实现发起支付、退款等功能 + * + * @author 芋道源码 + */ +public interface PayClient { + + CommonResult unifiedOrder(); + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/PayClientConfig.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/PayClientConfig.java new file mode 100644 index 000000000..0cc5378ca --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/PayClientConfig.java @@ -0,0 +1,10 @@ +package cn.iocoder.yudao.framework.pay.core; + +/** + * 支付客户端的配置,本质是支付渠道的配置 + * 每个不同的渠道,需要不同的配置,通过子类来定义 + * + * @author 芋道源码 + */ +public interface PayClientConfig { +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/aop/package-info.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/aop/package-info.java deleted file mode 100644 index 2a1d9ee81..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/aop/package-info.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * @description - * @author Qingchen - * @version 1.0.0 - * @date 2021-09-29 14:59 - * @class cn.iocoder.yudao.framework.pay.core.aop.package-info.java - */ -package cn.iocoder.yudao.framework.pay.core.aop; \ No newline at end of file diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/AbstractPayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/AbstractPayClient.java new file mode 100644 index 000000000..7d42e9ffc --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/AbstractPayClient.java @@ -0,0 +1,15 @@ +package cn.iocoder.yudao.framework.pay.core.client; + +import cn.iocoder.yudao.framework.pay.core.PayClient; +import com.alipay.api.DefaultAlipayClient; + +/** + * 支付客户端的抽象类,提供模板方法,减少子类的冗余代码 + * + * @author 芋道源码 + */ +public abstract class AbstractPayClient implements PayClient { + + + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/alipay/AlipayPayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/alipay/AlipayPayClient.java new file mode 100644 index 000000000..8de2fea9c --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/alipay/AlipayPayClient.java @@ -0,0 +1,42 @@ +package cn.iocoder.yudao.framework.pay.core.client.alipay; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.pay.core.client.AbstractPayClient; +import com.alipay.api.AlipayApiException; +import com.alipay.api.DefaultAlipayClient; +import com.alipay.api.domain.AlipayTradePrecreateModel; +import com.alipay.api.request.AlipayTradePrecreateRequest; +import com.alipay.api.response.AlipayTradePrecreateResponse; + +/** + * 支付宝的 PayClient 实现类 + */ +public class AlipayPayClient extends AbstractPayClient { + + private DefaultAlipayClient client = new DefaultAlipayClient("https://openapi.alipaydev.com/gateway.do","2021000118634035","MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCHsEV1cDupwJv890x84qbppUtRIfhaKSwSVN0thCcsDCaAsGR5MZslDkO8NCT9V4r2SVXjyY7eJUZlZd1M0C8T01Tg4UOx5LUbic0O3A1uJMy6V1n9IyYwbAW3AEZhBd5bSbPgrqvmv3NeWSTQT6Anxnllf+2iDH6zyA2fPl7cYyQt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vQ0nm/8h8NOoFZ4oNoGc+wU5Ubops7dUM6FjPR5e+OjdJ4E7Xp7d5O4J1TaIZlCEbo5OpdhaTDDcQvrkFu+Z4eN0qzj+YAKjDAOOrXc4tbr5q0FsgXscwtcNfaBuzFVTUrUkCgYEAwzPnMNhWG3zOWLUs2QFA2GP4Y+J8cpUYfj6pbKKzeLwyG9qBwF1NJpN8m+q9q7V9P2LY+9Lp9e1mGsGeqt5HMEA3P6vIpcqLJLqE/4PBLLRzfccTcmqb1m71+erxTRhHBRkGS+I7dZEb3olQfnS1Y1tpMBxiwYwR3LW4oXuJwj8=","json","utf-8","MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnq90KnF4dTnlzzmxpujbI05OYqi5WxAS6cL0gnZFv2gK51HExF8v/BaP7P979PhFMgWTqmOOI+Dtno5s+yD09XTY1WkshbLk6i4g2Xlr8fyW9ODnkU88RI2w9UdPhQU4cPPwBNlrsYhKkVK2OxwM3kFqjoBBY0CZoZCsSQ3LDH5WeZqPArlsS6xa2zqJBuuoKjMrdpELl3eXSjP8K54eDJCbeetCZNKWLL3DPahTPB7LZikfYmslb0QUvCgGapD0xkS7eVq70NaL1G57MWABs4tbfWgxike4Daj3EfUrzIVspQxj7w8HEj9WozJPgL88kSJSits0pqD3n5r8HSuseQIDAQAB","RSA2"); + + @Override + public CommonResult unifiedOrder() { + AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest(); + AlipayTradePrecreateModel model = new AlipayTradePrecreateModel(); + request.setBizModel(model); + model.setOutTradeNo(String.valueOf(System.currentTimeMillis())); + model.setTotalAmount("88.88"); + model.setSubject("Iphone6 16G"); + AlipayTradePrecreateResponse response = null; + try { + response = client.execute(request); + } catch (AlipayApiException e) { + e.printStackTrace(); + } + System.out.println(response.getBody()); + System.out.println(response.getQrCode()); + return null; + } + + public static void main(String[] args) { + AlipayPayClient client = new AlipayPayClient(); + client.unifiedOrder(); + } + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/alipay/AlipayPayConfig.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/alipay/AlipayPayConfig.java new file mode 100644 index 000000000..722efedd1 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/alipay/AlipayPayConfig.java @@ -0,0 +1,88 @@ +package cn.iocoder.yudao.framework.pay.core.client.alipay; + +import lombok.Data; + +// TODO 芋艿:参数校验 +/** + * 支付宝的 PayClientConfig 实现类 + * 属性主要来自 {@link com.alipay.api.AlipayConfig} 的必要属性 + * + * @author 芋道源码 + */ +@Data +public class AlipayPayConfig { + + /** + * 网关地址 - 线上 + */ + private static final String SERVER_URL_PROD = "https://openapi.alipay.com/gateway.do"; + /** + * 网关地址 - 沙箱 + */ + private static final String SERVER_URL_SANDBOX = "https://openapi.alipay.com/gateway.do"; + + /** + * 公钥类型 - 公钥模式 + */ + private static final Integer MODE_PUBLIC_KEY = 1; + /** + * 公钥类型 - 证书模式 + */ + private static final Integer MODE_CERTIFICATE = 2; + + /** + * 签名算法类型 - RSA + */ + private static final String SIGN_TYPE_DEFAULT = "RSA2"; + + /** + * 网关地址 + * 1. {@link #SERVER_URL_PROD} + * 2. {@link #SERVER_URL_SANDBOX} + */ + private String serverUrl; + + /** + * 开放平台上创建的应用的 ID + */ + private String appId; + + /** + * 签名算法类型,推荐:RSA2 + * + * {@link #SIGN_TYPE_DEFAULT} + */ + private String signType; + + /** + * 公钥类型 + * 1. {@link #MODE_PUBLIC_KEY} 情况,privateKey + alipayPublicKey + * 2. {@link #MODE_CERTIFICATE} 情况,appCertContent + alipayPublicCertContent + rootCertContent + */ + private Integer mode; + + // ========== 公钥模式 ========== + /** + * 商户私钥 + */ + private String privateKey; + /** + * 支付宝公钥字符串 + */ + private String alipayPublicKey; + + // ========== 证书模式 ========== + /** + * 指定商户公钥应用证书内容字符串 + */ + private String appCertContent; + /** + * 指定支付宝公钥证书内容字符串 + */ + private String alipayPublicCertContent; + /** + * 指定根证书内容字符串 + */ + private String rootCertContent; + +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/package-info.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/package-info.java new file mode 100644 index 000000000..0b5348f1f --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/package-info.java @@ -0,0 +1 @@ +package cn.iocoder.yudao.framework.pay.core.client; diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/gateway/ChannelNoticeService.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/gateway/ChannelNoticeService.java deleted file mode 100644 index 75799f260..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/gateway/ChannelNoticeService.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.yudao.framework.pay.core.gateway; -/** - * @description 渠道侧的通知网关服务,分为同步跳转(doReturn)和异步回调(doNotify) - * @author Qingchen - * @version 1.0.0 - * @date 2021-10-09 14:34 - * @class cn.iocoder.yudao.framework.pay.core.gateway.ChannelNoticeService.java - */ -public interface ChannelNoticeService { - - - - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/gateway/RefundService.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/gateway/RefundService.java deleted file mode 100644 index 0b7b3f8f7..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/gateway/RefundService.java +++ /dev/null @@ -1,13 +0,0 @@ -package cn.iocoder.yudao.framework.pay.core.gateway; -/** - * @description 退款网关服务 - * @author Qingchen - * @version 1.0.0 - * @date 2021-10-09 16:07 - * @class cn.iocoder.yudao.framework.pay.core.gateway.RefundService.java - */ -public interface RefundService { - - - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/gateway/UnifiedOrderService.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/gateway/UnifiedOrderService.java deleted file mode 100644 index b549cb2b8..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/gateway/UnifiedOrderService.java +++ /dev/null @@ -1,13 +0,0 @@ -package cn.iocoder.yudao.framework.pay.core.gateway; -/** - * @description 统一下单网关服务 - * @author Qingchen - * @version 1.0.0 - * @date 2021-09-29 16:14 - * @class cn.iocoder.yudao.framework.pay.core.gateway.UnifiedOrderService.java - */ -public interface UnifiedOrderService { - - - -} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/package-info.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/package-info.java deleted file mode 100644 index 2a8f41869..000000000 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/package-info.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * @description - * @author Qingchen - * @version 1.0.0 - * @date 2021-09-29 14:34 - * @class cn.iocoder.yudao.framework.pay.core.package-info.java - */ -package cn.iocoder.yudao.framework.pay.core; \ No newline at end of file diff --git a/yudao-framework/yudao-spring-boot-starter-biz-sms/src/main/java/cn/iocoder/yudao/framework/sms/core/client/SmsClient.java b/yudao-framework/yudao-spring-boot-starter-biz-sms/src/main/java/cn/iocoder/yudao/framework/sms/core/client/SmsClient.java index 2f936de8c..06bcba084 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-sms/src/main/java/cn/iocoder/yudao/framework/sms/core/client/SmsClient.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-sms/src/main/java/cn/iocoder/yudao/framework/sms/core/client/SmsClient.java @@ -8,7 +8,7 @@ import cn.iocoder.yudao.framework.sms.core.client.dto.SmsTemplateRespDTO; import java.util.List; /** - * 短信客户端接口 + * 短信客户端,用于对接各短信平台的 SDK,实现短信发送等功能 * * @author zzf * @date 2021/1/25 14:14 diff --git a/yudao-framework/yudao-spring-boot-starter-biz-sms/src/main/java/cn/iocoder/yudao/framework/sms/core/client/impl/AbstractSmsClient.java b/yudao-framework/yudao-spring-boot-starter-biz-sms/src/main/java/cn/iocoder/yudao/framework/sms/core/client/impl/AbstractSmsClient.java index a96038059..72a1e5271 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-sms/src/main/java/cn/iocoder/yudao/framework/sms/core/client/impl/AbstractSmsClient.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-sms/src/main/java/cn/iocoder/yudao/framework/sms/core/client/impl/AbstractSmsClient.java @@ -13,7 +13,7 @@ import lombok.extern.slf4j.Slf4j; import java.util.List; /** - * 短信客户端抽象类 + * 短信客户端的抽象类,提供模板方法,减少子类的冗余代码 * * @author zzf * @date 2021/2/1 9:28