zoukankan      html  css  js  c++  java
  • 网页授权获取用户基本信息

    微信授权登录。

    基本情况:认证的服务号;

    主要测试代码:

     public function openOAuth(){
            //获取回调连接中带有的code
            $code = $_GET['code'];
            //获取access_token openid
            $json = file_get_contents("https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx7a5423a6f023716c5&secret=6bb7bstddekxrsa3bdcd296979bfb66967f41&code=$code&grant_type=authorization_code");
            $json = json_decode($json);
    
            $refresh_token =  $json->refresh_token;
          //通过refresh_token 获取需要的access_token $json_ref
    = file_get_contents("https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=wx3a542a6f094310c5&grant_type=refresh_token&refresh_token=$refresh_token"); $json_ref = json_decode($json_ref); $access_token = $json_ref->access_token; $openId = $json_ref->openid; $json_userinfo = file_get_contents("https://api.weixin.qq.com/sns/userinfo?access_token=$access_token&openid=$openId&lang=zh_CN"); $json_userinfo = json_decode($json_userinfo); $nikename = $json_userinfo->nickname; $sex = $json_userinfo->sex; $area = $json_userinfo->province.'-'.$json_userinfo->city.'-'.$json_userinfo->country; $headimgurl = $json_userinfo->headimgurl; //echo $headimgurl; $privilege = $json_userinfo->privilege; $unionid = $json_userinfo->unionid; echo "<h1>展示身份信息</h1>"; echo"<h2>昵称:$nikename</h2>"; echo"<h2>性别:$sex</h2>"; echo"<h2>地址:$area</h2>"; echo'<h2>头像</h2><img src="'.$headimgurl.'">'; echo"<h2>privilege:$privilege </h2>"; echo"<h2>unionid:$unionid</h2>"; }

    个人完整文档;http://files.cnblogs.com/files/bin-pureLife/%E6%8E%88%E6%9D%83.zip

    APPID 等隐私处以替换。

    积累知识,分享知识,学习知识。
  • 相关阅读:
    Maven基本操作命令
    Android studio安装与配置
    java数据结构----图
    java数据结构----堆
    java数据结构----哈希表
    java数据结构----树
    java数据结构----链表
    java数据结构----队列,优先级队列
    java数据结构----栈
    java数据结构----数组篇
  • 原文地址:https://www.cnblogs.com/bin-pureLife/p/4113543.html
Copyright © 2011-2022 走看看