有一個界頁,使用了微信登錄功能,己關注該公眾的微信,可以正常通過,沒有關注公眾號的微信,就會報這個錯誤。
"errcode":48001,"errmsg":"api unauthorized, hints: [ req_id: Ftu8IA0999s106 ]"
//構造網頁授權獲取code的URL
string host = m_page.Request.Url.Host;
string path = m_page.Request.Path;
string redirect_uri = HttpUtility.UrlEncode("http://" + host + path);
OAuthData data = new OAuthData();
data.SetValue("appid", m_config.AppId);
data.SetValue("redirect_uri", redirect_uri);
data.SetValue("response_type", "code");
//data.SetValue("scope", "snsapi_base"); 使用這段代碼,在獲取用戶資料時就會報上述錯誤,
data.SetValue("scope", "snsapi_userinfo"); 正確應該是使用這段 代碼,
data.SetValue("state", "STATE" + "#wechat_redirect");
string url = "https://open.weixin.qq.com/connect/oauth2/authorize?" + data.ToUrl();
微信中其實是有兩個API都是獲取用戶信息的,網頁版的
這個API使用的方式又不一樣,在使用時需要特別注意。
https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN
該項目中使用的是下面的這個API
"https://api.weixin.qq.com/sns/userinfo?access_token=$ACCESS_TOKEN&openid=$OPENID&lang=zh_CN";
