我用的是官方给的C#示例代码Cryptography.cs中的AES_decrypt解密方法,传进来的Input="D7yzvUNAL930rd28wf21s4hvXhz0L6Uit/p2Di6C5DHyYGpEgdBRnKjBec34JwoQXicwaZC7fOVihW80F4VtsdvE//1vr7oAbqjDv8KenVp+ajKYpJnyQ4zMRhIC+a31fCVOMC03FfzV/QuC94kBP55a+Za3sJgvAn+ZbsNqZI5DkyuzkhQN8OBqCzFhizGmy0xpM0MEA4agpvE+RuNO1rhHTtuJB5yltw1FiYzecSXJ+y/D2r81VkRn2eYjh2ltsoyfbDR7Is6ookXIFxTfyeNyeHxMeT4KN5WpCDmSbTcUYrbBUlkGLJ9n/rU8YOywma6G7aTb7KZKOqCxgfoUlYEZPk4FUL/TK7ShriFDMVCLyjQJ15Ob++agDWtcxhfUfe6HIoIpRW8mKNBQiY/Jd1svvuskA1wLef1RTtzKfMpagSCX/laZINmdnX4zrF6kIaR9P4xQrWXbsTFHTYe0Mg=="
这个是官方文档中的消息推送介绍里的示例包体
EncodingAESKey="1223334444555556666667777777888888887777777"
public static string AES_decrypt(String Input, string EncodingAESKey, ref string appid)
{
byte[] Key;
Key = Convert.FromBase64String(EncodingAESKey + "=");
byte[] Iv = new byte[16];
Array.Copy(Key, Iv, 16);
byte[] btmpMsg = AES_decrypt(Input, Iv, Key);
int len = BitConverter.ToInt32(btmpMsg, 16);
len = IPAddress.NetworkToHostOrder(len);
byte[] bMsg = new byte[len];
byte[] bAppid = new byte[btmpMsg.Length - 20 - len];
Array.Copy(btmpMsg, 20, bMsg, 0, len);
Array.Copy(btmpMsg, 20+len , bAppid, 0, btmpMsg.Length - 20 - len);
string oriMsg = Encoding.UTF8.GetString(bMsg);
appid = Encoding.UTF8.GetString(bAppid);
return oriMsg;
}
代码走到byte[] bAppid= new byte[btmpMsg.Length - 20 - len]时btmpMsg.Length=352,len=1273545308。
然后捕获异常:System.OverflowException:“Arithmetic operation resulted in an overflow.”
此异常最初是在此调用堆栈中引发的:
Tencent.Cryptography.AES_decrypt(string, string, ref string) - 位于 Cryptography.cs
Tencent.WXBizMsgCrypt.DecryptMsg(string, string, string, string, ref string) - 位于 WXBizMsgCrypt.cs
你好,请自查aeskey和token等是否都配置正确了,参考https://developers.weixin.qq.com/community/develop/article/doc/000c2a14b54b407d09e1e73a769c13 核查
麻烦大佬们看一下,第一次接入不太懂