Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to obtain ACCESSTOKEN .net in the Development of Wechat Public platform

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about how to obtain ACCESSTOKEN .net in the development of Wechat public platform. I think it is very practical, so I share it with you. I hope you can get something after reading this article. Let's have a look with the editor.

After becoming a developer, Wechat platform will give you appid and secret, which are not available in Subscription account, so you can add menus, upload / download pictures and other functions with ACCESSTOKEN because you should apply for a service number.

Private string GetToken () {/ / can also write: / / return GetPage ("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid= your appid&secret= your secret", "); string res ="; HttpWebRequest req = (HttpWebRequest) HttpWebRequest.Create (" https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid= your appid&secret= your 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 (); List myACCESSTOKEN = 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); / / prepare the request. Try {/ / set parameters 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 (); / / send the request and get the corresponding response data response = request.GetResponse () as HttpWebResponse; / / until the request.GetResponse () program begins to send the Post request instream = response.GetResponseStream (); sr = new StreamReader (instream, encoding); / / returns the result page (html) code string content = sr.ReadToEnd (); string err = string.Empty Return content;} catch (Exception ex) {string err = ex.Message; Response.Write (err); return string.Empty;}} above is how to obtain ACCESSTOKEN .net in the development of Wechat public platform. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report