Public platform development and learning series (III): webpage authorization for obtaining basic user information and basic public information
Official documents: http://mp.weixin.qq.com/wiki/4/9ac2e7b1f1d22e9e57260f6553822520.html
In the interface permission table
Change it to the domain name of the server
According to the official documentation, an authorization Page Link is required, which can be implemented using the encapsulated OAuthApi. GetAuthorizeUrl () method.
1 menu. button. add (new MenuFull_RootButton () {key = "link", name = "link", type = ButtonType. view. toString (), 2 url = OAuthApi. getAuthorizeUrl (appId, "http://qxw1649420168.my3w.com/Home/GetUser", "123", OAuthScope. snsapi_userinfo) 3}); View Code
The callback link code is as follows:
1 public ActionResult GetUser (string code, string state) 2 {3 4 if (String. isNullOrEmpty (code) 5 {6 return Content ("unauthorized"); 7} 8 else 9 {10 OAuthAccessTokenResult result = OAuthApi. getAccessToken (appId, secret, code); 11 OAuthUserInfo userInfo = OAuthApi. getUserInfo (result. access_token, result. openid); 12 13 return Content (userInfo. nickname + "" + userInfo. openid); 14} 15} View Code