15 Commits

Author SHA1 Message Date
felord
3dd7c67f9a docs: update 2021-12-13 11:26:37 +08:00
felord
fa337b2997 refactor: merge pull request
Closes #40
2021-12-13 11:23:13 +08:00
felord.cn
f0d69600f7 Merge pull request #40 from fxbin/dev
build(deps): 变更依赖管理方式,交由spring-boot-dependencies管理
2021-12-13 11:19:12 +08:00
felord.cn
eb8c68b084 Merge pull request #58 from NotFound403/1.0.12.SNAPSHOT
1.0.12.RELEASE
2021-12-13 11:18:48 +08:00
felord.cn
b8ea383460 Merge branch 'release' into 1.0.12.SNAPSHOT 2021-12-13 11:18:35 +08:00
felord
61e98ffbe9 refactor: update to 1.0.12.RELEASE 2021-12-13 11:12:55 +08:00
felord
a5596e17bb refactor: 证书增加租户指纹 2021-09-08 14:16:03 +08:00
felord
194937025f refactor: 证书增加租户指纹 2021-09-08 11:03:02 +08:00
felord
90233b8e32 fix: 分账API错误
Closes 48
2021-09-08 10:10:39 +08:00
felord
7459039cfd refactor: V2 签名优化 2021-08-18 16:37:12 +08:00
felord
9eb58860f1 refactor: V2 签名优化 2021-08-18 16:34:29 +08:00
felord
e38167e748 refactor: V2 签名优化 2021-08-18 16:31:40 +08:00
felord
5a3f258390 refactor: 避免jackson xml 模块的联动影响 2021-08-18 11:01:21 +08:00
fxbin
ddf9a449d1 build(deps): 变更依赖管理方式,交由spring-boot-dependencies管理 2021-07-21 16:56:44 +08:00
felord
21ba6feee0 docs: Update pathParams 2021-06-08 18:09:56 +08:00
15 changed files with 106 additions and 82 deletions

View File

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

View File

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

View File

