mirror of
https://github.com/dromara/payment-spring-boot.git
synced 2026-03-14 05:43:46 +08:00
docs
This commit is contained in:
0
docs/.nojekyll
Normal file
0
docs/.nojekyll
Normal file
1
docs/README.md
Normal file
1
docs/README.md
Normal file
@@ -0,0 +1 @@
|
||||
123123
|
||||
16
docs/_coverpage.md
Normal file
16
docs/_coverpage.md
Normal file
@@ -0,0 +1,16 @@
|
||||
<!-- _coverpage.md -->
|
||||
|
||||
|
||||
|
||||
# payment spring boot
|
||||
|
||||
> Spring Boot 风格支付开发包。
|
||||
|
||||
- 快速接入微信支付V3、支付宝支付
|
||||
- Spring Boot Starter 风格
|
||||
- 配置简单、只依赖Spring框架
|
||||
|
||||
|
||||
[GitHub](https://github.com/docsifyjs/docsify/)
|
||||
[GitHub](https://github.com/docsifyjs/docsify/)
|
||||
[Get Started](/quick_start.md)
|
||||
2
docs/_sidebar.md
Normal file
2
docs/_sidebar.md
Normal file
@@ -0,0 +1,2 @@
|
||||
* [项目简介](guide.md)
|
||||
* [快速接入](quick_start.md)
|
||||
27
docs/guide.md
Normal file
27
docs/guide.md
Normal file
@@ -0,0 +1,27 @@
|
||||
## 缘由
|
||||
|
||||
大部分的 **Java Web** 项目都会使用 **Spring**,尤其是 **Spring Boot**。所以笔者在开发过程中萌生一种直接构建于Spring依赖之上的支付开发包的想法。由于支付宝已经提供了SDK,所以只要将其初始化委托给 **Spring** 即可。剩下的硬骨头就是微信支付了。笔者最开始实现微信支付的时候刚好**微信支付V3**版本的 **API**公布了。相比较于 **V2**版本:
|
||||
|
||||
- [x] 遵循统一的 **Restful** 的设计风格
|
||||
- [x] 使用 **JSON** 作为数据交互的格式,不再使用XML
|
||||
- [x] 使用基于非对称密钥的 **SHA256-RSA** 的数字签名算法,不再使用 **MD5** 或 **HMAC-SHA256**
|
||||
- [x] 不再要求 **HTTPS** 客户端证书
|
||||
- [x] 使用 **AES-256-GCM**,对回调中的关键信息进行加密保护
|
||||
|
||||
这种开发体验要远远好于之前的 **V2**,因此选择了微信支付V3。
|
||||
|
||||
## 目前支持的渠道
|
||||
|
||||
- [x] **微信支付V3** 全量支持,并支持多租户以同时满足移动应用App、公众号、小程序等支付场景
|
||||
- [x] **支付宝** 集成SDK,作简单适配
|
||||
|
||||
## 微信支付V3进度
|
||||
- 微信支付营销-代金券 `WechatMarketingFavorApi` 100%
|
||||
- 微信支付 支付功能-普通支付直连模式 `WechatDirectPayApi` 100%
|
||||
|
||||
## 采用技术
|
||||
只依赖了 **Spring**已有的东西,做到了低依赖。
|
||||
|
||||
- **Spring**
|
||||
- **Jackson**
|
||||
- **Ali-pay-sdk**
|
||||
BIN
docs/img/cert_path.png
Normal file
BIN
docs/img/cert_path.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 37 KiB |
BIN
docs/img/csr.png
Normal file
BIN
docs/img/csr.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 53 KiB |
BIN
docs/img/file_info.png
Normal file
BIN
docs/img/file_info.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
BIN
docs/img/set.png
Normal file
BIN
docs/img/set.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 39 KiB |
31
docs/index.html
Normal file
31
docs/index.html
Normal file
@@ -0,0 +1,31 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Document</title>
|
||||
<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">
|
||||
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script>
|
||||
window.$docsify = {
|
||||
coverpage: true,
|
||||
loadSidebar: true,
|
||||
alias: {
|
||||
'/.*/_sidebar.md': '/_sidebar.md'
|
||||
},
|
||||
name: '',
|
||||
repo: ''
|
||||
}
|
||||
</script>
|
||||
<!-- Docsify v4 -->
|
||||
<script src="//cdn.jsdelivr.net/npm/docsify@4"></script>
|
||||
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-bash.min.js"></script>
|
||||
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-java.min.js"></script>
|
||||
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-yaml.min.js"></script>
|
||||
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-json.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
143
docs/quick_start.md
Normal file
143
docs/quick_start.md
Normal file
@@ -0,0 +1,143 @@
|
||||
### 集成
|
||||
以**Spring Boot Starter**的形式集成到项目中。
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>cn.felord</groupId>
|
||||
<artifactId>payment-spring-boot-starter</artifactId>
|
||||
<version>1.0.0.RELEASE</version>
|
||||
</dependency>
|
||||
```
|
||||
### 配置
|
||||
#### 微信支付
|
||||
在Spring Boot项目中的`application.yaml`中配置`wechat.pay`相关参数。
|
||||
```yaml
|
||||
wechat:
|
||||
pay:
|
||||
v3:
|
||||
# 租户id
|
||||
<tentantID>:
|
||||
# 应用appId 必填
|
||||
app-id: xxxxxxxx
|
||||
# api 密钥 必填
|
||||
app-secret: xxxxxxxxxxx
|
||||
# api v3 密钥 必填
|
||||
app-v3-secret: xxxxxxxx
|
||||
# 微信支付商户号 必填
|
||||
mch-id: xxxxxxx
|
||||
# 合作商 选填
|
||||
partner-key:
|
||||
# 商户服务器域名 用于回调 需要放开回调接口的安全策略 必填
|
||||
domain: https://xxxx.xxx.com
|
||||
# 商户 api 证书 必填
|
||||
cert-path: apiclient_cert.p12
|
||||
|
||||
```
|
||||
然后启用`@EnableWechatPay`注解:
|
||||
```java
|
||||
@EnableMobilePay
|
||||
@Configuration
|
||||
public class PayConfig {
|
||||
}
|
||||
```
|
||||
> 请注意:只有`wechat.pay.v3.app-id`设置了有效值才能启用下面的API。
|
||||
##### API使用
|
||||
微信支付V3开放接口引入:
|
||||
```java
|
||||
@Autowired
|
||||
WechatApiProvider wechatApiProvider;
|
||||
```
|
||||
###### V3
|
||||
例如V3 查询商户下的优惠券
|
||||
|
||||
```java
|
||||
// 查询商户下的优惠券
|
||||
@Test
|
||||
public void v3MchStocks() {
|
||||
// 配置文件中对应的tenantID:
|
||||
String tenantId =<tenantID>;
|
||||
StocksQueryParams params = new StocksQueryParams();
|
||||
params.setOffset(0);
|
||||
params.setLimit(10);
|
||||
WechatResponseEntity<ObjectNode> objectNodeWechatResponseEntity = wechatApiProvider.favorApi(tenantId).queryStocksByMch(params);
|
||||
System.out.println("objectNodeWechatResponseEntity = " + objectNodeWechatResponseEntity);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
#### 支付宝
|
||||
##### 使用须知
|
||||
请注意因为未来**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的使用
|
||||
|
||||
引入接口:
|
||||
```java
|
||||
@Autowired
|
||||
AlipayClient alipayClient;
|
||||
```
|
||||
调用,以现金红包为例:
|
||||
```java
|
||||
@SneakyThrows
|
||||
public void campaignCash() {
|
||||
AlipayMarketingCampaignCashCreateRequest request = new AlipayMarketingCampaignCashCreateRequest();
|
||||
request.setBizContent("{" +
|
||||
"\"coupon_name\":\"XXX周年庆红包\"," +
|
||||
"\"prize_type\":\"random\"," +
|
||||
"\"total_money\":\"10000.00\"," +
|
||||
"\"total_num\":\"1000\"," +
|
||||
"\"prize_msg\":\"XXX送您大红包\"," +
|
||||
"\"start_time\":\"2020-11-02 22:48:30\"," +
|
||||
"\"end_time\":\"2020-12-01 22:48:30\"," +
|
||||
"\"merchant_link\":\"http://www.weibo.com\"," +
|
||||
"\"send_freqency\":\"D3|L10\"" +
|
||||
" }");
|
||||
|
||||
AlipayMarketingCampaignCashCreateResponse execute = alipayClient.certificateExecute(request);
|
||||
|
||||
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、支付宝支付
|
||||
- 微信支付多租户
|
||||
Reference in New Issue
Block a user