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


    #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 获取微信凭证

      通过JavaScriptSerializer将json转换为对象,获取值

    多思考,多创新,才是正道!
  • 相关阅读:
    伸展树(SplayTree)的实现
    map的访问
    #pragma warning(disable 4786)
    debian sftp/ssh197
    debian 配置静态ip197
    deepin 安装tar.gz197
    npm构建vue项目197
    linux 常用命令197
    application/force-download 不生效197
    reids 安装197
  • 原文地址:https://www.cnblogs.com/zxtceq/p/5435181.html
Copyright © 2020-2023  润新知