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

  1. 1、根据公众号的appid获取code  
  2.     $APPID=APPID;//公众号在微信的appid  
  3.     $REDIRECT_URI='http://www.ific.cc/check.php';//回调页面      
  4.     // $scope='snsapi_base';  
  5.     $scope='snsapi_userinfo';//需要授权  
  6.     $url="https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$APPID."&redirect_uri=".urlencode($REDIRECT_URI)."&response_type=code&scope=".$scope."&state=STATE#wechat_redirect";  
  7.     header("Location:".$url);  
  8. 特:  
  9.  -->此处必须修改公众号的获取用户信息的回调url  
  10.   
  11. 2.check.php页面  
  12. $code = $_GET['code'];  
  13. $state = $_GET['state'];  
  14.   
  15. /*根据code获取用户openid*/  
  16. $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx72e1ef917e46fc68&secret=eb209bfaa8effa31f4508cea9788f5d0&code=".$code."&grant_type=authorization_code";  
  17.   
  18. $abs = file_get_contents($url);  
  19. $obj=json_decode($abs);  
  20. $access_token = $obj->access_token;  
  21. $openid = $obj->openid;  
  22. /*根据code获取用户openid end*/  
  23.   
  24.   
  25. /*根据用户openid获取用户基本信息*/  
  26. $abs_url = "https://api.weixin.qq.com/sns/userinfo?access_token=".$access_token."&openid=".$openid."&lang=zh_CN";  
  27. $abs_url_data = file_get_contents($abs_url);  
  28. $obj_data=json_decode($abs_url_data);  
  29. echo $OpenId = $obj_data->openid;  
  30.   
  31. echo $NickName = $obj_data->nickname;  
  32. /*根据用户openid获取用户基本信息*/   
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值