对于微信用户来说,唯一标识就是OpenID(就是加密后的微信号,对于不同用户,所对应的OpenID是不一样的),但是还有一个问题就是只有当微信用户关注了微信公众号后,此时对应返回的subscribe的值为1的时候,此时说明的是微信用户已经关注了微信公众号,值为0时,表示没有关注。
公众号可通过本接口来根据OpenID获取用户基本信息,包括昵称、头像、性别、所在城市、语言和关注时间。
在需要通过OpenID来实现获取用户的信息时,此时使用的是https协议。
微信公众号可以获取的微信用户信息:
具体实现步骤:
==>先要获取到appid、appsecret,并且对OAuth2.0网页授权,也就是对回调域名进行验证。
举例:
https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8888888888888888&redirect_uri=http://mascot.duapp.com/oauth2.php&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect
如这里在微信平台上进行验证的时候使用的redirect_uri时使用的是mascot.duapp.com。
===>获取code
/// <summary>
/// 获取code
/// appid
/// redirect_uri
/// response_type=code
/// scope=snsapi_userinfo
/// 举例:https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8888888888888888&redirect_uri=http://mascot.duapp.com/oauth2.php&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect
/// </summary>
public string GetCodeUrl(string Appid, string redirect_uri)
{
return string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect", Appid, redirect_uri);
}