mirror of
https://github.com/dromara/payment-spring-boot.git
synced 2026-03-13 21:33:41 +08:00
enhance: 优化逻辑
This commit is contained in:
@@ -184,15 +184,15 @@ public class SignatureProvider {
|
|||||||
.orElseThrow(() -> new PayException("cannot obtain the certificate"));
|
.orElseThrow(() -> new PayException("cannot obtain the certificate"));
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final String signatureStr = createSign(params.getWechatpayTimestamp(), params.getWechatpayNonce(), params.getBody());
|
final String signatureStr = createSign(params.getWechatpayTimestamp(), params.getWechatpayNonce(), params.getBody());
|
||||||
Signature signer = Signature.getInstance("SHA256withRSA", BC_PROVIDER);
|
Signature signer = Signature.getInstance("SHA256withRSA", BC_PROVIDER);
|
||||||
signer.initVerify(certificate.getX509Certificate());
|
signer.initVerify(certificate.getX509Certificate());
|
||||||
signer.update(signatureStr.getBytes(StandardCharsets.UTF_8));
|
signer.update(signatureStr.getBytes(StandardCharsets.UTF_8));
|
||||||
return signer.verify(Base64Utils.decodeFromString(params.getWechatpaySignature()));
|
return signer.verify(Base64Utils.decodeFromString(params.getWechatpaySignature()));
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
throw new PayException("An exception occurred during the response verification, the cause: "+e.getMessage());
|
throw new PayException("An exception occurred during the response verification, the cause: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -230,12 +230,9 @@ public class SignatureProvider {
|
|||||||
throw new PayException("cant obtain the response body");
|
throw new PayException("cant obtain the response body");
|
||||||
}
|
}
|
||||||
ArrayNode certificates = bodyObjectNode.withArray("data");
|
ArrayNode certificates = bodyObjectNode.withArray("data");
|
||||||
if (certificates.isArray() && certificates.size() > 0) {
|
if (certificates.isArray() && !certificates.isEmpty()) {
|
||||||
CERTIFICATE_SET.forEach(x509WechatCertificateInfo -> {
|
CERTIFICATE_SET.removeIf(x509WechatCertificateInfo ->
|
||||||
if (Objects.equals(tenantId, x509WechatCertificateInfo.getTenantId())) {
|
Objects.equals(tenantId, x509WechatCertificateInfo.getTenantId()));
|
||||||
CERTIFICATE_SET.remove(x509WechatCertificateInfo);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
final CertificateFactory certificateFactory = CertificateFactory.getInstance("X509", BC_PROVIDER);
|
final CertificateFactory certificateFactory = CertificateFactory.getInstance("X509", BC_PROVIDER);
|
||||||
certificates.forEach(objectNode -> {
|
certificates.forEach(objectNode -> {
|
||||||
JsonNode encryptCertificate = objectNode.get("encrypt_certificate");
|
JsonNode encryptCertificate = objectNode.get("encrypt_certificate");
|
||||||
|
|||||||
Reference in New Issue
Block a user