diff --git a/README.md b/README.md index 56978d2..b2a8ef4 100644 --- a/README.md +++ b/README.md @@ -87,18 +87,18 @@ public class PayConfig { 1.使用支付宝开发助手申请CSR文件 -![先申请密钥对,再申请csr](./img/csr.png) +![先申请密钥对,再申请csr](docs/img/csr.png) 申请成功后看文件说明: -![](./img/file_info.png) +![](docs/img/file_info.png) 2.上传CSR设置证书 -![](./img/set.png) +![](docs/img/set.png) 上传成功后需要下载证书,和配置的对应关系为: -![](./img/cert_path.png) +![](docs/img/cert_path.png) 3. 其它开发平台商户平台的配置,参考支付宝接入文档。 ##### 项目开发配置 在Spring Boot项目中的`application.yaml`中配置`ali.pay`相关参数。 diff --git a/docs/.nojekyll b/docs/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..93a5f6a --- /dev/null +++ b/docs/README.md @@ -0,0 +1 @@ +123123 \ No newline at end of file diff --git a/docs/_coverpage.md b/docs/_coverpage.md new file mode 100644 index 0000000..606940a --- /dev/null +++ b/docs/_coverpage.md @@ -0,0 +1,16 @@ + + + + +# 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) \ No newline at end of file diff --git a/docs/_sidebar.md b/docs/_sidebar.md new file mode 100644 index 0000000..cc91107 --- /dev/null +++ b/docs/_sidebar.md @@ -0,0 +1,2 @@ +* [项目简介](guide.md) +* [快速接入](quick_start.md) \ No newline at end of file diff --git a/docs/guide.md b/docs/guide.md new file mode 100644 index 0000000..5dd5622 --- /dev/null +++ b/docs/guide.md @@ -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** \ No newline at end of file diff --git a/img/cert_path.png b/docs/img/cert_path.png similarity index 100% rename from img/cert_path.png rename to docs/img/cert_path.png diff --git a/img/csr.png b/docs/img/csr.png similarity index 100% rename from img/csr.png rename to docs/img/csr.png diff --git a/img/file_info.png b/docs/img/file_info.png similarity index 100% rename from img/file_info.png rename to docs/img/file_info.png diff --git a/img/set.png b/docs/img/set.png similarity index 100% rename from img/set.png rename to docs/img/set.png diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..4859372 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,31 @@ + + + + + Document + + + + + + +
+ + + + + + + + + diff --git a/docs/quick_start.md b/docs/quick_start.md new file mode 100644 index 0000000..b4f4b40 --- /dev/null +++ b/docs/quick_start.md @@ -0,0 +1,143 @@ +### 集成 +以**Spring Boot Starter**的形式集成到项目中。 + +```xml + + cn.felord + payment-spring-boot-starter + 1.0.0.RELEASE + +``` +### 配置 +#### 微信支付 +在Spring Boot项目中的`application.yaml`中配置`wechat.pay`相关参数。 +```yaml +wechat: + pay: + v3: +# 租户id + : +# 应用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 =; + StocksQueryParams params = new StocksQueryParams(); + params.setOffset(0); + params.setLimit(10); + WechatResponseEntity objectNodeWechatResponseEntity = wechatApiProvider.favorApi(tenantId).queryStocksByMch(params); + System.out.println("objectNodeWechatResponseEntity = " + objectNodeWechatResponseEntity); + } +``` + + +#### 支付宝 +##### 使用须知 +请注意因为未来**SHA1withRSA**将被淘汰,因此采用最新的**SHA256withRSA**证书,旧的模式将不提供支持。步骤如下: + +1.使用支付宝开发助手申请CSR文件 + +![先申请密钥对,再申请csr](./img/csr.png) +申请成功后看文件说明: + +![](./img/file_info.png) + +2.上传CSR设置证书 + +![](./img/set.png) + +上传成功后需要下载证书,和配置的对应关系为: + +![](./img/cert_path.png) +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、支付宝支付 +- 微信支付多租户 \ No newline at end of file