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

获取微信的access_tokey,处理json格式的数据

时间:2016-04-26 15:52:10      阅读:508      评论:0      收藏:0      [点我收藏+]

标签:

#region 获取微信凭证
      public string GetAccessToken(string wechat_id)
      {
          string accessToken = "";
 
          DataTable dtwecaht = wechatdal.GetList("wechat_id=‘" + wechat_id + "‘").Tables[0];
 
          if (dtwecaht.Rows.Count > 0)
          {
              string respText = "";
              string wechat_appid = dtwecaht.Rows[0]["wechat_appid"].ToString();
              string wechat_appsecret = dtwecaht.Rows[0]["wechat_appsecret"].ToString();
              string url = string.Format(getAccessTokenUrl, wechat_appid, wechat_appsecret);
 
              HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
              HttpWebResponse response = (HttpWebResponse)request.GetResponse();
 
              using (Stream resStream = response.GetResponseStream())
              {
                  StreamReader reader = new StreamReader(resStream, Encoding.Default);
                  respText = reader.ReadToEnd();
                  resStream.Close();
              }
              JavaScriptSerializer Jss = new JavaScriptSerializer();
              Dictionary<stringobject> respDic = (Dictionary<stringobject>)Jss.DeserializeObject(respText);
 
              accessToken = respDic["access_token"].ToString();
          }
 
          return accessToken;
      }
      #endregion 获取微信凭证

获取微信的access_tokey,处理json格式的数据

标签:

原文地址:http://www.cnblogs.com/zxtceq/p/5435181.html

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