public class WxCryptUtil extends Object
对公众平台发送给公众账号的消息加解密示例代码. Copyright (c) 1998-2014 Tencent Inc. 针对org.apache.commons.codec.binary.Base64, 需要导入架包commons-codec-1.9(或commons-codec-1.8等其他版本) 官方下载地址:http://commons.apache.org/proper/commons-codec/download_codec.cgi
限定符和类型 | 类和说明 |
---|---|
static class |
WxCryptUtil.EncryptContext |
限定符和类型 | 字段和说明 |
---|---|
protected byte[] |
aesKey |
protected String |
appidOrCorpid |
protected String |
token |
构造器和说明 |
---|
WxCryptUtil() |
WxCryptUtil(String token,
String encodingAesKey,
String appidOrCorpid)
构造函数.
|
限定符和类型 | 方法和说明 |
---|---|
String |
decrypt(String cipherText)
对密文进行解密.
|
String |
decrypt(String msgSignature,
String timeStamp,
String nonce,
String encryptedXml)
已过时。
由于语义不清晰,置为过时方法,请查看替代方法
decryptXml(java.lang.String, java.lang.String, java.lang.String, java.lang.String) |
String |
decryptContent(String msgSignature,
String timeStamp,
String nonce,
String encryptedContent)
检验消息的真实性,并且获取解密后的明文.
|
String |
decryptXml(String msgSignature,
String timeStamp,
String nonce,
String encryptedXml)
检验消息的真实性,并且获取解密后的明文.
|
String |
encrypt(String plainText)
将公众平台回复用户的消息加密打包.
|
String |
encrypt(String randomStr,
String plainText)
对明文进行加密.
|
WxCryptUtil.EncryptContext |
encryptContext(String plainText)
将公众平台回复用户的消息加密打包.
|
protected byte[] aesKey
protected String token
protected String appidOrCorpid
public String encrypt(String plainText)
plainText
- 公众平台待回复用户的消息,xml格式的字符串public WxCryptUtil.EncryptContext encryptContext(String plainText)
plainText
- 公众平台待回复用户的消息,xml格式的字符串public String encrypt(String randomStr, String plainText)
plainText
- 需要加密的明文public String decryptXml(String msgSignature, String timeStamp, String nonce, String encryptedXml)
msgSignature
- 签名串,对应URL参数的msg_signaturetimeStamp
- 时间戳,对应URL参数的timestampnonce
- 随机串,对应URL参数的nonceencryptedXml
- 包含 Encrypt 密文的 xml,对应POST请求的数据@Deprecated public String decrypt(String msgSignature, String timeStamp, String nonce, String encryptedXml)
decryptXml(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
msgSignature
- 签名串,对应URL参数的msg_signaturetimeStamp
- 时间戳,对应URL参数的timestampnonce
- 随机串,对应URL参数的nonceencryptedXml
- 包含 Encrypt 密文的 xml,对应POST请求的数据public String decryptContent(String msgSignature, String timeStamp, String nonce, String encryptedContent)
msgSignature
- 签名串,对应URL参数的msg_signaturetimeStamp
- 时间戳,对应URL参数的timestampnonce
- 随机串,对应URL参数的nonceencryptedContent
- 加密文本体Copyright © 2024. All rights reserved.