![【移动应用开发技术】asp.net如何开发微信验证消息功能_第1页](http://file4.renrendoc.com/view/90e6a6088c1a7591126a3d52aab40069/90e6a6088c1a7591126a3d52aab400691.gif)
![【移动应用开发技术】asp.net如何开发微信验证消息功能_第2页](http://file4.renrendoc.com/view/90e6a6088c1a7591126a3d52aab40069/90e6a6088c1a7591126a3d52aab400692.gif)
![【移动应用开发技术】asp.net如何开发微信验证消息功能_第3页](http://file4.renrendoc.com/view/90e6a6088c1a7591126a3d52aab40069/90e6a6088c1a7591126a3d52aab400693.gif)
![【移动应用开发技术】asp.net如何开发微信验证消息功能_第4页](http://file4.renrendoc.com/view/90e6a6088c1a7591126a3d52aab40069/90e6a6088c1a7591126a3d52aab400694.gif)
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【移动应用开发技术】如何开发微信验证消息功能
新建数据模型/upload/information/20201208/260/10292.jpg/upload/information/20201208/260/10293.jpg/upload/information/20201208/260/10294.jpg/upload/information/20201208/260/10295.jpgModel///
<summary>
///
微信推送消息模型
///
</summary>
public
class
WeChatMsgRequestModel
{
public
string
timestamp
{
get;
set;
}
public
string
nonce
{
get;
set;
}
public
string
msg_signature
{
get;
set;
}
}Filterpublic
class
WeChatRequestValidAttribute
:
ActionFilterAttribute
{
private
const
string
Token
=
"StupidMe";
public
override
void
OnActionExecuting(ActionExecutingContext
filterContext)
{
//参数适配
Model.FormatModel.WeChatMsgRequestModel
model
=
new
Model.FormatModel.WeChatMsgRequestModel()
{
nonce=
filterContext.HttpContext.Request.QueryString["nonce"],msg_signature=
filterContext.HttpContext.Request.QueryString["msg_signature"],timestamp=
filterContext.HttpContext.Request.QueryString["timestamp"]
};
//验证
if
(CheckSignature(model))
{
base.OnActionExecuting(filterContext);
}
}
private
bool
CheckSignature(Model.FormatModel.WeChatMsgRequestModel
model)
{
string
signature,
timestamp,
nonce,
tempStr;
//获取请求来的参数
signature
=
model.msg_signature;
timestamp
=
model.timestamp;
nonce
=
model.nonce;
//创建数组,将
Token,
timestamp,
nonce
三个参数加入数组
string[]
array
=
{
Token,
timestamp,
nonce
};
//进行排序
Array.Sort(array);
//拼接为一个字符串
tempStr
=
String.Join("",
array);
//对字符串进行
SHA1加密
tempStr
=
FormsAuthentication.HashPasswordForStoringInConfigFile(tempStr,
"SHA1").ToLower();
//判断signature
是否正确
if
(tempStr.Equals(signature))
{
return
true;
}
else
{
return
false;
}
}
}///
<summary>
///
日志助手
///
</summary>
private
static
Common.LogHelper
logger
=
new
Common.LogHelper(typeof(HomeController));
[Filters.WeChatRequestValid]
public
void
Valid(Model.FormatModel.WeChatMsgRequestModel
model)
{
if
(ModelState.IsValid)
{
try
{
//判断是否是POST请求
if
(HttpContext.Request.HttpMethod.ToUpper()
==
"POST")
{
//从请求的数据流中获取请求信息
using
(Stream
stream
=
HttpContext.Request.InputStream)
{
byte[]
postBytes
=
new
byte[stream.Length];
stream.Read(postBytes,
0,
(int)stream.Length);
string
postString
=
System.Text.Encoding.UTF8.GetString(postBytes);
Handle(postString,model);
}
}
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 临床口腔粘膜炎漱口方法及漱口时机
- DIV+CSS与javascript的结合运用
- 基于新信息技术的软件测试技术 课件 第8章 软件自动化测试概述
- 2022年度辽宁省安全员之C证(专职安全员)综合检测试卷B卷含答案
- 2022年度辽宁省安全员之B证(项目负责人)能力检测试卷B卷附答案
- 【可行性报告】2023年真空冷冻干燥机项目可行性研究分析报告
- 开展比赛活动策划方案范本(34篇)
- 三年级下册英语教案-Lesson 21 In the Restaurant∣冀教版
- 大学生当老师实习心得
- 集体劳动工资合同(3篇)
- S22天天高速安庆至潜山段(月山至潜山)环境影响报告书
- 51单片机简易计算器设计
- 我来教你玩音响
- 《疫苗管理法》解读【2020】
- 西式面点制作技术期末试卷及答案
- (完整word版)一级减速器设计说明书
- 2023年中建六局土木工程商务管理岗招聘笔试参考题库附带答案详解
- 信用修复申请文书(当事人适用)
- 光储电站储能系统调试方案
- 五金价格表完整版
- 宣传片整体服务方案
评论
0/150
提交评论