微信公众平台开发中如何获得ACCESSTOKEN.Net-创新互联
本篇文章给大家分享的是有关微信公众平台开发中如何获得ACCESSTOKEN .Net,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
站在用户的角度思考问题,与客户深入沟通,找到来安网站设计与来安网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:网站建设、成都做网站、企业官网、英文网站、手机端网站、网站推广、域名申请、虚拟主机、企业邮箱。业务覆盖来安地区。成为了开发者之后微信平台会给您appid和secret,在订阅号中是没有的,所以因该申请一下服务号,有了ACCESSTOKEN才能做添加菜单,上传/下载图片等功能。
private string GetToken() { // 也可以这样写: //return GetPage("/tupian/20230522/token string res = ""; HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential &appid=你的appid&secret=你的secret"); req.Method = "GET"; using (WebResponse wr = req.GetResponse()) { HttpWebResponse myResponse = (HttpWebResponse)req.GetResponse(); StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8); string content = reader.ReadToEnd(); ListmyACCESSTOKEN = Json.JSONStringToList (content); res = myACCESSTOKEN[0].access_token; } return res; } public string GetPage(string posturl, string postData) { Stream outstream = null; Stream instream = null; StreamReader sr = null; HttpWebResponse response = null; HttpWebRequest request = null; Encoding encoding = Encoding.UTF8; byte[] data = encoding.GetBytes(postData); // 准备请求... try { // 设置参数 request = WebRequest.Create(posturl) as HttpWebRequest; CookieContainer cookieContainer = new CookieContainer(); request.CookieContainer = cookieContainer; request.AllowAutoRedirect = true; request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = data.Length; outstream = request.GetRequestStream(); outstream.Write(data, 0, data.Length); outstream.Close(); //发送请求并获取相应回应数据 response = request.GetResponse() as HttpWebResponse; //直到request.GetResponse()程序才开始向目标网页发送Post请求 instream = response.GetResponseStream(); sr = new StreamReader(instream, encoding); //返回结果网页(html)代码 string content = sr.ReadToEnd(); string err = string.Empty; return content; } catch (Exception ex) { string err = ex.Message; Response.Write(err); return string.Empty; } }
以上就是微信公众平台开发中如何获得ACCESSTOKEN .Net,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注创新互联行业资讯频道。
网页标题:微信公众平台开发中如何获得ACCESSTOKEN.Net-创新互联
网页URL:http://ybzwz.com/article/gpsds.html