21 Commits

Author SHA1 Message Date
felord.cn
54a0822c73 ci: github action support 2021-03-23 00:37:08 +08:00
felord.cn
8d130e5df1 fix: remove unused files 2021-03-23 00:25:44 +08:00
felord.cn
e0eacd523e feat: upgrade to 1.0.9 2021-03-23 00:23:08 +08:00
felord.cn
d1068c1fb6 fix: 支付分支付成功回调反序列化异常
Closes #21
2021-03-23 00:23:08 +08:00
felord.cn
82bcc11dad fix: 修复枚举空指针问题
Closes #22
2021-03-23 00:23:08 +08:00
felord.cn
911f986d80 refactor: WechatPartnerPayApi 加入Spring IOC 2021-03-23 00:23:08 +08:00
felord.cn
b913698884 Create main.yml
ci: github action
2021-03-23 00:15:40 +08:00
felord.cn
34e5443e88 ci: github action support 2021-03-23 00:12:53 +08:00
felord.cn
f4dc70e828 docs: docs update 2021-03-11 18:40:10 +08:00
felord.cn
39716c30e4 feat: 对基础支付-服务商支付进行支持
目前微信官方还不支持V3的服务商退款
2021-03-11 18:40:10 +08:00
felord.cn
ab13d90b9b fix: 查询并下载转账电子回单API接口,下载文件接口签名失败
微信协议不统一造成的不兼容,1.0.8发布会修正这个问题。

Closes #18
2021-03-11 18:40:10 +08:00
felord.cn
4f71f419a7 refactor: 在异常返回时对非2xx状态返回的元信息进行包装方便序列化
用户需要判断非空

Closes #16
2021-03-11 18:40:10 +08:00
felord.cn
ec77604b99 fix: 修复类成员的属性
Closes #14
2021-03-11 18:40:10 +08:00
felord.cn
ff5911205b refactor: upgrade to 1.0.8 2021-03-11 18:40:10 +08:00
felord.cn
22d83edb89 fix: 修复类成员的属性
Closes #14
2021-03-11 18:40:10 +08:00
felord.cn
64d8294758 fix: 修复退款数据中时间无法解析的异常
这个问题是 Jackson在进行反序列化的时候需要声明对Java 8 时间包的支持。

Closes #13
2021-03-11 18:40:10 +08:00
felord.cn
cecee81b08 fix: 修复退款数据中时间无法解析的异常
这个问题是 Jackson在进行反序列化的时候需要声明对Java 8 时间包的支持。

Closes #13
2021-03-11 18:40:10 +08:00
felord.cn
6276b24c9f docs: docs update 2021-03-11 18:40:10 +08:00
felord.cn
282a60e3bb fix: 修复退款数据中时间无法解析的异常
这个问题是 Jackson在进行反序列化的时候需要声明对Java 8 时间包的支持。

Closes #13
2021-03-11 18:40:10 +08:00
felord.cn
2e143302e8 docs: changelog 2021-03-01 08:13:44 +08:00
felord.cn
9fba48d52d docs: changelog 2021-03-01 08:12:38 +08:00
28 changed files with 677 additions and 94 deletions

33
.github/workflows/main.yml vendored Normal file
View File

@@ -0,0 +1,33 @@
name: Maven Central Repo Deployment
# 当 release 的时候触发
on:
release:
types: [released]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Maven Central Repo
uses: actions/setup-java@v1
with:
java-version: 1.8
server-id: sonatype-nexus-staging
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
- id: install-secret-key
name: Install GPG Secret Key
run: |
cat <(echo -e "${{ secrets.GPG_PUB }}") | gpg --batch --import
gpg --list-secret-keys --keyid-format LONG
- id: publish-to-central
name: Publish to Maven Central Repo
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USER }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
run: |
mvn \
--no-transfer-progress \
--batch-mode \
-Dgpg.passphrase=${{ secrets.GPG_PASSWORD }} \
clean deploy

View File

@@ -11,7 +11,7 @@
<dependency>
<groupId>cn.felord</groupId>
<artifactId>payment-spring-boot-starter</artifactId>
<version>1.0.7.RELEASE</version>
<version>1.0.9.RELEASE</version>
</dependency>
```

View File

@@ -35,7 +35,7 @@
<dependency>
<groupId>cn.felord</groupId>
<artifactId>payment-spring-boot-starter</artifactId>
<version>1.0.7.RELEASE</version>
<version>1.0.9.RELEASE</version>
</dependency>
```
## 采用技术

View File

