微信公众号获取微信用户信息

对于微信用户来说,唯一标识就是OpenID(就是加密后的微信号,对于不同用户,所对应的OpenID是不一样的),但是还有一个问题就是只有当微信用户关注了微信公众号后,此时对应返回的subscribe的值为1的时候,此时说明的是微信用户已经关注了微信公众号,值为0时,表示没有关注。

公众号可通过本接口来根据OpenID获取用户基本信息,包括昵称、头像、性别、所在城市、语言和关注时间。

在需要通过OpenID来实现获取用户的信息时,此时使用的是https协议。

微信公众号可以获取的微信用户信息:

 

 

具体实现步骤:

==>先要获取到appidappsecret,并且对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);

        }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值