资源简介
(附上说明文档,让大家快速通过回调验证)用C#写的,网上找了很多但是都无法直接使用,也有部分遗漏,正好自己优化一个分享给大家。例子是把用户发送的消息回复给用户,下载后只需在web.config配置好相应的参数,即可发布使用。

代码片段和文件信息
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个文件信息
相关资源
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
- C#自定义控件
- 基于c#的实验室设备管理系统621530
- C# 使用ListView控件实现图片浏览器(源
- C#简单窗体聊天程序
评论
共有 条评论