zoukankan      html  css  js  c++  java
  • 微信订阅号,获取用户openid

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

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

          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

       /// <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;
                }
    
            }            
    

      

  • 相关阅读:
    基于Metaweblog API 接口一键发布到国内外主流博客平台
    uva144 Student Grants
    Uva 10452
    Uva 439 Knight Moves
    Uva 352 The Seasonal War
    switch语句
    java——基础知识
    我的lua学习2
    codeforces 431 D. Random Task 组合数学
    codeforces 285 D. Permutation Sum 状压 dfs打表
  • 原文地址:https://www.cnblogs.com/zitjubiz/p/7043144.html
Copyright © 2011-2022 走看看