EVENT - 解析后的事件明文public abstract class AbstractCallbackCrypto<EVENT> extends Object
| Modifier and Type | Field and Description |
|---|---|
private static String |
BASE_ |
private static String |
BOM |
private CallbackAsyncConsumer<EVENT> |
callbackAsyncConsumer |
private static String |
MSG |
private static Random |
RANDOM |
private XmlReader |
xmlReader |
| Constructor and Description |
|---|
AbstractCallbackCrypto(XmlReader xmlReader,
CallbackAsyncConsumer<EVENT> callbackAsyncConsumer)
构造函数
|
| Modifier and Type | Method and Description |
|---|---|
<T> T |
accept(EVENT eventBody,
T response)
Accept t.
|
private CallbackDecrypted |
decrypt(byte[] aesKey,
String text)
对密文进行解密.
|
CallbackDecrypted |
decrypt(CallbackSettings callbackSettings,
String msgSignature,
String timeStamp,
String nonce,
String encrypt)
解密验签,用于解密XML BODY以及校验回调URL真实性
|
String |
encrypt(String receiveid,
byte[] aesKey,
String randomStr,
String text)
对明文进行加密.
|
String |
encryptJsonMsg(CallbackSettings callbackSettings,
String replyMsg,
String timeStamp,
String nonce)
将企业微信回复用户的消息加密打包.
|
String |
encryptXmlMsg(CallbackSettings callbackSettings,
String replyMsg,
String timeStamp,
String nonce)
Encrypt xml msg string.
|
(package private) byte[] |
getNetworkBytesOrder(int sourceNumber)
生成4个字节的网络字节序
|
(package private) String |
randomStr()
随机生成16位字符串
|
<T extends XmlEntity> |
readXml(String xmlBody,
Class<T> clazz)
Read xml t.
|
(package private) int |
recoverNetworkBytesOrder(byte[] orderBytes)
还原4个字节的网络字节序
|
private static final String BOM
private static final String BASE_
private static final String MSG
private static final Random RANDOM
private final XmlReader xmlReader
private final CallbackAsyncConsumer<EVENT> callbackAsyncConsumer
public AbstractCallbackCrypto(XmlReader xmlReader, CallbackAsyncConsumer<EVENT> callbackAsyncConsumer)
xmlReader - the xml readercallbackAsyncConsumer - the callback consumerpublic String encrypt(String receiveid, byte[] aesKey, String randomStr, String text) throws IllegalArgumentException
receiveid - the receiveidaesKey - the aes keyrandomStr - the random strtext - 需要加密的明文IllegalArgumentException - aes加密失败private CallbackDecrypted decrypt(byte[] aesKey, String text) throws IllegalArgumentException
aesKey - the aes keytext - 需要解密的密文IllegalArgumentException - aes解密失败public String encryptJsonMsg(CallbackSettings callbackSettings, String replyMsg, String timeStamp, String nonce)
callbackSettings - the callback settingsreplyMsg - 企业微信待回复用户的消息,json格式的字符串timeStamp - 时间戳,可以自己生成,也可以用URL参数的timestampnonce - 随机串,可以自己生成,也可以用URL参数的noncepublic String encryptXmlMsg(CallbackSettings callbackSettings, String replyMsg, String timeStamp, String nonce)
callbackSettings - the callback settingsreplyMsg - the reply msgtimeStamp - the time stampnonce - the noncepublic <T> T accept(EVENT eventBody, T response)
T - the type parametereventBody - the event bodyresponse - the responsepublic CallbackDecrypted decrypt(CallbackSettings callbackSettings, String msgSignature, String timeStamp, String nonce, String encrypt)
callbackSettings - the callback settingsmsgSignature - the msg signaturetimeStamp - the time stampnonce - the nonceencrypt - the encryptpublic <T extends XmlEntity> T readXml(String xmlBody, Class<T> clazz)
T - the type parameterxmlBody - the xml bodyclazz - the clazzbyte[] getNetworkBytesOrder(int sourceNumber)
sourceNumber - the source numberint recoverNetworkBytesOrder(byte[] orderBytes)
orderBytes - the order bytesString randomStr()
Copyright © 2024. All rights reserved.