@@ -1,10 +1,31 @@
## 1.0.8.RELEASE
- 微信支付
- feat: 对基础支付-服务商支付进行支持
- refactor: 在异常返回时对非2xx状态返回的元信息进行包装方便序列化([#16](https://github.com/NotFound403/payment-spring-boot/issues/16))
- fix: 修复退款数据中时间无法解析的异常([#13](https://github.com/NotFound403/payment-spring-boot/issues/13))
- fix: 修复类成员的属性([#14](https://github.com/NotFound403/payment-spring-boot/issues/14))
- fix: 查询并下载转账电子回单API接口下载文件接口签名失败([#18](https://github.com/NotFound403/payment-spring-boot/issues/18))
## 1.0.7.RELEASE
- 微信支付
- refactor: X509证书加载优化。
- refactor: 移除过期的`WechatPayRefundApi`
- refactor: 优化RestTemplate在低版本引起的一个I/O异常,详见 [spring-framework#21321](https://github.com/spring-projects/spring-framework/issues/21321)。
- refactor: 在请求头Content-Type中声明字符集UTF-8,避免中文乱码。
- fix: 修复退款回调中退款状态枚举无法正确被解析的异常([#11](https://github.com/NotFound403/payment-spring-boot/issues/11))。
## 1.0.6.RELEASE
- 微信支付
- feat:实现微信支付V3批量转账到零钱所有APIWechatBatchTransferApi助力抗击新冠疫情。
- feat:实现微信支付V3退款以及退款通知等所有退款相关的API推荐使用新的V3退款。
- refactor: V2退款进入过期模式由于V3已经推出了退款功能所以V2退款 WechatPayRefundApi 被标记为 Deprecated 未来会被移除。
- refactor: 交易状态增加等待扣款状态,根据微信最新的业务变动增加 “ACCEPT” 字段用来标记“已接收,等待扣款”状态。
## 1.0.5.RELEASE
- 微信支付
- feat:增加V2退款接口
- feat:增加V2企业付款到零钱接口
@@ -15,6 +36,7 @@
- fix: 关单接口调用异常
## 1.0.4.RELEASE
- 微信支付
- feat: 增加微信支付商家券相关接口`WechatMarketingBusiFavorApi`,商家券请阅读相关产品文档。
- feat: 代金券功能增加发放消费卡接口。
@@ -24,6 +46,7 @@
- fix: 支付分`RiskFund`下枚举无法使用的问题[(#2)](https://github.com/NotFound403/payment-spring-boot/issues/2)。
## 1.0.3.RELEASE
- 微信支付
- feat: 完善合单支付账单
1. 增加合单支付-申请交易账单API。

View File

@@ -4,7 +4,7 @@
<dependency>
<groupId>cn.felord</groupId>
<artifactId>payment-spring-boot-starter</artifactId>
<version>1.0.7.RELEASE</version>
<version>1.0.9.RELEASE</version>
</dependency>
```
> 基于 **Spring Boot 2.x**
@@ -48,13 +48,13 @@ wechat:
v3:
# 租户id
<tentantID>:
# 应用appId 必填
# 应用appId 服务商模式下为服务商的appid 必填
app-id: xxxxxxxx
# v2 api 密钥 1.0.5版本以后如果用到V2的接口时必填
app-secret: xxxxxxxxxxx
# api v3 密钥 必填
app-v3-secret: xxxxxxxx
# 微信支付商户号 必填
# 微信支付商户号 服务商模式下为服务商的mchid 必填
mch-id: xxxxxxx
# 商户服务器域名 用于回调 需要放开回调接口的安全策略 必填
domain: https://felord.cn

View File

@@ -5,11 +5,11 @@
<parent>
<groupId>cn.felord</groupId>
<artifactId>payment-spring-boot</artifactId>
<version>1.0.7.RELEASE</version>
<version>1.0.9.RELEASE</version>
</parent>
<artifactId>payment-spring-boot-autoconfigure</artifactId>
<version>1.0.7.RELEASE</version>
<version>1.0.9.RELEASE</version>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>

View File

@@ -18,11 +18,17 @@
*/
package cn.felord.payment;
import org.springframework.http.ResponseEntity;
/**
* @author felord.cn
* @since 1.0.0.RELEASE
*/
public class PayException extends RuntimeException {
/**
* response maybe null
*/
private ResponseEntity<?> response;
public PayException() {
}
@@ -42,4 +48,12 @@ public class PayException extends RuntimeException {
public PayException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
public ResponseEntity<?> getResponse() {
return response;
}
public void setResponse(ResponseEntity<?> response) {
this.response = response;
}
}

View File

@@ -486,7 +486,57 @@ public enum WechatPayV3Type {
*
* @since 1.0.6.RELEASES
*/
BATCH_TRANSFER_DOWNLOAD_BILL(HttpMethod.GET, "%s/v3/transfer/bill-receipt/{out_batch_no}");
BATCH_TRANSFER_DOWNLOAD_BILL(HttpMethod.GET, "%s/v3/transfer/bill-receipt/{out_batch_no}"),
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* 服务商APP下单API.
*
* @since 1.0.8.RELEASES
*/
APP_PARTNER(HttpMethod.POST, "%s/v3/pay/partner/transactions/app"),
/**
* 微信公众号支付或者小程序支付.
*
* @since 1.0.8.RELEASE
*/
JSAPI_PARTNER(HttpMethod.POST, "%s/v3/pay/partner/transactions/jsapi"),
/**
* 微信扫码支付.
*
* @since 1.0.8.RELEASE
*/
NATIVE_PARTNER(HttpMethod.POST, "%s/v3/pay/partner/transactions/native"),
/**
* H5支付.
*
* @since 1.0.8.RELEASE
*/
MWEB_PARTNER(HttpMethod.POST, "%s/v3/pay/partner/transactions/h5"),
/**
* 关闭订单.
*
* @since 1.0.0.RELEASE
*/
CLOSE_PARTNER(HttpMethod.POST, "%s/v3/pay/partner/transactions/out-trade-no/{out_trade_no}/close"),
/**
* 微信支付订单号查询API.
*
* @since 1.0.0.RELEASE
*/
TRANSACTION_TRANSACTION_ID_PARTNER(HttpMethod.GET, "%s/v3/pay/partner/transactions/id/{transaction_id}"),
/**
* 商户订单号查询API.
*
* @since 1.0.0.RELEASE
*/
TRANSACTION_OUT_TRADE_NO_PARTNER(HttpMethod.GET, "%s/v3/pay/partner/transactions/out-trade-no/{out_trade_no}"),
;
/**
* The Pattern.
*

View File

@@ -120,6 +120,7 @@ public class SignatureProvider {
/**
* 我方请求前用 SHA256withRSA 加签使用API证书.
*
* @param newLine the new line
* @param tenantId the properties key
* @param method the method
* @param canonicalUrl the canonical url
@@ -127,7 +128,7 @@ public class SignatureProvider {
* @return the string
*/
@SneakyThrows
public String requestSign(String tenantId, String method, String canonicalUrl, String body) {
public String requestSign(boolean newLine,String tenantId, String method, String canonicalUrl, String body) {
long timestamp = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"));
String nonceStr = nonceStrGenerator.generateId()
@@ -135,7 +136,7 @@ public class SignatureProvider {
.replaceAll("-", "");
WechatMetaBean wechatMetaBean = wechatMetaContainer.getWechatMeta(tenantId);
PrivateKey privateKey = wechatMetaBean.getKeyPair().getPrivate();
String encode = this.doRequestSign(privateKey, method, canonicalUrl, String.valueOf(timestamp), nonceStr, body);
String encode = this.doRequestSign(newLine,privateKey, method, canonicalUrl, String.valueOf(timestamp), nonceStr, body);
// 序列号
String serialNo = wechatMetaBean.getSerialNumber();
// 生成token
@@ -149,16 +150,17 @@ public class SignatureProvider {
/**
* Do request sign.
*
* @param newLine the has suffix
* @param privateKey the private key
* @param orderedComponents the orderedComponents
* @return the string
* @since 1.0.4.RELEASE
*/
@SneakyThrows
public String doRequestSign(PrivateKey privateKey, String... orderedComponents) {
public String doRequestSign(boolean newLine,PrivateKey privateKey, String... orderedComponents) {
Signature signer = Signature.getInstance("SHA256withRSA", BC_PROVIDER);
signer.initSign(privateKey);
final String signatureStr = createSign(orderedComponents);
final String signatureStr = createSign(newLine,orderedComponents);
signer.update(signatureStr.getBytes(StandardCharsets.UTF_8));
return Base64Utils.encodeToString(signer.sign());
}
@@ -178,7 +180,7 @@ public class SignatureProvider {
}
Certificate certificate = CERTIFICATE_MAP.get(wechatpaySerial);
final String signatureStr = createSign(params.getWechatpayTimestamp(), params.getWechatpayNonce(), params.getBody());
final String signatureStr = createSign(true,params.getWechatpayTimestamp(), params.getWechatpayNonce(), params.getBody());
Signature signer = Signature.getInstance("SHA256withRSA");
signer.initVerify(certificate);
signer.update(signatureStr.getBytes(StandardCharsets.UTF_8));
@@ -206,7 +208,7 @@ public class SignatureProvider {
}
// 签名
HttpMethod httpMethod = WechatPayV3Type.CERT.method();
String authorization = requestSign(tenantId, httpMethod.name(), canonicalUrl, "");
String authorization = requestSign(true,tenantId, httpMethod.name(), canonicalUrl, "");
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
@@ -278,7 +280,7 @@ public class SignatureProvider {
/**
* 对请求敏感字段进行加密
*
* @param message the message
* @param message the message
* @param certificate the certificate
* @return encrypt message
* @since 1.0.6.RELEASE
@@ -297,6 +299,11 @@ public class SignatureProvider {
}
}
/**
* Get certificate x 509 wechat certificate info.
*
* @return the x 509 wechat certificate info
*/
public X509WechatCertificateInfo getCertificate(){
for (String serial : CERTIFICATE_MAP.keySet()) {
X509Certificate x509Cert = (X509Certificate) CERTIFICATE_MAP.get(serial);
@@ -341,9 +348,11 @@ public class SignatureProvider {
* @param components the components
* @return string string
*/
private static String createSign(String... components) {
private static String createSign(boolean newLine,String... components) {
String suffix = newLine? "\n":"";
return Arrays.stream(components)
.collect(Collectors.joining("\n", "", "\n"));
.collect(Collectors.joining("\n", "", suffix));
}
}

View File

@@ -65,6 +65,18 @@ public class WechatApiProvider {
return new WechatDirectPayApi(wechatPayClient, tenantId);
}
/**
* 普通支付-服务商模式.
*
* @param tenantId the tenant id
* @return the wechat pay api
* @since 1.0.9.RELEASE
*/
public WechatPartnerPayApi partnerPayApi(String tenantId) {
return new WechatPartnerPayApi(wechatPayClient, tenantId);
}
/**
* 合单支付.
*

View File

@@ -87,7 +87,7 @@ public class WechatDirectPayApi extends AbstractApi {
.toString()
.replaceAll("-", "");
String prepayId = body.get("prepay_id").asText();
String paySign = signatureProvider.doRequestSign(privateKey, appId, timestamp, nonceStr, prepayId);
String paySign = signatureProvider.doRequestSign(true,privateKey, appId, timestamp, nonceStr, prepayId);
String mchId = wechatMetaBean.getV3().getMchId();
body.put("appid", appId);
@@ -136,7 +136,7 @@ public class WechatDirectPayApi extends AbstractApi {
.toString()
.replaceAll("-", "");
String packageStr = "prepay_id=" + body.get("prepay_id").asText();
String paySign = signatureProvider.doRequestSign(privateKey, appId, timestamp, nonceStr, packageStr);
String paySign = signatureProvider.doRequestSign(true,privateKey, appId, timestamp, nonceStr, packageStr);
body.put("appId", appId);
body.put("timeStamp", timestamp);

View File

@@ -30,6 +30,7 @@ import org.springframework.util.StringUtils;
import org.springframework.web.util.UriComponentsBuilder;
import java.net.URI;
import java.util.Optional;
/**
* 微信支付商家券.
@@ -146,7 +147,10 @@ public class WechatMarketingBusiFavorApi extends AbstractApi {
queryParams.add("appid", appid);
}
queryParams.add("stock_id", userBusiFavorQueryParams.getStockId());
queryParams.add("coupon_state", userBusiFavorQueryParams.getCouponState().name());
Optional.ofNullable(userBusiFavorQueryParams.getCouponState())
.ifPresent(state-> queryParams.add("coupon_state", state.name()));
queryParams.add("creator_merchant", userBusiFavorQueryParams.getCreatorMerchant());
queryParams.add("belong_merchant", userBusiFavorQueryParams.getBelongMerchant());
queryParams.add("sender_merchant", userBusiFavorQueryParams.getSenderMerchant());

View File

@@ -0,0 +1,276 @@
/*
* Copyright 2019-2021 felord.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
*
* https://www.apache.org/licenses/LICENSE-2.0
* Website:
* https://felord.cn
* 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.
*/
package cn.felord.payment.wechat.v3;
import cn.felord.payment.PayException;
import cn.felord.payment.wechat.WechatPayProperties;
import cn.felord.payment.wechat.enumeration.WeChatServer;
import cn.felord.payment.wechat.enumeration.WechatPayV3Type;
import cn.felord.payment.wechat.v3.model.TransactionQueryParams;
import cn.felord.payment.wechat.v3.model.partner.CloseTransParams;
import cn.felord.payment.wechat.v3.model.partner.PartnerPayParams;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.springframework.http.RequestEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.util.UriComponentsBuilder;
import java.net.URI;
import java.security.PrivateKey;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
* 普通支付-服务商模式
*
* @author felord.cn
* @since 1.0.8.RELEASE
*/
public class WechatPartnerPayApi extends AbstractApi {
/**
* Instantiates a new Abstract api.
*
* @param wechatPayClient the wechat pay client
* @param tenantId the tenant id
*/
public WechatPartnerPayApi(WechatPayClient wechatPayClient, String tenantId) {
super(wechatPayClient, tenantId);
}
/**
* APP下单API
*
* @param partnerPayParams the partner pay params
* @return the wechat response entity
* @since 1.0.8.RELEASE
*/
public WechatResponseEntity<ObjectNode> appPay(PartnerPayParams partnerPayParams) {
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
this.client().withType(WechatPayV3Type.APP_PARTNER, partnerPayParams)
.function(this::payFunction)
.consumer(responseEntity -> {
ObjectNode body = responseEntity.getBody();
if (Objects.isNull(body)) {
throw new PayException("response body cannot be resolved");
}
SignatureProvider signatureProvider = this.client().signatureProvider();
WechatMetaContainer wechatMetaContainer = signatureProvider.wechatMetaContainer();
WechatMetaBean wechatMetaBean = wechatMetaContainer.getWechatMeta(tenantId());
PrivateKey privateKey = wechatMetaBean.getKeyPair().getPrivate();
String subAppid = partnerPayParams.getSubAppid();
long epochSecond = LocalDateTime.now()
.toEpochSecond(ZoneOffset.of("+8"));
String timestamp = String.valueOf(epochSecond);
String nonceStr = signatureProvider.nonceStrGenerator()
.generateId()
.toString()
.replaceAll("-", "");
String prepayId = body.get("prepay_id").asText();
String paySign = signatureProvider.doRequestSign(true, privateKey, subAppid, timestamp, nonceStr, prepayId);
body.put("appid", subAppid);
body.put("partnerid", partnerPayParams.getSubMchid());
body.put("prepayid", prepayId);
body.put("package", "Sign=WXPay");
body.put("nonceStr", nonceStr);
body.put("timeStamp", timestamp);
body.put("signType", "RSA");
body.put("paySign", paySign);
wechatResponseEntity.setHttpStatus(responseEntity.getStatusCodeValue());
wechatResponseEntity.setBody(body);
})
.request();
return wechatResponseEntity;
}
/**
* JSAPI/小程序下单API
*
* @param partnerPayParams the pay params
* @return wechat response entity
* @since 1.0.8.RELEASE
*/
public WechatResponseEntity<ObjectNode> jsPay(PartnerPayParams partnerPayParams) {
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
this.client().withType(WechatPayV3Type.JSAPI_PARTNER, partnerPayParams)
.function(this::payFunction)
.consumer(responseEntity -> {
ObjectNode body = responseEntity.getBody();
if (Objects.isNull(body)) {
throw new PayException("response body cannot be resolved");
}
SignatureProvider signatureProvider = this.client().signatureProvider();
WechatMetaContainer wechatMetaContainer = signatureProvider.wechatMetaContainer();
WechatMetaBean wechatMetaBean = wechatMetaContainer.getWechatMeta(tenantId());
PrivateKey privateKey = wechatMetaBean.getKeyPair().getPrivate();
String subAppid = partnerPayParams.getSubAppid();
long epochSecond = LocalDateTime.now()
.toEpochSecond(ZoneOffset.of("+8"));
String timestamp = String.valueOf(epochSecond);
String nonceStr = signatureProvider.nonceStrGenerator()
.generateId()
.toString()
.replaceAll("-", "");
String packageStr = "prepay_id=" + body.get("prepay_id").asText();
String paySign = signatureProvider.doRequestSign(true, privateKey, subAppid, timestamp, nonceStr, packageStr);
body.put("appId", subAppid);
body.put("timeStamp", timestamp);
body.put("nonceStr", nonceStr);
body.put("package", packageStr);
body.put("signType", "RSA");
body.put("paySign", paySign);
wechatResponseEntity.setHttpStatus(responseEntity.getStatusCodeValue());
wechatResponseEntity.setBody(body);
})
.request();
return wechatResponseEntity;
}
/**
* Native下单API
*
* @param partnerPayParams the pay params
* @return wechat response entity
* @since 1.0.8.RELEASE
*/
public WechatResponseEntity<ObjectNode> nativePay(PartnerPayParams partnerPayParams) {
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
this.client().withType(WechatPayV3Type.NATIVE_PARTNER, partnerPayParams)
.function(this::payFunction)
.consumer(wechatResponseEntity::convert)
.request();
return wechatResponseEntity;
}
/**
* H5下单API
*
* @param partnerPayParams the partner pay params
* @return wechat response entity
* @since 1.0.8.RELEASE
*/
public WechatResponseEntity<ObjectNode> h5Pay(PartnerPayParams partnerPayParams) {
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
this.client().withType(WechatPayV3Type.MWEB_PARTNER, partnerPayParams)
.function(this::payFunction)
.consumer(wechatResponseEntity::convert)
.request();
return wechatResponseEntity;
}
private RequestEntity<?> payFunction(WechatPayV3Type type, PartnerPayParams partnerPayParams) {
WechatPayProperties.V3 v3 = this.wechatMetaBean().getV3();
partnerPayParams.setSpAppid(v3.getAppId());
partnerPayParams.setSpMchid(v3.getMchId());
String notifyUrl = v3.getDomain().concat(partnerPayParams.getNotifyUrl());
partnerPayParams.setNotifyUrl(notifyUrl);
URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA))
.build()
.toUri();
return Post(uri, partnerPayParams);
}
/**
* 微信支付订单号查询API
*
* @param params the params
* @return the wechat response entity
* @since 1.0.8.RELEASE
*/
public WechatResponseEntity<ObjectNode> queryTransactionById(TransactionQueryParams params) {
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
this.client().withType(WechatPayV3Type.TRANSACTION_TRANSACTION_ID_PARTNER, params)
.function(this::queryTransactionFunction)
.consumer(wechatResponseEntity::convert)
.request();
return wechatResponseEntity;
}
/**
* 商户订单号查询API
*
* @param params the params
* @return the wechat response entity
* @since 1.0.8.RELEASE
*/
public WechatResponseEntity<ObjectNode> queryTransactionByOutTradeNo(TransactionQueryParams params) {
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
this.client().withType(WechatPayV3Type.TRANSACTION_OUT_TRADE_NO_PARTNER, params)
.function(this::queryTransactionFunction)
.consumer(wechatResponseEntity::convert)
.request();
return wechatResponseEntity;
}
private RequestEntity<?> queryTransactionFunction(WechatPayV3Type type, TransactionQueryParams params) {
WechatPayProperties.V3 v3 = this.wechatMetaBean().getV3();
MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<>();
queryParams.add("sp_mchid", v3.getMchId());
queryParams.add("sub_mchid", params.getMchId());
URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA))
.queryParams(queryParams)
.build()
.expand(params.getTransactionIdOrOutTradeNo())
.toUri();
return Get(uri);
}
/**
* 关单API
*
* @param closeTransParams the closeTransParams
* @return the wechat response entity
* @since 1.0.8.RELEASE
*/
public WechatResponseEntity<ObjectNode> close(CloseTransParams closeTransParams) {
WechatResponseEntity<ObjectNode> wechatResponseEntity = new WechatResponseEntity<>();
this.client().withType(WechatPayV3Type.CLOSE_PARTNER, closeTransParams)
.function(this::closeByOutTradeNoFunction)
.consumer(wechatResponseEntity::convert)
.request();
return wechatResponseEntity;
}
private RequestEntity<?> closeByOutTradeNoFunction(WechatPayV3Type type, CloseTransParams closeTransParams) {
WechatPayProperties.V3 v3 = this.wechatMetaBean().getV3();
Map<String, String> queryParams = new HashMap<>(1);
queryParams.put("sp_mchid", v3.getMchId());
queryParams.put("sub_mchid", closeTransParams.getSubMchid());
URI uri = UriComponentsBuilder.fromHttpUrl(type.uri(WeChatServer.CHINA))
.build()
.expand(closeTransParams.getOutTradeNo())
.toUri();
return Post(uri, queryParams);
}
}

View File

@@ -31,8 +31,11 @@ import cn.felord.payment.wechat.v3.model.payscore.PayScoreUserPaidConsumeData;
import cn.felord.payment.wechat.v3.model.payscore.PayScoreUserPermissionConsumeData;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert;
@@ -71,6 +74,9 @@ public class WechatPayCallback {
static {
MAPPER.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL);
MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
SimpleModule module = new JavaTimeModule();
MAPPER.registerModule(module);
}
/**
@@ -107,7 +113,7 @@ public class WechatPayCallback {
}
/**
* 微信支付成功回调.
* 微信支付成功回调,在1.0.8.RELEASE时支持服务商模式支付回调通知
* <p>
* 无需开发者判断,只有扣款成功微信才会回调此接口
*

View File

@@ -164,7 +164,7 @@ public class WechatPayClient {
public void request() {
RequestEntity<?> requestEntity = this.requestEntityBiFunction.apply(this.wechatPayV3Type, this.model);
WechatRequestEntity<?> wechatRequestEntity = WechatRequestEntity.of(requestEntity, this.responseBodyConsumer);
this.doExecute(this.header(wechatRequestEntity));
this.doExecute(this.header(true,wechatRequestEntity));
}
@@ -176,18 +176,19 @@ public class WechatPayClient {
public String download() {
RequestEntity<?> requestEntity = this.requestEntityBiFunction.apply(this.wechatPayV3Type, this.model);
WechatRequestEntity<?> wechatRequestEntity = WechatRequestEntity.of(requestEntity, this.responseBodyConsumer);
return this.doDownload(this.header(wechatRequestEntity));
return this.doDownload(this.header(true,wechatRequestEntity));
}
/**
* Download string.
*
* @return the string
* @since 1.0.6.RELEASE
*/
public ResponseEntity<Resource> resource() {
public ResponseEntity<Resource> resource() {
RequestEntity<?> requestEntity = this.requestEntityBiFunction.apply(this.wechatPayV3Type, this.model);
WechatRequestEntity<?> wechatRequestEntity = WechatRequestEntity.of(requestEntity, this.responseBodyConsumer);
return this.doResource(this.header(wechatRequestEntity));
return this.doResource(this.header(false,wechatRequestEntity));
}
@@ -198,7 +199,7 @@ public class WechatPayClient {
* @param requestEntity the request entity
* @return the wechat request entity
*/
private <T> WechatRequestEntity<T> header(WechatRequestEntity<T> requestEntity) {
private <T> WechatRequestEntity<T> header(boolean newLine,WechatRequestEntity<T> requestEntity) {
UriComponents uri = UriComponentsBuilder.fromUri(requestEntity.getUrl()).build();
String canonicalUrl = uri.getPath();
@@ -219,7 +220,7 @@ public class WechatPayClient {
}
String tenantId = Objects.requireNonNull(headers.get("Pay-TenantId")).get(0);
String authorization = signatureProvider.requestSign(tenantId, httpMethod.name(), canonicalUrl, body);
String authorization = signatureProvider.requestSign(newLine,tenantId, httpMethod.name(), canonicalUrl, body);
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.addAll(headers);
@@ -253,7 +254,9 @@ public class WechatPayClient {
// 微信请求id
String requestId = headers.getFirst("Request-ID");
if (!statusCode.is2xxSuccessful()) {
throw new PayException("wechat pay server error, Request-ID " + requestId + " , statusCode " + statusCode + ",result : " + body);
PayException payException = new PayException("wechat pay server error, Request-ID " + requestId + " , statusCode " + statusCode + ",result : " + body);
payException.setResponse(responseEntity);
throw payException;
}
ResponseSignVerifyParams params = new ResponseSignVerifyParams();
@@ -276,7 +279,9 @@ public class WechatPayClient {
responseConsumer.accept(responseEntity);
}
} else {
throw new PayException("wechat pay signature verify failed, Request-ID " + requestId);
PayException payException = new PayException("wechat pay signature verify failed, Request-ID " + requestId);
payException.setResponse(responseEntity);
throw payException;
}
}
@@ -295,7 +300,9 @@ public class WechatPayClient {
// 微信请求id
String requestId = requestEntity.getHeaders().getFirst("Request-ID");
if (!statusCode.is2xxSuccessful()) {
throw new PayException("wechat pay server error, Request-ID " + requestId + " , statusCode " + statusCode + ",result : " + responseEntity);
PayException payException = new PayException("wechat pay server error, Request-ID " + requestId + " , statusCode " + statusCode + ",result : " + responseEntity);
payException.setResponse(responseEntity);
throw payException;
}
return Optional.ofNullable(responseEntity.getBody()).orElse("");
}
@@ -309,7 +316,7 @@ public class WechatPayClient {
* @return the resource
* @since 1.0.6.RELEASE
*/
private <T> ResponseEntity<Resource> doResource(WechatRequestEntity<T> requestEntity) {
private <T> ResponseEntity<Resource> doResource(WechatRequestEntity<T> requestEntity) {
ResponseEntity<Resource> responseEntity = restOperations.exchange(requestEntity, Resource.class);
@@ -317,7 +324,9 @@ public class WechatPayClient {
// 微信请求id
String requestId = requestEntity.getHeaders().getFirst("Request-ID");
if (!statusCode.is2xxSuccessful()) {
throw new PayException("wechat pay server error, Request-ID " + requestId + " , statusCode " + statusCode + ",result : " + responseEntity);
PayException payException = new PayException("wechat pay server error, Request-ID " + requestId + " , statusCode " + statusCode + ",result : " + responseEntity);
payException.setResponse(responseEntity);
throw payException;
}
return responseEntity;
}

View File

@@ -0,0 +1,75 @@
/*
* Copyright 2019-2021 felord.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
*
* https://www.apache.org/licenses/LICENSE-2.0
* Website:
* https://felord.cn
* 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.
*/
package cn.felord.payment.wechat.v3.model;
import lombok.Data;
/**
* @author felord.cn
* @since 1.0.8.RELEASE
*/
@Data
public abstract class AbstractPayParams {
/**
* 商品描述
* Image形象店-深圳腾大-QQ公仔
*/
private String description;
/**
* 商户系统内部订单号只能是数字、大小写字母_-*且在同一个商户号下唯一,详见【商户订单号】。
* 示例值1217752501201407033233368018
*/
private String outTradeNo;
/**
* 订单失效时间 YYYY-MM-DDTHH:mm:ss+TIMEZONE
*/
private String timeExpire;
/**
* 附加数据在查询API和支付通知中原样返回可作为自定义参数使用
*/
private String attach;
/**
* 通知URL必须为直接可访问的URL不允许携带查询串。
*/
private String notifyUrl;
/**
* 订单优惠标记
*/
private String goodsTag;
/**
* 支付金额
*/
private Amount amount;
/**
* 优惠功能
*/
private Detail detail;
/**
* 支付者 JSAPI/小程序下单 必传
*/
private Payer payer;
/**
* 场景信息
*/
private SceneInfo sceneInfo;
/**
* 结算信息
*/
private SettleInfo settleInfo;
}

View File

@@ -31,7 +31,7 @@ public class Amount {
/**
* 金额,单位【分】。
*/
private int total;
private Integer total;
/**
* 货币单位,固定为 CNY 。
*/

View File

@@ -20,6 +20,7 @@ package cn.felord.payment.wechat.v3.model;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 支付请求参数.
@@ -27,8 +28,9 @@ import lombok.Data;
* @author felord.cn
* @since 1.0.0.RELEASE
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class PayParams {
public class PayParams extends AbstractPayParams {
/**
* The Appid.
*/
@@ -37,48 +39,5 @@ public class PayParams {
* The Mchid.
*/
private String mchid;
/**
* 商品描述
* Image形象店-深圳腾大-QQ公仔
*/
private String description;
/**
* 商户系统内部订单号只能是数字、大小写字母_-*且在同一个商户号下唯一,详见【商户订单号】。
* 示例值1217752501201407033233368018
*/
private String outTradeNo;
/**
* 订单失效时间 YYYY-MM-DDTHH:mm:ss+TIMEZONE
*/
private String timeExpire;
/**
* 附加数据在查询API和支付通知中原样返回可作为自定义参数使用
*/
private String attach;
/**
* 通知URL必须为直接可访问的URL不允许携带查询串。
*/
private String notifyUrl;
/**
* 订单优惠标记
*/
private String goodsTag;
/**
* 支付金额
*/
private Amount amount;
/**
* 支付者 JSAPI/小程序下单 必传
*/
private Payer payer;
/**
* 优惠功能
*/
private Detail detail;
/**
* 场景信息
*/
private SceneInfo sceneInfo;
}

View File

@@ -59,12 +59,17 @@ public class RefundConsumeData {
/**
* 退款成功时间
*/
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss", timezone = "GMT+8")
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssXXX", timezone = "GMT+8")
private OffsetDateTime successTime;
/**
* 退款入账账户
*/
private String userReceivedAccount;
/**
* 金额信息
*/
private Amount amount;
/**
* 微信支付退款金额信息
@@ -85,7 +90,6 @@ public class RefundConsumeData {
/**
* 用户实际支付金额,单位为分
*/
private Integer payerTotal;
/**
* 退款给用户的金额,单位为分,不包含所有优惠券金额

View File

@@ -44,12 +44,12 @@ public class StocksCreateParams {
*/
private String belongMerchant;
/**
* 批次开始时间 rfc 3339 yyyy-MM-ddTHH:mm:ss+TIMEZONE
* 批次开始时间 rfc 3339 yyyy-MM-ddTHH:mm:ss.sss+TIMEZONE
*/
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", timezone = "GMT+8")
private OffsetDateTime availableBeginTime;
/**
* 批次结束时间 rfc 3339 yyyy-MM-ddTHH:mm:ss+TIMEZONE
* 批次结束时间 rfc 3339 yyyy-MM-ddTHH:mm:ss.sss+TIMEZONE
*/
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", timezone = "GMT+8")
private OffsetDateTime availableEndTime;

View File

@@ -20,8 +20,10 @@ package cn.felord.payment.wechat.v3.model;
import cn.felord.payment.wechat.enumeration.TradeState;
import cn.felord.payment.wechat.enumeration.TradeType;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.time.OffsetDateTime;
import java.util.List;
/**
@@ -38,9 +40,29 @@ public class TransactionConsumeData {
*/
private Amount amount;
/**
* 应用ID
* 直连模式应用ID服务商模式请解析spAppid
*/
private String appid;
/**
* 直连模式商户号服务商模式请解析spMchid
*/
private String mchid;
/**
* 服务商模式-服务商APPID
*/
private String spAppid;
/**
* 服务商模式-服务商户号
*/
private String spMchid;
/**
* 服务商模式-子商户appid
*/
private String subAppid;
/**
* 服务商模式-子商户商户id
*/
private String subMchid;
/**
* 附加数据在查询API和支付通知中原样返回可作为自定义参数使用
*/
@@ -49,10 +71,6 @@ public class TransactionConsumeData {
* 银行类型,采用字符串类型的银行标识。银行标识请参考 <a target= "_blank" href= "https://pay.weixin.qq.com/wiki/doc/apiv3/terms_definition/chapter1_1_3.shtml#part-6">《银行类型对照表》</a>
*/
private String bankType;
/**
* 商户号
*/
private String mchid;
/**
* 商户订单号
*/
@@ -72,7 +90,8 @@ public class TransactionConsumeData {
/**
* 支付完成时间 YYYY-MM-DDTHH:mm:ss+TIMEZONE
*/
private String successTime;
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssXXX", timezone = "GMT+8")
private OffsetDateTime successTime;
/**
* 在 1.0.0.RELEASE 直接返回了枚举字符串1.0.2.RELEASE 中变更为枚举
*

View File

@@ -49,7 +49,7 @@ public class BusiFavorReceiveConsumeData {
/**
* 发放时间 rfc 3339 yyyy-MM-ddTHH:mm:ss+TIMEZONE
*/
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssXXX", timezone = "GMT+8")
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss", timezone = "GMT+8")
private OffsetDateTime sendTime;
/**
* 微信用户在appid下的唯一标识。

View File

@@ -40,7 +40,7 @@ public class CouponAvailableTime {
* <p>
* 需配合{@link #availableDayAfterReceive} 一同填写,不可单独填写。
*/
private int waitDaysAfterReceive;
private Integer waitDaysAfterReceive;
/**
* 生效后N天内有效
* <p>
@@ -50,7 +50,7 @@ public class CouponAvailableTime {
* <p>
* 可配合{@link #waitDaysAfterReceive}一同填写也可单独填写。单独填写时有效期内领券后立即生效生效后x天内有效。
*/
private int availableDayAfterReceive;
private Integer availableDayAfterReceive;
/**
* 批次开始时间 rfc 3339 yyyy-MM-ddTHH:mm:ss+TIMEZONE
*/

View File

@@ -0,0 +1,38 @@
/*
* Copyright 2019-2021 felord.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
*
* https://www.apache.org/licenses/LICENSE-2.0
* Website:
* https://felord.cn
* 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.
*/
package cn.felord.payment.wechat.v3.model.partner;
import lombok.Data;
/**
* 服务商模式-关闭订单请求参数
*
* @author felord.cn
* @since 1.0.8.RELEASE
*/
@Data
public class CloseTransParams {
/**
* 子商户号
*/
private String subMchid;
/**
* 商户订单号
*/
private String outTradeNo;
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2019-2021 felord.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
*
* https://www.apache.org/licenses/LICENSE-2.0
* Website:
* https://felord.cn
* 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.
*/
package cn.felord.payment.wechat.v3.model.partner;
import cn.felord.payment.wechat.v3.model.AbstractPayParams;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @author felord.cn
* @since 1.0.8.RELEASE
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class PartnerPayParams extends AbstractPayParams {
/**
* 服务商公众号ID
*/
private String spAppid;
/**
* 服务商户号
*/
private String spMchid;
/**
* 子商户appid.
*/
private String subAppid;
/**
* 子商户号
*/
private String subMchid;
}

View File

@@ -98,6 +98,10 @@ public class PayScoreUserPaidConsumeData {
* The Time range.
*/
private TimeRange timeRange;
/**
* stateDescription
*/
private String stateDescription;
/**
* The Total amount.
*/

View File

@@ -5,11 +5,11 @@
<parent>
<groupId>cn.felord</groupId>
<artifactId>payment-spring-boot</artifactId>
<version>1.0.7.RELEASE</version>
<version>1.0.9.RELEASE</version>
</parent>
<artifactId>payment-spring-boot-starter</artifactId>
<version>1.0.7.RELEASE</version>
<version>1.0.9.RELEASE</version>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>

View File

@@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>cn.felord</groupId>
<artifactId>payment-spring-boot</artifactId>
<version>1.0.7.RELEASE</version>
<version>1.0.9.RELEASE</version>
<packaging>pom</packaging>
<modelVersion>4.0.0</modelVersion>
@@ -30,7 +30,7 @@
</developers>
<scm>
<tag>payment-spring-boot-1.0.7.RELEASE</tag>
<tag>payment-spring-boot-1.0.9.RELEASE</tag>
<url>https://github.com/NotFound403/payment-spring-boot</url>
<connection>scm:git:https://github.com/NotFound403/payment-spring-boot.git</connection>
<developerConnection>scm:git:https://github.com/NotFound403/payment-spring-boot.git</developerConnection>