官方文檔:http://mp.weixin.QQ.com/wiki/4/9ac2e7b1f1d22e9e57260f6553822520.html
在接口權限表
將其修改成服務器的域名
根據官方文檔,需要一個授權頁面鏈接,可以用封裝好的OAuthApi.GetAuthorizeUrl()方法實現
1 menu.button.Add(new MenuFull_RootButton() { key = "link", name = "鏈接", type = ButtonType.view.ToString(),2 url = OAuthApi.GetAuthorizeUrl(appId, "http://qxw1649420168.my3w.com/Home/GetUser", "123", OAuthScope.snsapi_userinfo)3 });
回調鏈接代碼如下:
1 public ActionResult GetUser(string code,string state) 2 { 3 4 if (String.IsNullOrEmpty(code)) 5 { 6 return Content("沒有授權"); 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 }
新聞熱點
疑難解答