@@ -1,3 +1,27 @@
## 1.0.12.RELEASE
- refector: 变更依赖管理方式交由spring-boot-dependencies管理依赖([#40](https://github.com/NotFound403/payment-spring-boot/pull/40))
- 微信支付
- fix: 修复多租户配置下,平台证书刷新错误的问题([#49](https://github.com/NotFound403/payment-spring-boot/issues/49))
- fix: 分账API描述符错误([#48](https://github.com/NotFound403/payment-spring-boot/issues/48)) 。
- refactor: 避免受jackson类库xml模块的影响
- refactor: V2签名优化
## 1.0.11.RELEASE
- 微信支付
- feat: bcprov-jdk15to18算法库从1.66 升级到 1.67
- feat: 微信支付 《支付通知API》新增优惠功能promotion_detail字段
- feat: 微信支付基础支付《申请退款API》、《查询退款API》新增字段 from退款出资账户及金额
- feat: 现在支持V3分账功能目前只支持直连商户分账`WechatProfitsharingApi`和服务商分账`WechatPartnerProfitsharingApi`
- feat: 完善V3批量转账到零钱API增加实现转账明细电子回单受理API、查询转账明细电子回单受理结果API、查询账户实时余额API、查询账户日终余额API、商户银行来账查询API
- refactor: 微信支付分分账标记默认改为不分账
- refactor: 平台证书刷新逻辑优化 ([#I3NGSB](https://gitee.com/felord/payment-spring-boot/issues/I3NGSB))
- refactor: 交易账单和资金账单现在能够正常的下载文件了可以根据参数自动选择下载为gzip或者txt文件
- fix: 批量转账到零钱:微信明细单号查询明细单API,商家明细单号查询明细单API 参数错误
- fix: 修复查询代金券参数的错误
- 支付宝
- feat: 支付宝增加字段`classpathUsed`来标识是否使用类路径,默认`true`。证书路径可依此来决定是使用绝对路径还是类路径
## 1.0.10.RELEASE
- 微信支付

View File

@@ -4,7 +4,7 @@
<dependency>
<groupId>cn.felord</groupId>
<artifactId>payment-spring-boot-starter</artifactId>
<version>1.0.11.RELEASE</version>
<version>1.0.12.RELEASE</version>
</dependency>
```
> 基于 **Spring Boot 2.x**

View File

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

View File

@@ -622,7 +622,7 @@ public enum WechatPayV3Type {
*
* @since 1.0.11.RELEASE
*/
PROFITSHARING_RECEIVERS_DELETE(HttpMethod.POST, "%s/v3/profitsharing/receivers/add");
PROFITSHARING_RECEIVERS_DELETE(HttpMethod.POST, "%s/v3/profitsharing/receivers/delete");
/**
* The Pattern.
*

View File

@@ -21,8 +21,8 @@ package cn.felord.payment.wechat.v2.model;
import cn.felord.payment.PayException;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
@@ -56,6 +56,8 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.*;
import java.security.cert.CertificateException;
import java.util.TreeMap;
import java.util.stream.Collectors;
/**
* The type Base model.
@@ -74,7 +76,8 @@ public abstract class BaseModel {
XML_MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL)
// 属性使用 驼峰首字母小写
.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
OBJECT_MAPPER.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true)
OBJECT_MAPPER
// .configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true)
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
}
@@ -149,10 +152,11 @@ public abstract class BaseModel {
*/
@SneakyThrows
private String hmacSha256(String src) {
Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
SecretKeySpec secret_key = new SecretKeySpec(appSecret.getBytes(),"HmacSHA256");
sha256_HMAC.init(secret_key);
byte[] bytes = sha256_HMAC.doFinal(src.getBytes(StandardCharsets.UTF_8));
String algorithm = "HmacSHA256";
Mac sha256HMAC = Mac.getInstance(algorithm,"BC");
SecretKeySpec secretKeySpec = new SecretKeySpec(appSecret.getBytes(), algorithm);
sha256HMAC.init(secretKeySpec);
byte[] bytes = sha256HMAC.doFinal(src.getBytes(StandardCharsets.UTF_8));
return Hex.toHexString(bytes).toUpperCase();
}
@@ -166,13 +170,17 @@ public abstract class BaseModel {
@SneakyThrows
private <T> String link(T t) {
Assert.hasText(appSecret, "wechat pay appSecret is required");
String link = OBJECT_MAPPER
.writer()
.writeValueAsString(t)
.replaceAll("\":\"", "=")
.replaceAll("\",\"", "&")
.replaceAll("\\\\\"", "\"");
return link.substring(2, link.length() - 2).concat("&key=").concat(this.appSecret);
String json = OBJECT_MAPPER
.writeValueAsString(t);
TreeMap<String, String> map = OBJECT_MAPPER.readValue(json, new TypeReference<TreeMap<String, String>>() {
});
String query = map.entrySet()
.stream()
.map(entry -> entry.getKey().concat("=").concat(entry.getValue()))
.collect(Collectors.joining("&"));
return query.concat("&key=").concat(this.appSecret);
}

View File

@@ -30,7 +30,12 @@ import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.springframework.http.*;
import org.springframework.util.*;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter;
import org.springframework.util.AlternativeJdkIdGenerator;
import org.springframework.util.Assert;
import org.springframework.util.Base64Utils;
import org.springframework.util.IdGenerator;
import org.springframework.web.client.RestOperations;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponents;
@@ -49,10 +54,7 @@ import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@@ -86,7 +88,7 @@ public class SignatureProvider {
/**
* 微信平台证书容器 key = 序列号 value = 证书对象
*/
private static final Map<String, Certificate> CERTIFICATE_MAP = new ConcurrentHashMap<>();
private static final Map<String, X509WechatCertificateInfo> CERTIFICATE_MAP = new ConcurrentHashMap<>();
/**
* 加密算法提供方 - BouncyCastle
*/
@@ -96,7 +98,7 @@ public class SignatureProvider {
/**
* The Rest operations.
*/
private final RestOperations restOperations = new RestTemplate();
private final RestOperations restOperations;
/**
* The Wechat meta container.
*/
@@ -110,6 +112,11 @@ public class SignatureProvider {
public SignatureProvider(WechatMetaContainer wechatMetaContainer) {
Provider bouncyCastleProvider = new BouncyCastleProvider();
Security.addProvider(bouncyCastleProvider);
RestTemplate restOperations = new RestTemplate();
List<HttpMessageConverter<?>> messageConverters = restOperations.getMessageConverters();
messageConverters.removeIf(httpMessageConverter -> httpMessageConverter instanceof MappingJackson2XmlHttpMessageConverter);
restOperations.setMessageConverters(messageConverters);
this.restOperations = restOperations;
this.wechatMetaContainer = wechatMetaContainer;
wechatMetaContainer.getTenantIds().forEach(this::refreshCertificate);
}
@@ -174,10 +181,10 @@ public class SignatureProvider {
if (CERTIFICATE_MAP.isEmpty() || !CERTIFICATE_MAP.containsKey(wechatpaySerial)) {
wechatMetaContainer.getTenantIds().forEach(this::refreshCertificate);
}
Certificate certificate = CERTIFICATE_MAP.get(wechatpaySerial);
Certificate certificate = CERTIFICATE_MAP.get(wechatpaySerial).getX509Certificate();
final String signatureStr = createSign(true, params.getWechatpayTimestamp(), params.getWechatpayNonce(), params.getBody());
Signature signer = Signature.getInstance("SHA256withRSA");
Signature signer = Signature.getInstance("SHA256withRSA", BC_PROVIDER);
signer.initVerify(certificate);
signer.update(signatureStr.getBytes(StandardCharsets.UTF_8));
@@ -234,7 +241,11 @@ public class SignatureProvider {
try {
Certificate certificate = certificateFactory.generateCertificate(inputStream);
String responseSerialNo = objectNode.get("serial_no").asText();
CERTIFICATE_MAP.put(responseSerialNo, certificate);
X509WechatCertificateInfo x509WechatCertificateInfo = new X509WechatCertificateInfo();
x509WechatCertificateInfo.setWechatPaySerial(responseSerialNo);
x509WechatCertificateInfo.setTenantId(tenantId);
x509WechatCertificateInfo.setX509Certificate((X509Certificate) certificate);
CERTIFICATE_MAP.put(responseSerialNo, x509WechatCertificateInfo);
} catch (CertificateException e) {
throw new PayException("An error occurred while generating the wechat v3 certificate, reason : " + e.getMessage());
}
@@ -307,21 +318,23 @@ public class SignatureProvider {
/**
* Get certificate x 509 wechat certificate info.
*
* @param tenantId the tenant id
* @return the x 509 wechat certificate info
*/
public X509WechatCertificateInfo getCertificate() {
public X509WechatCertificateInfo getCertificate(String tenantId) {
for (String serial : CERTIFICATE_MAP.keySet()) {
X509Certificate x509Cert = (X509Certificate) CERTIFICATE_MAP.get(serial);
try {
x509Cert.checkValidity();
X509WechatCertificateInfo x509WechatCertificateInfo = new X509WechatCertificateInfo();
x509WechatCertificateInfo.setWechatPaySerial(serial);
x509WechatCertificateInfo.setX509Certificate(x509Cert);
return x509WechatCertificateInfo;
} catch (Exception e) {
log.warn("the wechat certificate is invalid , {}", e.getMessage());
// Async?
wechatMetaContainer.getTenantIds().forEach(this::refreshCertificate);
X509WechatCertificateInfo wechatCertificateInfo = CERTIFICATE_MAP.get(serial);
X509Certificate x509Cert = wechatCertificateInfo.getX509Certificate();
if (wechatCertificateInfo.getTenantId().equals(tenantId)){
try {
x509Cert.checkValidity();
return wechatCertificateInfo;
} catch (Exception e) {
log.warn("the wechat certificate is invalid , {}", e.getMessage());
// Async?
wechatMetaContainer.getTenantIds().forEach(this::refreshCertificate);
}
}
}
throw new PayException("failed to obtain wechat pay x509Certificate ");

View File

@@ -77,7 +77,7 @@ public class WechatBatchTransferApi extends AbstractApi {
List<CreateBatchTransferParams.TransferDetailListItem> transferDetailList = createBatchTransferParams.getTransferDetailList();
SignatureProvider signatureProvider = this.client().signatureProvider();
X509WechatCertificateInfo certificate = signatureProvider.getCertificate();
X509WechatCertificateInfo certificate = signatureProvider.getCertificate(this.wechatMetaBean().getTenantId());
final X509Certificate x509Certificate = certificate.getX509Certificate();
List<CreateBatchTransferParams.TransferDetailListItem> encrypted = transferDetailList.stream()
.peek(transferDetailListItem -> {

View File

@@ -56,7 +56,7 @@ public class WechatPartnerProfitsharingApi extends AbstractApi {
.function((wechatPayV3Type, params) -> {
WechatPayProperties.V3 v3 = this.wechatMetaBean().getV3();
SignatureProvider signatureProvider = this.client().signatureProvider();
X509WechatCertificateInfo certificate = signatureProvider.getCertificate();
X509WechatCertificateInfo certificate = signatureProvider.getCertificate(this.wechatMetaBean().getTenantId());
final X509Certificate x509Certificate = certificate.getX509Certificate();
params.setAppid(v3.getAppId());
List<Receiver> receivers = params.getReceivers();
@@ -272,7 +272,7 @@ public class WechatPartnerProfitsharingApi extends AbstractApi {
.function((wechatPayV3Type, params) -> {
WechatPayProperties.V3 v3 = this.wechatMetaBean().getV3();
SignatureProvider signatureProvider = this.client().signatureProvider();
X509WechatCertificateInfo certificate = signatureProvider.getCertificate();
X509WechatCertificateInfo certificate = signatureProvider.getCertificate(this.wechatMetaBean().getTenantId());
final X509Certificate x509Certificate = certificate.getX509Certificate();
params.setAppid(v3.getAppId());
String name = params.getName();

View File

@@ -29,6 +29,7 @@ import org.springframework.http.*;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter;
import org.springframework.util.Assert;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.RestOperations;
@@ -351,7 +352,7 @@ public class WechatPayClient {
DefaultResponseErrorHandler errorHandler = new WechatPayResponseErrorHandler();
restTemplate.setErrorHandler(errorHandler);
List<HttpMessageConverter<?>> messageConverters = restTemplate.getMessageConverters();
messageConverters.removeIf(httpMessageConverter -> httpMessageConverter instanceof MappingJackson2XmlHttpMessageConverter);
messageConverters.removeIf(httpMessageConverter -> httpMessageConverter instanceof AllEncompassingFormHttpMessageConverter);
messageConverters.add(new ExtensionFormHttpMessageConverter());
restTemplate.setMessageConverters(messageConverters);

View File

@@ -53,7 +53,7 @@ public class WechatProfitsharingApi extends AbstractApi {
.function((wechatPayV3Type, params) -> {
WechatPayProperties.V3 v3 = this.wechatMetaBean().getV3();
SignatureProvider signatureProvider = this.client().signatureProvider();
X509WechatCertificateInfo certificate = signatureProvider.getCertificate();
X509WechatCertificateInfo certificate = signatureProvider.getCertificate(this.wechatMetaBean().getTenantId());
final X509Certificate x509Certificate = certificate.getX509Certificate();
params.setAppid(v3.getAppId());
List<Receiver> receivers = params.getReceivers();
@@ -239,7 +239,7 @@ public class WechatProfitsharingApi extends AbstractApi {
.function((wechatPayV3Type, params) -> {
WechatPayProperties.V3 v3 = this.wechatMetaBean().getV3();
SignatureProvider signatureProvider = this.client().signatureProvider();
X509WechatCertificateInfo certificate = signatureProvider.getCertificate();
X509WechatCertificateInfo certificate = signatureProvider.getCertificate(this.wechatMetaBean().getTenantId());
final X509Certificate x509Certificate = certificate.getX509Certificate();
params.setAppid(v3.getAppId());
String name = params.getName();

View File

@@ -33,6 +33,11 @@ public class X509WechatCertificateInfo {
* wechatPaySerial
*/
private String wechatPaySerial;
/**
* tenantId
* @since 1.0.12.RELEASE
*/
private String tenantId;
/**
* X509Certificate
*/

View File

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

39
pom.xml
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.11.RELEASE</version>
<version>1.0.12.RELEASE</version>
<packaging>pom</packaging>
<modelVersion>4.0.0</modelVersion>
@@ -78,7 +78,6 @@
<jackson.version>2.9.10</jackson.version>
<bcprov.version>1.67</bcprov.version>
<jackson.version>2.11.4</jackson.version>
<httpclient.version>4.5.13</httpclient.version>
</properties>
<distributionManagement>
@@ -96,31 +95,15 @@
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alipay.sdk</groupId>
<artifactId>alipay-sdk-java</artifactId>
@@ -141,16 +124,6 @@
<artifactId>payment-spring-boot-autoconfigure</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
</dependencies>
</dependencyManagement>