随笔 - 435  文章 - 0  评论 - 110  阅读 - 62万 

在微信后台,启用服务器配置。

服务器URL地址,要通过Token的验证。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
private void Auth()
  {
      string token = ConfigurationManager.AppSettings["WeixinToken"];//从配置文件获取Token
      if (string.IsNullOrEmpty(token))
      {              
          LogTextHelper.Error(string.Format("WeixinToken 配置项没有配置!"));
      }
 
      string echoString = HttpContext.Current.Request.QueryString["echoStr"];
      string signature = HttpContext.Current.Request.QueryString["signature"];
      string timestamp = HttpContext.Current.Request.QueryString["timestamp"];
      string nonce = HttpContext.Current.Request.QueryString["nonce"];
 
      if (CheckSignature(token, signature, timestamp, nonce))
      {
          if (!string.IsNullOrEmpty(echoString))
          {
              HttpContext.Current.Response.Write(echoString);
              HttpContext.Current.Response.End();
          }
      }
  }

  关注订阅号,发一个文本消息。里面有用户的openid

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/// <summary>
     /// 主入口
     /// </summary>
     /// <param name="msg"></param>
     private void OnRecvEvent(ReqMsgEventBase msg)
     {
         switch (msg.Event)
         {
             case Event.LOCATION:
                 break;
             case Event.subscribe:
                  string content = “openid=”+msg.FromUserName;
                 SendResponseText(msg, content);
                 break;
             case Event.unsubscribe:
                 break;
             default:
                 break;
         }
 
     }           

  

posted on   Gu  阅读(15672)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 记一次.NET内存居高不下排查解决与启示
点击右上角即可分享
微信分享提示