码迷,mamicode.com
首页 > 微信 > 详细

微信公众号开发总结

时间:2016-03-05 23:20:59      阅读:404      评论:0      收藏:0      [点我收藏+]

标签:

微信公众号开发总结:

1、微信公众号分为三种:服务号、订阅号、企业号

2、微信公众号API官方文档http://qydev.weixin.qq.com/wiki/index.php?title=%E9%A6%96%E9%A1%B5

3、获取Token,然后调用是否Token过期,一般设置7200(两小时)过期。

技术分享
public class TokenHelper
    {

      public string CorpID = "xxxxxxxxxx";

      public string CorpSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
       

      private string _Token;

      public string Token
      {
          get { return _Token; }
          set { _Token = value; }
      }

      public string GetToken(string URL)
      {
               /*获取AccessToken*/
              string Access_Token = string.Format(@"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={0}&corpsecret={1}",CorpID,CorpSecret);
              if (!string.IsNullOrEmpty(URL))
              {
                  Access_Token = URL;
              }
              HttpWebRequest request = WebRequest.Create(Access_Token) as HttpWebRequest;
              CookieContainer cookieContainer = new CookieContainer();
              request.CookieContainer = cookieContainer;
              request.AllowAutoRedirect = true;
              request.Method = "POST";
              request.ContentType = "text/html";
              request.Headers.Add("charset", "utf-8");
              HttpWebResponse response = request.GetResponse() as HttpWebResponse;
              Stream responseStream = response.GetResponseStream();
              StreamReader sr = new StreamReader(responseStream, Encoding.UTF8);
              Token = sr.ReadToEnd();

          return Token;
      }
View Code

4、获取Token后任意调用一个简单的方法,如提示过期,再重新获取。

技术分享

微信公众号开发总结

标签:

原文地址:http://www.cnblogs.com/p_db/p/5246018.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!