In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how Wechat development through authorization to obtain the basic information of users, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article. Let's take a look at it!
Fill in the domain name of the authorization callback page
Fill in wx.alinq.org here. After obtaining the user's authorization, it jumps to a page specified by the developer whose link must be under the domain name. If it is not filled in, a page with an invalid link will appear.
Second, guide the user to the specified authorization page
For example: https://open.weixin.qq.com/connect/oauth3/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect
For the explanation of the parameters, please refer to the relevant documents of Wechat. It is worth noting that redirect_uri is a url, it must be url-encoded, after generating the url, you can go to http://cli.im/text/2014052714?4QbdC to generate a QR code for url, and then scan it in Wechat to test.
After scanning:
Finally, the fully implemented code is presented.
The following is the complete code, I hope it will be useful to you. ^ _ ^
Public class UserAuth: IHttpHandler {public void ProcessRequest (HttpContext context) {var appid = "wxf1c24c60e3ac13b7"; var secret = "5902b9817acb7a290d4b7c2e6e97d4d3"; var code = context.Request.QueryString ["Code"] If (string.IsNullOrEmpty (code)) {var url = string.Format ("https://open.weixin.qq.com/connect/oauth3/authorize?appid={0}&redirect_uri=http%3a%2f%2fwx.alinq.org%2fTest%2fUserAuth.ashx&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect", appid); context.Response.Redirect (url)) } else {var client = new System.Net.WebClient (); client.Encoding = System.Text.Encoding.UTF8; var url = string.Format ("https://api.weixin.qq.com/sns/oauth3/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code", appid, secret, code); var data = client.DownloadString (url) Var serializer = new JavaScriptSerializer (); var obj = serializer.Deserialize (data); string accessToken; if (! obj.TryGetValue ("access_token", out accessToken)) return; var opentid = obj ["openid"] Url = string.Format ("https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}&lang=zh_CN", accessToken, opentid); data = client.DownloadString (url); var userInfo = serializer.Deserialize (data) Foreach (var key in userInfo.Keys) {context.Response.Write (string.Format ("{0}: {1}", key, userInfo [key]) + ");} these are all the contents of the article" how Wechat developers get basic information about users through authorization ". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.