微信网页授权获取用户信息失败
通过OAuth实现自定义View菜单的网页授权跳转,跳转页面为GetUserInfoByOAuth.aspx,使用公众号为微信公众平台提供的测试号。
GetUserInfoByOAuth部分代码如下:
WeChatUserInfo userInfo = WeChatAuthorize.GetUserInfoByOAuth(out errorMessage);
if (userInfo != null)
{
Response.Write("OpenId->" + userInfo.openid + " Nickname->" + userInfo.nickname);
}
else
{
Response.Write("OMG,未获取到用户信息~" + errorMessage.errmsg);
}
微信测试号自定义菜单View的url为:string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect",appId,redirectUrl);
问题出来了,
问题一:点击菜单项,scope是snsapi_userinfo,却没有授权跳转提示,听说测试号只能是关注的用户才能实现网页授权跳转,但是无授权提示是怎么回事?又不是snsapi_base。
问题二:跳转虽然无提示,却成功跳转,页面上却只有OpenId-> Nickname->,没有实际的openid和nickname的值。能够输出OpenId->表示userInfo不为空,但是怎么实际的值却无法显示出来呢?
问题三:写了一个StreamWriter writer = new StreamWriter(HttpContext.Current.Server.MapPath(".") + "\\Log.md", true);
writer.WriteLine(userInfo.openid); 运行之后服务器上的Log.md没有任何内容。
一次问了三个问题,求各位大侠大神不吝赐教!