資源簡介
(附上說明文檔,讓大家快速通過回調(diào)驗(yàn)證)用C#寫的,網(wǎng)上找了很多但是都無法直接使用,也有部分遺漏,正好自己優(yōu)化一個分享給大家。例子是把用戶發(fā)送的消息回復(fù)給用戶,下載后只需在web.config配置好相應(yīng)的參數(shù),即可發(fā)布使用。

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.Security.Cryptography;
using?System.IO;
using?System.Net;
namespace?Tencent
{
????class?Cryptography
????{
????????public?static?UInt32?HostToNetworkOrder(UInt32?inval)
????????{
????????????UInt32?outval?=?0;
????????????for?(int?i?=?0;?i?4;?i++)
????????????????outval?=?(outval?<8)?+?((inval?>>?(i?*?8))?&?255);
????????????return?outval;
????????}
????????public?static?Int32?HostToNetworkOrder(Int32?inval)
????????{
????????????Int32?outval?=?0;
????????????for?(int?i?=?0;?i?4;?i++)
????????????????outval?=?(outval?<8)?+?((inval?>>?(i?*?8))?&?255);
????????????return?outval;
????????}
????????///?
????????///?解密方法
????????///?
????????///?密文
????????///?
????????///?
????????///?
????????public?static?string?AES_decrypt(String?Input?string?EncodingAESKey?ref?string?corpid)
????????{
????????????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[]?bCorpid?=?new?byte[btmpMsg.Length?-?20?-?len];
????????????Array.Copy(btmpMsg?20?bMsg?0?len);
????????????Array.Copy(btmpMsg?20?+?len?bCorpid?0?btmpMsg.Length?-?20?-?len);
????????????string?oriMsg?=?Encoding.UTF8.GetString(bMsg);
????????????corpid?=?Encoding.UTF8.GetString(bCorpid);
????????????return?oriMsg;
????????}
????????public?static?String?AES_encrypt(String?Input?string?EncodingAESKey?string?corpid)
????????{
????????????byte[]?Key;
????????????Key?=?Convert.Frombase64String(EncodingAESKey?+?“=“);
????????????byte[]?Iv?=?new?byte[16];
????????????Array.Copy(Key?Iv?16);
????????????string?Randcode?=?CreateRandCode(16);
????????????byte[]?bRand?=?Encoding.UTF8.GetBytes(Randcode);
????????????byte[]?bCorpid?=?Encoding.UTF8.GetBytes(corpid);
????????????byte[]?btmpMsg?=?Encoding.UTF8.GetBytes(Input);
????????????byte[]?bMsgLen?=?BitConverter.GetBytes(HostToNetworkOrder(btmpMsg.Length));
????????????byte[]?bMsg?=?new?byte[bRand.Length?+?bMsgLen.Length?+?bCorpid.Length?+?btmpMsg.Length];
????????????Array.Copy(bRand?bMsg?bRand.Length);
????????????Array.Copy(bMsgLen?0?bMsg?bRand.Length?bMsgLen.Length);
????????????Array.Copy(btmpMsg?0?bMsg?bRand.Length?+?bMsgLen.Length?btmpMsg.Length);
????????????Array.Copy(bCorpid?0?bMsg?bRand.Length?+?bMsgLen.Length?+?btmpMsg.Length?bCorpid.Length);
????????????return?AES_encrypt(bMsg?Iv?Key);
????????}
????????private?static?string?CreateRandCode(int?codeLen)
????????{
????????????string?codeSerial?=?“234567
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2016-06-29?11:09??Demo.WeChat\
?????目錄???????????0??2016-06-29?11:27??Demo.WeChat\Demo.Common\
?????目錄???????????0??2016-06-29?11:27??Demo.WeChat\Demo.Common\bin\
?????目錄???????????0??2016-06-29?11:27??Demo.WeChat\Demo.Common\bin\Debug\
?????目錄???????????0??2016-06-29?11:27??Demo.WeChat\Demo.Common\bin\Release\
?????文件????????8580??2016-06-23?16:15??Demo.WeChat\Demo.Common\Cryptography.cs
?????文件????????2583??2016-06-29?11:10??Demo.WeChat\Demo.Common\Demo.Common.csproj
?????文件?????????227??2016-06-22?01:17??Demo.WeChat\Demo.Common\Demo.Common.csproj.user
?????文件????????9151??2016-06-29?11:09??Demo.WeChat\Demo.Common\Log.cs
?????目錄???????????0??2016-06-29?11:27??Demo.WeChat\Demo.Common\obj\
?????目錄???????????0??2016-06-29?11:27??Demo.WeChat\Demo.Common\obj\Debug\
?????目錄???????????0??2016-06-29?11:27??Demo.WeChat\Demo.Common\obj\Debug\TempPE\
?????目錄???????????0??2016-06-29?11:27??Demo.WeChat\Demo.Common\obj\Release\
?????目錄???????????0??2016-06-29?11:27??Demo.WeChat\Demo.Common\obj\Release\TempPE\
?????目錄???????????0??2016-06-29?11:17??Demo.WeChat\Demo.Common\Properties\
?????文件????????1358??2016-06-22?01:17??Demo.WeChat\Demo.Common\Properties\AssemblyInfo.cs
?????文件????????4347??2016-06-29?11:10??Demo.WeChat\Demo.Common\weixinsendmessage.cs
?????文件???????10439??2016-06-23?16:17??Demo.WeChat\Demo.Common\WXBizMsgCrypt.cs
?????文件?????????662??2016-06-29?11:10??Demo.WeChat\Demo.Common\wxmessage.cs
?????目錄???????????0??2016-06-29?11:27??Demo.WeChat\Demo.WeChat\
?????文件????????1410??2016-06-29?11:09??Demo.WeChat\Demo.WeChat.sln
?????文件???????61440??2016-06-29?11:18??Demo.WeChat\Demo.WeChat.suo
?????目錄???????????0??2016-06-29?11:27??Demo.WeChat\Demo.WeChat\bin\
?????文件?????????444??2016-06-29?11:10??Demo.WeChat\Demo.WeChat\Default.aspx
?????文件????????7431??2016-06-29?11:16??Demo.WeChat\Demo.WeChat\Default.aspx.cs
?????文件?????????806??2016-06-29?11:11??Demo.WeChat\Demo.WeChat\Default.aspx.designer.cs
?????文件????????4521??2016-06-29?11:11??Demo.WeChat\Demo.WeChat\Demo.WeChat.csproj
?????文件????????1171??2016-06-24?09:31??Demo.WeChat\Demo.WeChat\Demo.WeChat.csproj.user
?????文件?????????980??2016-06-29?11:11??Demo.WeChat\Demo.WeChat\Demo.WeChat.Publish.xm
?????目錄???????????0??2016-06-29?11:27??Demo.WeChat\Demo.WeChat\obj\
?????目錄???????????0??2016-06-29?11:27??Demo.WeChat\Demo.WeChat\obj\Debug\
............此處省略7個文件信息
評論
共有 條評論