From 55e467b9947f2272c60c4842aba7a80f1bfbea1b Mon Sep 17 00:00:00 2001 From: huziyang Date: Fri, 28 May 2021 14:15:23 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=94=AF=E4=BB=98api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel-d-pay/pay-api/pom.xml | 23 ++++ .../roses/kernel/pay/api/PayApi.java | 79 +++++++++++ .../pay/api/constants/PayConstants.java | 56 ++++++++ .../pay/api/exception/PayException.java | 43 ++++++ .../pay/api/pojo/TradeRefundResponse.java | 129 ++++++++++++++++++ kernel-d-pay/pom.xml | 34 +++++ pom.xml | 3 + 7 files changed, 367 insertions(+) create mode 100644 kernel-d-pay/pay-api/pom.xml create mode 100644 kernel-d-pay/pay-api/src/main/java/cn/stylefeng/roses/kernel/pay/api/PayApi.java create mode 100644 kernel-d-pay/pay-api/src/main/java/cn/stylefeng/roses/kernel/pay/api/constants/PayConstants.java create mode 100644 kernel-d-pay/pay-api/src/main/java/cn/stylefeng/roses/kernel/pay/api/exception/PayException.java create mode 100644 kernel-d-pay/pay-api/src/main/java/cn/stylefeng/roses/kernel/pay/api/pojo/TradeRefundResponse.java create mode 100644 kernel-d-pay/pom.xml diff --git a/kernel-d-pay/pay-api/pom.xml b/kernel-d-pay/pay-api/pom.xml new file mode 100644 index 000000000..b8e92f1ba --- /dev/null +++ b/kernel-d-pay/pay-api/pom.xml @@ -0,0 +1,23 @@ + + + + kernel-d-pay + cn.stylefeng.roses + 7.0.4 + + 4.0.0 + + pay-api + + + 8 + 8 + + + + + + + \ No newline at end of file diff --git a/kernel-d-pay/pay-api/src/main/java/cn/stylefeng/roses/kernel/pay/api/PayApi.java b/kernel-d-pay/pay-api/src/main/java/cn/stylefeng/roses/kernel/pay/api/PayApi.java new file mode 100644 index 000000000..3c0604a76 --- /dev/null +++ b/kernel-d-pay/pay-api/src/main/java/cn/stylefeng/roses/kernel/pay/api/PayApi.java @@ -0,0 +1,79 @@ +/* + * Copyright [2020-2030] [https://www.stylefeng.cn] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + * + * 1.请不要删除和修改根目录下的LICENSE文件。 + * 2.请不要删除和修改Guns源码头部的版权声明。 + * 3.请保留源码和相关描述文件的项目出处,作者声明等。 + * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns + * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns + * 6.若您的项目无法满足以上几点,可申请商业授权 + */ +package cn.stylefeng.roses.kernel.pay.api; + + +import cn.stylefeng.roses.kernel.pay.api.pojo.TradeRefundResponse; + +/** + * 支付的api + * + * @author huziyang + * @date 2021/04/20 20:43 + */ +public interface PayApi { + + /** + * PC网页支付 + * + * @param orderName 订单名称 + * @param outTradeNo 商家订单编号 + * @param total 金额 + * @param returnUrl 付款完成后跳转页面 + * @return 支付页面 + * @author huziyang + * @date 2021/04/20 20:43 + */ + String page(String orderName, String outTradeNo, String total, String returnUrl); + + + /** + * 手机支付 + * + * @param orderName 订单名称 + * @param outTradeNo 商家订单编号 + * @param total 金额 + * @param quitUrl 中途退出时返回的页面 + * @param returnUrl 付款完成后跳转页面 + * @return 支付页面 + * @author huziyang + * @date 2021/04/20 20:43 + */ + String wap(String orderName, String outTradeNo, String total, String quitUrl, String returnUrl); + + + /** + * 退款 + * + * @param outTradeNo 商家订单编号 + * @param refundAmount 退款金额 + * @return 退款结果 + * @author huziyang + * @date 2021/04/20 20:43 + */ + TradeRefundResponse refund(String outTradeNo, String refundAmount); + + +} diff --git a/kernel-d-pay/pay-api/src/main/java/cn/stylefeng/roses/kernel/pay/api/constants/PayConstants.java b/kernel-d-pay/pay-api/src/main/java/cn/stylefeng/roses/kernel/pay/api/constants/PayConstants.java new file mode 100644 index 000000000..5a1384847 --- /dev/null +++ b/kernel-d-pay/pay-api/src/main/java/cn/stylefeng/roses/kernel/pay/api/constants/PayConstants.java @@ -0,0 +1,56 @@ +/* + * Copyright [2020-2030] [https://www.stylefeng.cn] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + * + * 1.请不要删除和修改根目录下的LICENSE文件。 + * 2.请不要删除和修改Guns源码头部的版权声明。 + * 3.请保留源码和相关描述文件的项目出处,作者声明等。 + * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns + * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns + * 6.若您的项目无法满足以上几点,可申请商业授权 + */ +package cn.stylefeng.roses.kernel.pay.api.constants; + +/** + * 支付模块的常量 + * + * @author huziyang + * @date 2021/04/20 20:43 + */ +public interface PayConstants { + + /** + * mongodb模块的名称 + */ + String PAY_MODULE_NAME = "kernel-d-pay"; + + /** + * 异常枚举的步进值 + */ + String PAY_EXCEPTION_STEP_CODE = "80"; + + + /** + * 退款成功的返回码 + */ + String REFUND_SUCCESS_CODE = "10000"; + + /** + * 退款失败的返回码 + */ + String REFUND_ERROR_CODE = "40000"; + +} diff --git a/kernel-d-pay/pay-api/src/main/java/cn/stylefeng/roses/kernel/pay/api/exception/PayException.java b/kernel-d-pay/pay-api/src/main/java/cn/stylefeng/roses/kernel/pay/api/exception/PayException.java new file mode 100644 index 000000000..594fad767 --- /dev/null +++ b/kernel-d-pay/pay-api/src/main/java/cn/stylefeng/roses/kernel/pay/api/exception/PayException.java @@ -0,0 +1,43 @@ +/* + * Copyright [2020-2030] [https://www.stylefeng.cn] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + * + * 1.请不要删除和修改根目录下的LICENSE文件。 + * 2.请不要删除和修改Guns源码头部的版权声明。 + * 3.请保留源码和相关描述文件的项目出处,作者声明等。 + * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns + * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns + * 6.若您的项目无法满足以上几点,可申请商业授权 + */ +package cn.stylefeng.roses.kernel.pay.api.exception; + +import cn.stylefeng.roses.kernel.pay.api.constants.PayConstants; +import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum; +import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException; + +/** + * 支付模块的异常 + * + * @author huziyang + * @date 2021/04/20 20:43 + */ +public class PayException extends ServiceException { + + public PayException(AbstractExceptionEnum exception) { + super(PayConstants.PAY_MODULE_NAME, exception); + } + +} diff --git a/kernel-d-pay/pay-api/src/main/java/cn/stylefeng/roses/kernel/pay/api/pojo/TradeRefundResponse.java b/kernel-d-pay/pay-api/src/main/java/cn/stylefeng/roses/kernel/pay/api/pojo/TradeRefundResponse.java new file mode 100644 index 000000000..41291a1a4 --- /dev/null +++ b/kernel-d-pay/pay-api/src/main/java/cn/stylefeng/roses/kernel/pay/api/pojo/TradeRefundResponse.java @@ -0,0 +1,129 @@ +/* + * Copyright [2020-2030] [https://www.stylefeng.cn] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + * + * 1.请不要删除和修改根目录下的LICENSE文件。 + * 2.请不要删除和修改Guns源码头部的版权声明。 + * 3.请保留源码和相关描述文件的项目出处,作者声明等。 + * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns + * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns + * 6.若您的项目无法满足以上几点,可申请商业授权 + */ +package cn.stylefeng.roses.kernel.pay.api.pojo; + +import cn.stylefeng.roses.kernel.pay.api.constants.PayConstants; +import lombok.*; + +/** + * 退款响应 + * + * @author huziyang + * @date 2021/04/20 20:43 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class TradeRefundResponse{ + + /** + * 退款状态码 + */ + private String code; + + /** + * 状态描述 + */ + private String msg; + + /** + * 商家订单号 + */ + private String outTradeNo; + + /** + * 退款金额 + */ + private String refundFee; + + /** + * 各厂商系统中的交易流水号 + */ + private String tradeNo; + + /** + * 退款实际的发生时间 + */ + private String gmtRefundPay; + + /** + * 买家账号 + */ + private String buyerLogonId; + + /** + * 买家在各厂商系统中的用户id + */ + private String buyerUserId; + + /** + * 各厂商响应值 + */ + private Object data; + + /** + * 初始化一个新创建的 TradeRefundResponse对象 + * + * @param code 状态码 + * @param msg 描述 + * @param data 对象值 + * @author huziyang + * @date 2021/04/20 20:43 + */ + public TradeRefundResponse(String code, String msg, Object data){ + this.code = code; + this.msg = msg; + this.data = data; + } + + /** + * 返回错误信息 + * + * @param msg 描述 + * @param data 对象值 + * @return TradeRefundResponse对象 + * @author huziyang + * @date 2021/04/20 20:43 + */ + public static TradeRefundResponse error(String msg, Object data){ + return new TradeRefundResponse(PayConstants.REFUND_ERROR_CODE,msg,data); + } + + + /** + * 返回错误信息 + * + * @param msg 描述 + * @return TradeRefundResponse对象 + * @author huziyang + * @date 2021/04/20 20:43 + */ + public static TradeRefundResponse error(String msg){ + return error(msg,null); + } + + +} diff --git a/kernel-d-pay/pom.xml b/kernel-d-pay/pom.xml new file mode 100644 index 000000000..f5611541b --- /dev/null +++ b/kernel-d-pay/pom.xml @@ -0,0 +1,34 @@ + + + + roses-kernel + cn.stylefeng.roses + 7.0.4 + + 4.0.0 + + kernel-d-pay + pom + + pay-api + pay-sdk-alipay + + + + 8 + 8 + + + + + + + cn.stylefeng.roses + kernel-a-rule + 7.0.4 + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 953dd9c0d..3f42d17d6 100644 --- a/pom.xml +++ b/pom.xml @@ -94,6 +94,9 @@ kernel-d-mongodb + + kernel-d-pay + kernel-s-system From e5b76e28b0847a82cf0ebf29dd7337b6d499ec30 Mon Sep 17 00:00:00 2001 From: huziyang Date: Fri, 28 May 2021 14:15:43 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E9=98=BF=E9=87=8C=E6=94=AF=E4=BB=98api?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel-d-pay/pay-sdk-alipay/pom.xml | 37 +++++ .../pay/alipay/config/AlipayConfig.java | 136 ++++++++++++++++++ .../pay/alipay/constants/AlipayConstants.java | 36 +++++ .../pay/alipay/service/AlipayService.java | 79 ++++++++++ .../service/impl/AlipayServiceImpl.java | 91 ++++++++++++ 5 files changed, 379 insertions(+) create mode 100644 kernel-d-pay/pay-sdk-alipay/pom.xml create mode 100644 kernel-d-pay/pay-sdk-alipay/src/main/java/cn/stylefeng/roses/kernel/pay/alipay/config/AlipayConfig.java create mode 100644 kernel-d-pay/pay-sdk-alipay/src/main/java/cn/stylefeng/roses/kernel/pay/alipay/constants/AlipayConstants.java create mode 100644 kernel-d-pay/pay-sdk-alipay/src/main/java/cn/stylefeng/roses/kernel/pay/alipay/service/AlipayService.java create mode 100644 kernel-d-pay/pay-sdk-alipay/src/main/java/cn/stylefeng/roses/kernel/pay/alipay/service/impl/AlipayServiceImpl.java diff --git a/kernel-d-pay/pay-sdk-alipay/pom.xml b/kernel-d-pay/pay-sdk-alipay/pom.xml new file mode 100644 index 000000000..3486c066c --- /dev/null +++ b/kernel-d-pay/pay-sdk-alipay/pom.xml @@ -0,0 +1,37 @@ + + + + kernel-d-pay + cn.stylefeng.roses + 7.0.4 + + 4.0.0 + + pay-sdk-alipay + + + 8 + 8 + + + + + + + cn.stylefeng.roses + pay-api + 7.0.4 + + + + + com.alipay.sdk + alipay-easysdk + 2.2.0 + + + + + \ No newline at end of file diff --git a/kernel-d-pay/pay-sdk-alipay/src/main/java/cn/stylefeng/roses/kernel/pay/alipay/config/AlipayConfig.java b/kernel-d-pay/pay-sdk-alipay/src/main/java/cn/stylefeng/roses/kernel/pay/alipay/config/AlipayConfig.java new file mode 100644 index 000000000..c79b7f951 --- /dev/null +++ b/kernel-d-pay/pay-sdk-alipay/src/main/java/cn/stylefeng/roses/kernel/pay/alipay/config/AlipayConfig.java @@ -0,0 +1,136 @@ +/* + * Copyright [2020-2030] [https://www.stylefeng.cn] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + * + * 1.请不要删除和修改根目录下的LICENSE文件。 + * 2.请不要删除和修改Guns源码头部的版权声明。 + * 3.请保留源码和相关描述文件的项目出处,作者声明等。 + * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns + * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns + * 6.若您的项目无法满足以上几点,可申请商业授权 + */ +package cn.stylefeng.roses.kernel.pay.alipay.config; + +import com.alipay.easysdk.factory.Factory; +import com.alipay.easysdk.kernel.Config; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +/** + * 阿里支付配置类 + * + * @author huziyang + * @date 2021/04/20 20:43 + */ +@Component +public class AlipayConfig implements ApplicationRunner { + + /** + * 应用id + */ + @Value("${alipay.appId}") + private String appId; + + /** + * 私钥 + */ + @Value("${alipay.merchantPrivateKey}") + private String merchantPrivateKey; + + /** + * 公钥 + */ + @Value("${alipay.alipayPublicKey}") + private String alipayPublicKey; + + /** + * 网关 + */ + @Value("${alipay.gatewayHost}") + private String gatewayHost; + + /** + * 支付成功后的接口回调地址 (可选) + */ + @Value("${alipay.notifyUrl:#{null}}") + private String notifyUrl; + + /** + * AES密钥 (可选) + */ + @Value("${alipay.encryptKey:#{null}}") + private String encryptKey; + + /** + * 应用公钥证书文件路径 + */ + @Value("${alipay.merchantCertPath:#{null}}") + private String merchantCertPath; + + /** + * 支付宝公钥证书文件路径 + */ + @Value("${alipay.alipayCertPath:#{null}}") + private String alipayCertPath; + + /** + * 支付宝根证书文件路径 + */ + @Value("${alipay.alipayRootCertPath:#{null}}") + private String alipayRootCertPath; + + /** + * 初始化 + * + * @author huziyang + * @date 2021/04/20 20:43 + */ + @Override + public void run(ApplicationArguments args) throws Exception { + Factory.setOptions(getOptions()); + } + + /** + * 获取支付配置对象 + * + * @return 支付配置对象 + * @author huziyang + * @date 2021/04/20 20:43 + */ + private Config getOptions() { + Config config = new Config(); + config.protocol = "https"; + config.gatewayHost = this.gatewayHost; + config.signType = "RSA2"; + config.appId = this.appId; + config.merchantPrivateKey = this.merchantPrivateKey; + // 证书文件路径支持设置为文件系统中的路径或CLASS_PATH中的路径,优先从文件系统中加载,加载失败后会继续尝试从CLASS_PATH中加载 + config.merchantCertPath = this.merchantCertPath; + config.alipayCertPath = this.alipayCertPath; + config.alipayRootCertPath = this.alipayRootCertPath; + // 如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可 + config.alipayPublicKey = this.alipayPublicKey; + // 可设置异步通知接收服务地址(可选) + config.notifyUrl = notifyUrl; + // 可设置AES密钥,调用AES加解密相关接口时需要(可选) + config.encryptKey = this.encryptKey; + return config; + } + + +} diff --git a/kernel-d-pay/pay-sdk-alipay/src/main/java/cn/stylefeng/roses/kernel/pay/alipay/constants/AlipayConstants.java b/kernel-d-pay/pay-sdk-alipay/src/main/java/cn/stylefeng/roses/kernel/pay/alipay/constants/AlipayConstants.java new file mode 100644 index 000000000..3a257e671 --- /dev/null +++ b/kernel-d-pay/pay-sdk-alipay/src/main/java/cn/stylefeng/roses/kernel/pay/alipay/constants/AlipayConstants.java @@ -0,0 +1,36 @@ +/* + * Copyright [2020-2030] [https://www.stylefeng.cn] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + * + * 1.请不要删除和修改根目录下的LICENSE文件。 + * 2.请不要删除和修改Guns源码头部的版权声明。 + * 3.请保留源码和相关描述文件的项目出处,作者声明等。 + * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns + * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns + * 6.若您的项目无法满足以上几点,可申请商业授权 + */ +package cn.stylefeng.roses.kernel.pay.alipay.constants; + +/** + * 阿里支付常量 + * + * @author huziyang + * @date 2021/04/20 20:43 + */ +public interface AlipayConstants { + + String ALIPAY_REFUND_SUCCESS_CODE = "10000"; +} diff --git a/kernel-d-pay/pay-sdk-alipay/src/main/java/cn/stylefeng/roses/kernel/pay/alipay/service/AlipayService.java b/kernel-d-pay/pay-sdk-alipay/src/main/java/cn/stylefeng/roses/kernel/pay/alipay/service/AlipayService.java new file mode 100644 index 000000000..925560096 --- /dev/null +++ b/kernel-d-pay/pay-sdk-alipay/src/main/java/cn/stylefeng/roses/kernel/pay/alipay/service/AlipayService.java @@ -0,0 +1,79 @@ +/* + * Copyright [2020-2030] [https://www.stylefeng.cn] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + * + * 1.请不要删除和修改根目录下的LICENSE文件。 + * 2.请不要删除和修改Guns源码头部的版权声明。 + * 3.请保留源码和相关描述文件的项目出处,作者声明等。 + * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns + * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns + * 6.若您的项目无法满足以上几点,可申请商业授权 + */ +package cn.stylefeng.roses.kernel.pay.alipay.service; + + +import cn.stylefeng.roses.kernel.pay.api.pojo.TradeRefundResponse; + +/** + * 阿里支付的接口 + * + * @author huziyang + * @date 2021/04/20 20:43 + */ +public interface AlipayService { + + /** + * PC网页支付 + * + * @param orderName 订单名称 + * @param outTradeNo 商家订单编号 + * @param total 金额 + * @param returnUrl 付款完成后跳转页面 + * @return 支付页面 + * @author huziyang + * @date 2021/04/20 20:43 + */ + String page(String orderName, String outTradeNo, String total, String returnUrl); + + + /** + * 手机支付 + * + * @param orderName 订单名称 + * @param outTradeNo 商家订单编号 + * @param total 金额 + * @param quitUrl 中途退出时返回的页面 + * @param returnUrl 付款完成后跳转页面 + * @return 支付页面 + * @author huziyang + * @date 2021/04/20 20:43 + */ + String wap(String orderName, String outTradeNo, String total, String quitUrl, String returnUrl); + + + /** + * 退款 + * + * @param outTradeNo 商家订单编号 + * @param refundAmount 退款金额 + * @return 退款结果 + * @author huziyang + * @date 2021/04/20 20:43 + */ + TradeRefundResponse refund(String outTradeNo, String refundAmount); + + +} diff --git a/kernel-d-pay/pay-sdk-alipay/src/main/java/cn/stylefeng/roses/kernel/pay/alipay/service/impl/AlipayServiceImpl.java b/kernel-d-pay/pay-sdk-alipay/src/main/java/cn/stylefeng/roses/kernel/pay/alipay/service/impl/AlipayServiceImpl.java new file mode 100644 index 000000000..329d653a1 --- /dev/null +++ b/kernel-d-pay/pay-sdk-alipay/src/main/java/cn/stylefeng/roses/kernel/pay/alipay/service/impl/AlipayServiceImpl.java @@ -0,0 +1,91 @@ +/* + * Copyright [2020-2030] [https://www.stylefeng.cn] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + * + * 1.请不要删除和修改根目录下的LICENSE文件。 + * 2.请不要删除和修改Guns源码头部的版权声明。 + * 3.请保留源码和相关描述文件的项目出处,作者声明等。 + * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns + * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns + * 6.若您的项目无法满足以上几点,可申请商业授权 + */ +package cn.stylefeng.roses.kernel.pay.alipay.service.impl; + +import cn.stylefeng.roses.kernel.pay.alipay.constants.AlipayConstants; +import cn.stylefeng.roses.kernel.pay.alipay.service.AlipayService; +import cn.stylefeng.roses.kernel.pay.api.PayApi; +import cn.stylefeng.roses.kernel.pay.api.constants.PayConstants; +import cn.stylefeng.roses.kernel.pay.api.pojo.TradeRefundResponse; +import com.alipay.easysdk.factory.Factory; +import com.alipay.easysdk.payment.common.models.AlipayTradeRefundResponse; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +/** + * 阿里支付接口实现 + * + * @author huziyang + * @date 2021/04/20 20:43 + */ +@Service +@Slf4j +public class AlipayServiceImpl implements AlipayService, PayApi { + + + @Override + public String page(String orderName, String outTradeNo, String total, String returnUrl) { + try { + return Factory.Payment.Page().pay(orderName, outTradeNo, total, returnUrl).body; + } catch (Exception e) { + log.error(e.getMessage()); + return e.getMessage(); + } + } + + @Override + public String wap(String orderName, String outTradeNo, String total, String quitUrl, String returnUrl) { + try { + return Factory.Payment.Wap().pay(orderName, outTradeNo, total, quitUrl, returnUrl).body; + } catch (Exception e) { + log.error(e.getMessage()); + return e.getMessage(); + } + } + + @Override + public TradeRefundResponse refund(String outTradeNo, String refundAmount) { + try { + AlipayTradeRefundResponse response = Factory.Payment.Common().refund(outTradeNo, refundAmount); + if (AlipayConstants.ALIPAY_REFUND_SUCCESS_CODE.equals(response.getCode())){ + return TradeRefundResponse.builder() + .code(PayConstants.REFUND_SUCCESS_CODE) + .msg(response.getMsg()) + .outTradeNo(response.getOutTradeNo()) + .refundFee(response.getRefundFee()) + .tradeNo(response.getTradeNo()) + .gmtRefundPay(response.getGmtRefundPay()) + .buyerLogonId(response.buyerLogonId) + .buyerUserId(response.buyerUserId) + .data(response) + .build(); + } + return TradeRefundResponse.error(response.msg,response); + } catch (Exception e) { + log.error(e.getMessage()); + return TradeRefundResponse.error(e.getMessage()); + } + } +} From cd7ee1dbce8bbdd60a983ad5a63a13ba8a96c86f Mon Sep 17 00:00:00 2001 From: huziyang Date: Sat, 29 May 2021 22:57:56 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel-d-pay/pay-api/pom.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/kernel-d-pay/pay-api/pom.xml b/kernel-d-pay/pay-api/pom.xml index b8e92f1ba..926d2e61c 100644 --- a/kernel-d-pay/pay-api/pom.xml +++ b/kernel-d-pay/pay-api/pom.xml @@ -16,8 +16,5 @@ 8 - - - \ No newline at end of file From abf8a392190c69ec3fff732c1944bf8efdc87745 Mon Sep 17 00:00:00 2001 From: huziyang Date: Sat, 29 May 2021 22:58:30 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=94=AF=E4=BB=98=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E9=85=8D=E7=BD=AE=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel-d-pay/README.md | 151 ++++++++++++++++++ kernel-d-pay/pay-spring-boot-starter/pom.xml | 28 ++++ .../pay/starter/GunsPayAutoConfiguration.java | 54 +++++++ .../main/resources/META-INF/spring.factories | 3 + kernel-d-pay/pom.xml | 1 + 5 files changed, 237 insertions(+) create mode 100644 kernel-d-pay/README.md create mode 100644 kernel-d-pay/pay-spring-boot-starter/pom.xml create mode 100644 kernel-d-pay/pay-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/pay/starter/GunsPayAutoConfiguration.java create mode 100644 kernel-d-pay/pay-spring-boot-starter/src/main/resources/META-INF/spring.factories diff --git a/kernel-d-pay/README.md b/kernel-d-pay/README.md new file mode 100644 index 000000000..f50795254 --- /dev/null +++ b/kernel-d-pay/README.md @@ -0,0 +1,151 @@ +# 支付模块 + +## 接入支付宝支付 + +### application.yml添加支付宝支付appid等信息 + +```yml +alipay: + appId: 2021000117660206 + gatewayHost: openapi.alipaydev.com + notifyUrl: http://101.132.1.2:8001/pay/notify_url + merchantPrivateKey: MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC+g1/v3Z968 + alipayPublicKey: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB +``` + +注:openapi.alipaydev.com 是沙盒环境 ,正式环境需要更换网关 + +gatewayHost:必须是外网穿透host,否则阿里无法回调成功 + +### 使用Demo + +```java +package com.alipay.controller; + +import cn.hutool.core.lang.UUID; +import cn.stylefeng.roses.kernel.pay.api.PayApi; +import cn.stylefeng.roses.kernel.pay.api.pojo.TradeRefundResponse; +import com.alipay.easysdk.factory.Factory; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.util.HashMap; +import java.util.Map; + +/** + * 支付模块测试 + * + * @author huziyang + * @date 2021/05/29 21:38 + */ +@RestController +@RequestMapping("/test") +@Slf4j +public class AlipayTest { + + + @Resource + private PayApi payApi; + + /** + * PC支付 + * + * @return 支付页面 + * @author huziyang + * @date 2021/04/20 20:43 + */ + @GetMapping("/page") + public String page(){ + return payApi.page("xx全屋定制", "eb58cd5c-7613-41ce-93ef-fcf0ad4284f9","12.5",null); + } + + /** + * 手机支付 + * + * @return 支付页面 + * @author huziyang + * @date 2021/04/20 20:43 + */ + @GetMapping("/wap") + public String wap(){ + return payApi.wap("xx全屋定制", "eb58cd5c-7613-41ce-93ef-fcf0ad4284f8","12.5",null,null); + } + + /** + * 退款 + * + * @return 退款实体 + * @author huziyang + * @date 2021/04/20 20:43 + */ + @PostMapping("/refund") + public TradeRefundResponse refund() { + return payApi.refund("eb58cd5c-7613-41ce-93ef-fcf0ad4284f8", "12.5"); + } + + + /** + * 支付宝回调 + * + * @param request + * @throws Exception + * @author huziyang + * @date 2021/04/20 20:43 + */ + @PostMapping("/notify_url") + public void notify(HttpServletRequest request) throws Exception { + if (request.getParameter("trade_status").equals("TRADE_SUCCESS")) { + Map params = new HashMap<>(); + Map requestParams = request.getParameterMap(); + for (String name : requestParams.keySet()) { + params.put(name, request.getParameter(name)); + } + if (Factory.Payment.Common().verifyNotify(params)) { + log.info("支付宝异步回调成功"); + log.info("订单名称: " + params.get("subject")); + log.info("交易状态: " + params.get("trade_status")); + log.info("支付宝交易凭证号: " + params.get("trade_no")); + log.info("商家订单号: " + params.get("out_trade_no")); + log.info("交易金额: " + params.get("total_amount")); + log.info("支付宝唯一id: " + params.get("buyer_id")); + log.info("付款时间: " + params.get("gmt_payment")); + log.info("付款金额: " + params.get("buyer_pay_amount")); + } + } + } +} +``` + +### pom中引用支付依赖 + +```xml + + cn.stylefeng.roses + pay-spring-boot-starter + 7.0.4 + +``` + +至此支付宝支付就接入成功啦! + + + +如果需要配置应用公钥证书文件路径等信息,参照如下yml(具体配置参数可以查看支付宝支付官方文档) + +```yml +alipay: + appId: + gatewayHost: + notifyUrl: + merchantPrivateKey: + alipayPublicKey: + encryptKey: + merchantCertPath: + alipayCertPath: + alipayRootCertPath: +``` + diff --git a/kernel-d-pay/pay-spring-boot-starter/pom.xml b/kernel-d-pay/pay-spring-boot-starter/pom.xml new file mode 100644 index 000000000..f67ccd803 --- /dev/null +++ b/kernel-d-pay/pay-spring-boot-starter/pom.xml @@ -0,0 +1,28 @@ + + + + kernel-d-pay + cn.stylefeng.roses + 7.0.4 + + 4.0.0 + + pay-spring-boot-starter + + + 8 + 8 + + + + + + cn.stylefeng.roses + pay-sdk-alipay + 7.0.4 + + + + \ No newline at end of file diff --git a/kernel-d-pay/pay-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/pay/starter/GunsPayAutoConfiguration.java b/kernel-d-pay/pay-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/pay/starter/GunsPayAutoConfiguration.java new file mode 100644 index 000000000..b02618de7 --- /dev/null +++ b/kernel-d-pay/pay-spring-boot-starter/src/main/java/cn/stylefeng/roses/kernel/pay/starter/GunsPayAutoConfiguration.java @@ -0,0 +1,54 @@ +/* + * Copyright [2020-2030] [https://www.stylefeng.cn] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: + * + * 1.请不要删除和修改根目录下的LICENSE文件。 + * 2.请不要删除和修改Guns源码头部的版权声明。 + * 3.请保留源码和相关描述文件的项目出处,作者声明等。 + * 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns + * 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns + * 6.若您的项目无法满足以上几点,可申请商业授权 + */ +package cn.stylefeng.roses.kernel.pay.starter; + +import cn.stylefeng.roses.kernel.pay.alipay.service.impl.AlipayServiceImpl; +import cn.stylefeng.roses.kernel.pay.api.PayApi; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * 支付模块自动配置 + * + * @author huziyang + * @date 2021/05/29 21:38 + */ +@Configuration +public class GunsPayAutoConfiguration { + + /** + * 支付 阿里支付实现 + * + * @author huziyang + * @date 2021/05/29 21:38 + */ + @Bean + public PayApi payApi() { + return new AlipayServiceImpl(); + } + + +} + diff --git a/kernel-d-pay/pay-spring-boot-starter/src/main/resources/META-INF/spring.factories b/kernel-d-pay/pay-spring-boot-starter/src/main/resources/META-INF/spring.factories new file mode 100644 index 000000000..f8b084b65 --- /dev/null +++ b/kernel-d-pay/pay-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -0,0 +1,3 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + cn.stylefeng.roses.kernel.pay.starter.GunsPayAutoConfiguration,\ + cn.stylefeng.roses.kernel.pay.alipay.config.AlipayConfig \ No newline at end of file diff --git a/kernel-d-pay/pom.xml b/kernel-d-pay/pom.xml index f5611541b..a4f793ab3 100644 --- a/kernel-d-pay/pom.xml +++ b/kernel-d-pay/pom.xml @@ -14,6 +14,7 @@ pay-api pay-sdk-alipay + pay-spring-boot-starter