mirror of
https://github.com/dromara/payment-spring-boot.git
synced 2026-03-13 21:33:41 +08:00
docs
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# 移动支付 Spring Boot 组件
|
||||
为了满足业务中出现app支付、公众号支付、小程序支付等多appid并存的场景,对原有的进行了增强开发出了多租户版本。
|
||||
|
||||
## 开源协议
|
||||
**Apache 2.0**
|
||||
# 文档地址
|
||||
|
||||
[payment-spring-boot 文档](https://notfound403.github.io/payment-spring-boot)
|
||||
|
||||
@@ -27,4 +27,12 @@
|
||||
|
||||
- **Spring**
|
||||
- **Jackson**
|
||||
- **Ali-pay-sdk**
|
||||
- **Ali-pay-sdk**
|
||||
|
||||
## 开源协议
|
||||
|
||||
本项目采用Apache2.0开源协议。
|
||||
|
||||
## 免责声明
|
||||
|
||||
**<span style="color:red;">本项目涉及到资金交易,开发者需要经严格测试后方能用于生产环境,本项目不对使用者的行为负责。</span>**
|
||||
@@ -9,4 +9,7 @@
|
||||
|
||||
|
||||
[GitHub](https://github.com/NotFound403/payment-spring-boot)
|
||||
[Get Started](README.md)
|
||||
[技术博客](https://felord.cn)
|
||||
[快速开始](README.md)
|
||||
|
||||

|
||||
@@ -1 +1,5 @@
|
||||
* [快速接入](quick_start.md)
|
||||
* [首页](/)
|
||||
* [项目简介](README.md)
|
||||
* [快速接入](quick_start.md)
|
||||
* [日常踩坑](stackoverflow.md)
|
||||
* [更新日志](changelog.md)
|
||||
|
||||
8
docs/changelog.md
Normal file
8
docs/changelog.md
Normal file
@@ -0,0 +1,8 @@
|
||||
## 1.0.0.RELEASE
|
||||
|
||||
- 微信支付
|
||||
- 基础支付-商户直连
|
||||
- 代金券
|
||||
- 多租户
|
||||
- 支付宝
|
||||
- 仅仅引入支付宝SDK,后续维护以支付宝SDK变动为准
|
||||
@@ -6,13 +6,20 @@
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||
<meta name="description" content="Description">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
|
||||
<style>
|
||||
strong{
|
||||
color: #42b983;
|
||||
}
|
||||
</style>
|
||||
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<div id="app">加载中……</div>
|
||||
<script>
|
||||
window.$docsify = {
|
||||
coverpage: true,
|
||||
onlyCover: true,
|
||||
subMaxLevel: 3,
|
||||
loadSidebar: true,
|
||||
alias: {
|
||||
'/.*/_sidebar.md': '/_sidebar.md'
|
||||
|
||||
@@ -1,16 +1,29 @@
|
||||
### 集成
|
||||
以**Spring Boot Starter**的形式集成到项目中。
|
||||
## Maven中央仓库
|
||||
|
||||
> ❗注意:<span style= 'color:red;'>目前并没有上传到Maven中央仓库,等稳定后会进行支持。</span>
|
||||
|
||||
## 自行安装
|
||||
|
||||
以**Spring Boot Starter**的形式集成到项目中。从[GitHub项目地址](https://github.com/NotFound403/payment-spring-boot)拉取`release`分支到本地后使用以下两种方式之一进行环境集成:
|
||||
|
||||
- `mvn install` 安装到本地
|
||||
- `mvn deploy`部署到**Maven**仓库
|
||||
|
||||
|
||||
|
||||
然后引用**Maven**坐标,请注意`${payment-spring-boot-starter.version}`要同你安装的一致。
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>cn.felord</groupId>
|
||||
<artifactId>payment-spring-boot-starter</artifactId>
|
||||
<version>1.0.0.RELEASE</version>
|
||||
<version>${payment-spring-boot-starter.version}</version>
|
||||
</dependency>
|
||||
```
|
||||
### 配置
|
||||
#### 微信支付
|
||||
在Spring Boot项目中的`application.yaml`中配置`wechat.pay`相关参数。
|
||||
## 配置
|
||||
|
||||
### 微信支付
|
||||
在Spring Boot项目中的`application.yaml`中配置`wechat.pay.v3`相关参数。
|
||||
```yaml
|
||||
wechat:
|
||||
pay:
|
||||
@@ -19,43 +32,94 @@ wechat:
|
||||
<tentantID>:
|
||||
# 应用appId 必填
|
||||
app-id: xxxxxxxx
|
||||
# api 密钥 必填
|
||||
# api 密钥 可不填
|
||||
app-secret: xxxxxxxxxxx
|
||||
# api v3 密钥 必填
|
||||
app-v3-secret: xxxxxxxx
|
||||
# 微信支付商户号 必填
|
||||
mch-id: xxxxxxx
|
||||
# 合作商 选填
|
||||
partner-key:
|
||||
# 商户服务器域名 用于回调 需要放开回调接口的安全策略 必填
|
||||
domain: https://xxxx.xxx.com
|
||||
# 商户 api 证书 必填
|
||||
# 商户 api 证书路径 必填 填写classpath路径 位于 maven项目的resources文件下
|
||||
cert-path: apiclient_cert.p12
|
||||
|
||||
```
|
||||
然后启用`@EnableWechatPay`注解:
|
||||
#### <span style="color:red;">微信支付 tentantID 场景说明</span>
|
||||
|
||||
当项目中需要同时支持微信App支付、微信公众号支付、微信小程序支付时,上述配置中的`app-id`可能为多个,因此我们需要进行路由标识以区分它们,所以这里需要你定义一个`tentanID`来进行标识。假如我们同时有App支付和微信小程序支付,我们应该这样配置:
|
||||
|
||||
```yaml
|
||||
wechat:
|
||||
pay:
|
||||
v3:
|
||||
# App租户租户标识为 mobile
|
||||
mobile:
|
||||
app-id: wx524534x423234
|
||||
app-secret: felord
|
||||
app-v3-secret: 0e5b123323h12234927e455703ec
|
||||
mch-id: 1603337223
|
||||
domain: https://felord.cn/mobile
|
||||
cert-path: mobile/apiclient_cert.p12
|
||||
# 微信小程序租户标识为 miniapp
|
||||
miniapp:
|
||||
app-id: wx344123x3541223
|
||||
app-secret: felord
|
||||
app-v3-secret: 0e5b123323h12234927e455703ec
|
||||
mch-id: 1603337223
|
||||
domain: https://felord.cn/miniapp
|
||||
cert-path: miniapp/apiclient_cert.p12
|
||||
```
|
||||
|
||||
> ❗注意:在一套系统中需要开发者保证`tentanID`唯一。
|
||||
|
||||
### 支付宝
|
||||
|
||||
在Spring Boot项目中的`application.yaml`中配置`ali.pay.v1`相关参数。
|
||||
```yaml
|
||||
ali:
|
||||
pay:
|
||||
v1:
|
||||
# 可以替换为沙箱
|
||||
server-url: https://openapi.alipaydev.com/gateway.do
|
||||
# 蚂蚁开放平台申请并认证的应用appId
|
||||
app-id: 2016223700762343
|
||||
app-private-key-path: META-INF/app_rsa
|
||||
alipay-public-cert-path: META-INF/alipayCertPublicKey_RSA2.crt
|
||||
alipay-root-cert-path: META-INF/alipayRootCert.crt
|
||||
app-cert-public-key-path: META-INF/appCertPublicKey_2016102700769563.crt
|
||||
charset: utf-8
|
||||
format: json
|
||||
sign-type: RSA2
|
||||
```
|
||||
> ❗注意:只有`ali.pay.v1.app-id`设置了有效值才能启用支付宝API。
|
||||
|
||||
## 启用配置
|
||||
|
||||
配置完毕后需要启用`@EnableMobilePay`注解来开启支付功能:
|
||||
|
||||
```java
|
||||
@EnableMobilePay
|
||||
@Configuration
|
||||
public class PayConfig {
|
||||
}
|
||||
```
|
||||
> 请注意:只有`wechat.pay.v3.app-id`设置了有效值才能启用下面的API。
|
||||
##### API使用
|
||||
微信支付V3开放接口引入:
|
||||
## 使用API
|
||||
|
||||
### 微信支付
|
||||
|
||||
微信支付V3开放接口都是通过`WechatApiProvider`引入的,当[启用配置](/quick_start?id=启用配置)步骤完成后会被初始化并注入了**Spring IoC**,可通过如下形式引入:
|
||||
```java
|
||||
@Autowired
|
||||
WechatApiProvider wechatApiProvider;
|
||||
```
|
||||
###### V3
|
||||
例如V3 查询商户下的优惠券
|
||||
`WechatApiProvider`需要开发者明确租户ID[tenantID](quick_start?id=微信支付-tentantid-场景说明)以初始化具体场景的**Api**。例如查询终端用户在租户`mobile`下的优惠券:
|
||||
|
||||
```java
|
||||
// 查询商户下的优惠券
|
||||
@Test
|
||||
public void v3MchStocks() {
|
||||
// 配置文件中对应的tenantID:
|
||||
String tenantId =<tenantID>;
|
||||
String tenantId =“mobile”;
|
||||
StocksQueryParams params = new StocksQueryParams();
|
||||
params.setOffset(0);
|
||||
params.setLimit(10);
|
||||
@@ -66,46 +130,7 @@ public class PayConfig {
|
||||
|
||||
|
||||
#### 支付宝
|
||||
##### 使用须知
|
||||
请注意因为未来**SHA1withRSA**将被淘汰,因此采用最新的**SHA256withRSA**证书,旧的模式将不提供支持。步骤如下:
|
||||
|
||||
1.使用支付宝开发助手申请CSR文件
|
||||
|
||||

|
||||
申请成功后看文件说明:
|
||||
|
||||

|
||||
|
||||
2.上传CSR设置证书
|
||||
|
||||

|
||||
|
||||
上传成功后需要下载证书,和配置的对应关系为:
|
||||
|
||||

|
||||
3. 其它开发平台商户平台的配置,参考支付宝接入文档。
|
||||
##### 项目开发配置
|
||||
在Spring Boot项目中的`application.yaml`中配置`ali.pay`相关参数。
|
||||
```yaml
|
||||
ali:
|
||||
pay:
|
||||
v1:
|
||||
# 可以替换为沙箱
|
||||
server-url: https://openapi.alipaydev.com/gateway.do
|
||||
# 蚂蚁开放平台申请并认证的应用appId
|
||||
app-id: 2016102700769563
|
||||
app-private-key-path: META-INF/app_rsa
|
||||
alipay-public-cert-path: META-INF/alipayCertPublicKey_RSA2.crt
|
||||
alipay-root-cert-path: META-INF/alipayRootCert.crt
|
||||
app-cert-public-key-path: META-INF/appCertPublicKey_2016102700769563.crt
|
||||
charset: utf-8
|
||||
format: json
|
||||
sign-type: RSA2
|
||||
```
|
||||
> 请注意:只有`ali.pay.v1.app-id`设置了有效值才能启用下面的API。
|
||||
##### API的使用
|
||||
|
||||
引入接口:
|
||||
当[启用配置](/quick_start?id=启用配置)步骤完成后会初始化支付宝支付客户端接口`AlipayClient`并注入**Spring IoC**,可通过以下形式引入:
|
||||
```java
|
||||
@Autowired
|
||||
AlipayClient alipayClient;
|
||||
@@ -131,13 +156,4 @@ ali:
|
||||
|
||||
System.out.println("execute = " + execute.getBody());
|
||||
}
|
||||
```
|
||||
打印响应体:
|
||||
```json
|
||||
{"alipay_marketing_campaign_cash_create_response":{"code":"40004","msg":"Business Failed","sub_code":"isv.UNKNOW_SYSTEM_ERROR","sub_msg":"系统繁忙,请稍后再试"},"alipay_cert_sn":"e65893247c520d9d46db3000158505ee","sign":"M7gyi6ZwnRoHmdzd1IIxLc+XEE1pCx6ptOyQP4aRGMc01bJebNL7PbMpfU7TcB75KHmk3Oor2fYZfVEB7+5gxV9YwMuW3QtZbyACw3Gzt7wz4D1YCXkQD9PRvSsgw8xgNL+WnZxEI2yFdSp47Mc/Um73M101zFeo2dYKYXyVRdsGxnipY8fZs0JaXlX5OoROfHDcbvzBDjQyernspIoFoNiAwpaBwyQcEzh8V34ca4Rep/LSyI4N4VtU0n2nq3dO0Jor36n0o4j0QobWSE3c8StkVjbdP5XJB+adE51MUmh7xDdixQXE2fTRKw5wYlBO9O3bpF/uw78hWW/y3JwG9Q=="}
|
||||
```
|
||||
## CHANGELOG
|
||||
### 1.0.0.RELEASE
|
||||
|
||||
- 支持微信支付V3、支付宝支付
|
||||
- 微信支付多租户
|
||||
```
|
||||
25
docs/stackoverflow.md
Normal file
25
docs/stackoverflow.md
Normal file
@@ -0,0 +1,25 @@
|
||||
## 微信
|
||||
|
||||
施工中……
|
||||
|
||||
## 支付宝
|
||||
|
||||
### 证书
|
||||
|
||||
请注意因为未来**SHA1withRSA**将被淘汰,因此采用最新的**SHA256withRSA**证书,旧的模式将不提供支持。步骤如下:
|
||||
|
||||
1.使用支付宝开发助手申请CSR文件
|
||||
|
||||

|
||||
申请成功后看文件说明:
|
||||
|
||||

|
||||
|
||||
2.上传CSR设置证书
|
||||
|
||||

|
||||
|
||||
上传成功后需要下载证书,和配置的对应关系为:
|
||||
|
||||

|
||||
|
||||
@@ -51,27 +51,5 @@ public class WechatPayProperties {
|
||||
* your pay server domain
|
||||
*/
|
||||
private String domain;
|
||||
/**
|
||||
* app in winxin open platform
|
||||
*/
|
||||
private App app;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* wechat mp for send coupons and notification.
|
||||
*/
|
||||
@Data
|
||||
public static class App {
|
||||
/**
|
||||
* app id
|
||||
*/
|
||||
private String appId;
|
||||
/**
|
||||
* app secret
|
||||
*/
|
||||
private String appSecret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -95,6 +95,8 @@ public class WechatDirectPayApi extends AbstractApi {
|
||||
WechatPayProperties.V3 v3 = this.wechatMetaBean().getV3();
|
||||
payParams.setAppid(v3.getAppId());
|
||||
payParams.setMchid(v3.getMchId());
|
||||
String notifyUrl = v3.getDomain().concat(payParams.getNotifyUrl());
|
||||
payParams.setNotifyUrl(notifyUrl);
|
||||
URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA))
|
||||
.build()
|
||||
.toUri();
|
||||
|
||||
Reference in New Issue
Block a user