• 微信公众平台获取微信用户信息


    1: 进入开发者管理中心 ---网页服务-----网页账号------网页授权获取用户基本信息  修改  改成自己网站的根域名 格式 如下图

                                  

    2:建立一个连接

    3: 具体获取数据的代码

    //获取用户信息的函数 $accesstoken $openud
    function usertoken($accesstoken,$openid){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://api.weixin.qq.com/sns/userinfo?access_token=".$accesstoken."&openid=".$openid );
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
    // curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $tmpInfo = curl_exec($ch);
    if (curl_errno($ch)) {
    echo 'Errno'.curl_error($ch);
    }
    curl_close($ch);
    $arr= json_decode($tmpInfo,true);
    return $arr;
    }


    //curltest("wx53cfe3a3e22780e8","28510dc852912a604bdd3ce8a6aaa9a5",$code);获取到的凭证
    function getUserinfo($appid,$secret,$code){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret=".$secret."&code=".$code."&grant_type=authorization_code");
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
    //curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $tmpInfo = curl_exec($ch);
    if (curl_errno($ch)) {
    //echo 'Errno'.curl_error($ch);
    }
    curl_close($ch);
    $arr= json_decode($tmpInfo,true);
    return usertoken($arr['access_token'], $arr['openid']);
    }

  • 相关阅读:
    SSM整合初级 简单的增删改查
    初始SpringMVC
    初始Spring MVC
    Web Service简介
    Quartz框架 实现任务调度
    搭建james邮件服务器
    使用Jdbc Template的基本操作步骤
    spring AOP四种实现方式
    Struts2数据校验
    Struts2 与Servlet API解耦,耦合的访问方式
  • 原文地址:https://www.cnblogs.com/QQ42246692/p/4536603.html
Copyright © 2020-2023  润新知