类 SignatureProvider
- java.lang.Object
-
- cn.crushes.cloud.core.pay.wechat.v3.SignatureProvider
-
public class SignatureProvider extends Object
签名 加签 验签我方请求微信服务器时,需要根据我方的API证书对参数进行加签;微信服务器会根据我方签名验签以确定请求来自我方服务器;
然后微信服务器响应我方请求并在响应报文中使用【微信平台证书】加签 我方需要根据规则验签是否响应来自微信支付服务器
其中【微信平台证书】定期会进行更新,不受我方管控,我方需要适当的时候获取最新的证书列表。
- 作者:
- youta
-
-
字段概要
字段 修饰符和类型 字段 说明 private static StringBC_PROVIDER加密算法提供方 - BouncyCastleprivate static Map<String,Certificate>CERTIFICATE_MAP微信平台证书容器 key = 序列号 value = 证书对象private org.springframework.util.IdGeneratornonceStrGeneratorThe constant ID_GENERATOR.private org.springframework.web.client.RestOperationsrestOperationsThe Rest operations.private static StringSCHEMAThe constant SCHEMA.static StringTOKEN_PATTERNThe constant TOKEN_PATTERN.private WechatMetaContainerwechatMetaContainerThe Wechat meta container.
-
构造器概要
构造器 构造器 说明 SignatureProvider(WechatMetaContainer wechatMetaContainer)Instantiates a new Signature provider.
-
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 private static StringcreateSign(boolean newLine, String... components)请求时设置签名 组件StringdecryptResponseBody(String tenantId, String associatedData, String nonce, String ciphertext)解密响应体.StringdoRequestSign(boolean newLine, PrivateKey privateKey, String... orderedComponents)Do request sign.StringencryptRequestMessage(String message, Certificate certificate)对请求敏感字段进行加密X509WechatCertificateInfogetCertificate()Get certificate x 509 wechat certificate info.org.springframework.util.IdGeneratornonceStrGenerator()Nonce generator.private voidrefreshCertificate(String tenantId)当我方服务器不存在平台证书或者证书同当前响应报文中的证书序列号不一致时应当刷新 调用/v3/certificatesStringrequestSign(boolean newLine, String tenantId, String method, String canonicalUrl, String body)我方请求前用 SHA256withRSA 加签,使用API证书.booleanresponseSignVerify(ResponseSignVerifyParams params)我方对响应验签,和应答签名做比较,使用微信平台证书.WechatMetaContainerwechatMetaContainer()Wechat meta container.
-
-
-
字段详细资料
-
nonceStrGenerator
private final org.springframework.util.IdGenerator nonceStrGenerator
The constant ID_GENERATOR.
-
CERTIFICATE_MAP
private static final Map<String,Certificate> CERTIFICATE_MAP
微信平台证书容器 key = 序列号 value = 证书对象
-
restOperations
private final org.springframework.web.client.RestOperations restOperations
The Rest operations.
-
wechatMetaContainer
private final WechatMetaContainer wechatMetaContainer
The Wechat meta container.
-
-
构造器详细资料
-
SignatureProvider
public SignatureProvider(WechatMetaContainer wechatMetaContainer)
Instantiates a new Signature provider.- 参数:
wechatMetaContainer- the wechat meta container
-
-
方法详细资料
-
requestSign
public String requestSign(boolean newLine, String tenantId, String method, String canonicalUrl, String body)
我方请求前用 SHA256withRSA 加签,使用API证书.- 参数:
newLine- the new linetenantId- the properties keymethod- the methodcanonicalUrl- the canonical urlbody- the body- 返回:
- the string
-
doRequestSign
public String doRequestSign(boolean newLine, PrivateKey privateKey, String... orderedComponents)
Do request sign.- 参数:
newLine- the has suffixprivateKey- the private keyorderedComponents- the orderedComponents- 返回:
- the string
-
responseSignVerify
public boolean responseSignVerify(ResponseSignVerifyParams params)
我方对响应验签,和应答签名做比较,使用微信平台证书.- 参数:
params- the params- 返回:
- the boolean
-
refreshCertificate
private void refreshCertificate(String tenantId)
当我方服务器不存在平台证书或者证书同当前响应报文中的证书序列号不一致时应当刷新 调用/v3/certificates- 参数:
tenantId- tenantId
-
decryptResponseBody
public String decryptResponseBody(String tenantId, String associatedData, String nonce, String ciphertext)
解密响应体.- 参数:
tenantId- the properties keyassociatedData- the associated datanonce- the nonceciphertext- the ciphertext- 返回:
- the string
-
encryptRequestMessage
public String encryptRequestMessage(String message, Certificate certificate)
对请求敏感字段进行加密- 参数:
message- the messagecertificate- the certificate- 返回:
- encrypt message
-
getCertificate
public X509WechatCertificateInfo getCertificate()
Get certificate x 509 wechat certificate info.- 返回:
- the x 509 wechat certificate info
-
wechatMetaContainer
public WechatMetaContainer wechatMetaContainer()
Wechat meta container.- 返回:
- the wechat meta container
-
nonceStrGenerator
public org.springframework.util.IdGenerator nonceStrGenerator()
Nonce generator.- 返回:
- the id generator
-
-