欢迎来到96微信群大全!我们致力于提供最全的微信群二维码大全,让您方便快捷加入微信群。本站是个人微信群经验免费分享网站,请勿用做商业用途
当前位置:96微信群大全 > 微信群学院 > 微信群百科 > asp.net开发微信微信群号群众平台之验证消息的切实性

asp.net开发微信微信群号群众平台之验证消息的切实性

标签:asp.net,开发,微信,群众,平台,验证,消息,切实性 网址:www.96qun.com 网站: 96微信群大全 浏览:1771
这篇文章主要说明了asp.net开发微信群众平台之验证消息的切实性的相干资料,需求的同伴可能考下 验证消息的切实性 在MVC Controller所在名目中减少过滤器,在过滤器中重写 public override void OnActionExecuting(ActionExecutingContext filterContext)

  这篇文章主要说明了asp.net开发微信平台验证消息的切实性的相干资料,需求的同伴可能考下

  验证消息的切实性

  在MVC Controller所在名目中减少过滤器,最全的微信群,最好的微信群,在过滤器中重写

  public override void OnActionExecuting(ActionExecutingContext filterContext)方法

  新建数据模型

asp.net开发微信微信群号大众平台之验证消息的实在性

  注:效劳器接纳消息时,最全的微信群,不再是signature而是msg_signature

  微信服务器推送消息到效劳器的HTTP申请报文示例

  POST /cgi-bin/wxpush? msg_signature=477715d11cdb4164915debcba66cb864d751f3e6×tamp=1409659813&nonce=1372623149 HTTP/1.1

  Host: qy.weixin.qq.com

  方法重写,最全的微信群,微信,完成抵消息的验证

  调用微信接入时验证的方法,不过参数需求小改变一下,多微信群,多微信群,驳回新建的数据模型

asp.net开发微信微信群号大众平台之验证消息的实在性
asp.net开发微信微信群号大众平台之验证消息的实在性

  在Action方法或在Controller上减少过滤器属性

asp.net开发微信微信群号大众平台之验证消息的实在性

  代码示例

  Model

  ?

1 2 3 4 5 6 7 8 9 10 /// <summary> /// 微信推送消息模型 /// </summary> public class WeChatMsgRequestModel { public string timestamp { get; set; } public string nonce { get; set; } public string msg_signature { get; set; } }

  Filter

  ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 public 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; } } }

  Controller Code

  ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 /// <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); } } } catch (Exception ex) { logger.Error("发作同样,同样信息:" + ex.Message + ex.StackTrace); } } }

  以上所述就是本文的全副内容 了,微信群二维码,宿愿大家可以青睐。

,最多的微信群,最好的微信群

本文来自网络采集,文中内容和观点不代表本站立场,本站不保证本文的准确性和真实性.关注微信群大全看更多微信群百科.

上一篇:http://www.96qun.com/weixinqunnew/baike/201609/13_3833.html 下一篇:http://www.96qun.com/weixinqunnew/baike/201609/14_3850.html
版权指引:
  • 本站稿件来互联网采集,如有侵权请联系删除,如需转载请保留出处及原文地址。
  • 96微信群大全:www.96qun.com

    优质微信群

    在线客服 关闭96微信群客服导航
    96微信群二维码大全热门栏目导航
    在线咨询 新手帮助 微信群文章 微信群大全