微信获取用户资料报错,48001
有一个界页,使用了微信登录功能,己关注该公众的微信,可以正常通过,没有关注公众号的微信,就会报这个错误。
"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";