微信公众号开发总结:

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后任意调用一个简单的方法,如提示过期,再重新获取。