public class SignatureProvider extends Object
我方请求微信服务器时,需要根据我方的API证书对参数进行加签;微信服务器会根据我方签名验签以确定请求来自我方服务器;
然后微信服务器响应我方请求并在响应报文中使用【微信平台证书】加签 我方需要根据规则验签是否响应来自微信支付服务器
其中【微信平台证书】定期会进行更新,不受我方管控,我方需要适当的时候获取最新的证书列表。
| 限定符和类型 | 字段和说明 |
|---|---|
private static String |
BC_PROVIDER
加密算法提供方 - BouncyCastle
|
private static Map<String,Certificate> |
CERTIFICATE_MAP
微信平台证书容器 key = 序列号 value = 证书对象
|
private org.springframework.util.IdGenerator |
nonceStrGenerator
The constant ID_GENERATOR.
|
private org.springframework.web.client.RestOperations |
restOperations
The Rest operations.
|
private static String |
SCHEMA
The constant SCHEMA.
|
static String |
TOKEN_PATTERN
The constant TOKEN_PATTERN.
|
private WechatMetaContainer |
wechatMetaContainer
The Wechat meta container.
|
| 构造器和说明 |
|---|
SignatureProvider(WechatMetaContainer wechatMetaContainer)
Instantiates a new Signature provider.
|
| 限定符和类型 | 方法和说明 |
|---|---|
private static String |
createSign(boolean newLine,
String... components)
请求时设置签名 组件
|
String |
decryptResponseBody(String tenantId,
String associatedData,
String nonce,
String ciphertext)
解密响应体.
|
String |
doRequestSign(boolean newLine,
PrivateKey privateKey,
String... orderedComponents)
Do request sign.
|
String |
encryptRequestMessage(String message,
Certificate certificate)
对请求敏感字段进行加密
|
X509WechatCertificateInfo |
getCertificate()
Get certificate x 509 wechat certificate info.
|
org.springframework.util.IdGenerator |
nonceStrGenerator()
Nonce generator.
|
private void |
refreshCertificate(String tenantId)
当我方服务器不存在平台证书或者证书同当前响应报文中的证书序列号不一致时应当刷新 调用/v3/certificates
|
String |
requestSign(boolean newLine,
String tenantId,
String method,
String canonicalUrl,
String body)
我方请求前用 SHA256withRSA 加签,使用API证书.
|
boolean |
responseSignVerify(ResponseSignVerifyParams params)
我方对响应验签,和应答签名做比较,使用微信平台证书.
|
WechatMetaContainer |
wechatMetaContainer()
Wechat meta container.
|
private final org.springframework.util.IdGenerator nonceStrGenerator
private static final Map<String,Certificate> CERTIFICATE_MAP
private final org.springframework.web.client.RestOperations restOperations
private final WechatMetaContainer wechatMetaContainer
public SignatureProvider(WechatMetaContainer wechatMetaContainer)
wechatMetaContainer - the wechat meta containerpublic String requestSign(boolean newLine, String tenantId, String method, String canonicalUrl, String body)
newLine - the new linetenantId - the properties keymethod - the methodcanonicalUrl - the canonical urlbody - the bodypublic String doRequestSign(boolean newLine, PrivateKey privateKey, String... orderedComponents)
newLine - the has suffixprivateKey - the private keyorderedComponents - the orderedComponentspublic boolean responseSignVerify(ResponseSignVerifyParams params)
params - the paramsprivate void refreshCertificate(String tenantId)
tenantId - tenantIdpublic String decryptResponseBody(String tenantId, String associatedData, String nonce, String ciphertext)
tenantId - the properties keyassociatedData - the associated datanonce - the nonceciphertext - the ciphertextpublic String encryptRequestMessage(String message, Certificate certificate)
message - the messagecertificate - the certificatepublic X509WechatCertificateInfo getCertificate()
public WechatMetaContainer wechatMetaContainer()
public org.springframework.util.IdGenerator nonceStrGenerator()
Copyright © 2021. All rights reserved.