mirror of https://gitee.com/stylefeng/roses
支付模块自动配置模块
parent
cd7ee1dbce
commit
abf8a39219
|
@ -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<String, String> params = new HashMap<>();
|
||||||
|
Map<String, String[]> 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
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.stylefeng.roses</groupId>
|
||||||
|
<artifactId>pay-spring-boot-starter</artifactId>
|
||||||
|
<version>7.0.4</version>
|
||||||
|
</dependency>
|
||||||
|
```
|
||||||
|
|
||||||
|
至此支付宝支付就接入成功啦!
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
如果需要配置应用公钥证书文件路径等信息,参照如下yml(具体配置参数可以查看支付宝支付官方文档)
|
||||||
|
|
||||||
|
```yml
|
||||||
|
alipay:
|
||||||
|
appId:
|
||||||
|
gatewayHost:
|
||||||
|
notifyUrl:
|
||||||
|
merchantPrivateKey:
|
||||||
|
alipayPublicKey:
|
||||||
|
encryptKey:
|
||||||
|
merchantCertPath:
|
||||||
|
alipayCertPath:
|
||||||
|
alipayRootCertPath:
|
||||||
|
```
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>kernel-d-pay</artifactId>
|
||||||
|
<groupId>cn.stylefeng.roses</groupId>
|
||||||
|
<version>7.0.4</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>pay-spring-boot-starter</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!--alipay api模块的sdk-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.stylefeng.roses</groupId>
|
||||||
|
<artifactId>pay-sdk-alipay</artifactId>
|
||||||
|
<version>7.0.4</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||||
|
cn.stylefeng.roses.kernel.pay.starter.GunsPayAutoConfiguration,\
|
||||||
|
cn.stylefeng.roses.kernel.pay.alipay.config.AlipayConfig
|
|
@ -14,6 +14,7 @@
|
||||||
<modules>
|
<modules>
|
||||||
<module>pay-api</module>
|
<module>pay-api</module>
|
||||||
<module>pay-sdk-alipay</module>
|
<module>pay-sdk-alipay</module>
|
||||||
|
<module>pay-spring-boot-starter</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|
Loading…
Reference in New Issue