微信开发之(二)获取access_token

官方文档说明:获取access tokenhtml

在上面的官方文档中咱们能够直接在最底下的连接里面进行测试例如:api

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

 

  是否必须 说明
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;
        }
相关文章
相关标签/搜索