微信开发之(二)获取access_token

官方文档说明:获取access token

在上面的官方文档中我们可以直接在最底下的链接里面进行测试例如:

https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET

 是否必须说明
grant_type 获取access_token填写client_credential
appid 第三方用户唯一凭证
secret 第三方用户唯一凭证密钥,即appsecret

C#代码:

         /// <summary>
        /// 获取访问凭证
        /// </summary>
        /// <returns></returns>
        private string GetAccessToken()
        {
            string url_token = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx114078ffd192d5&secret=c76fc416e4d9e33e9c9ddb2d4bc9e3";
            HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url_token);
            myRequest.Method = "GET";
            HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
            StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
            string content = reader.ReadToEnd(); 
            reader.Close();
            return content;
        }
原文地址:https://www.cnblogs.com/professional-NET/p/5665342.html