基本配置
public function getcode(){ //基本配置 $appid=''; $redirect_uri=urlencode("https://授权回调页面域名/plugs/task/getuserinfo"); $url=" header("location:".$url);}
获取信息
public function getuserinfo(){ $appid = ""; $secret = ""; //这里获取到了code $code = $_get['code']; //第一步:取得openid $oauth2url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret=".$secret."&code=".$code."&grant_type=authorization_code"; $oauth2 = $this->http_curl($oauth2url); //accestoken $access_token = $oauth2["access_token"]; //openid $openid = $oauth2['openid'];//第二步:根据全局access_token和openid查询用户信息$get_user_info_url = "https://api.weixin.qq.com/sns/userinfoaccess_token=".$access_token."&openid=".$openid."&lang=zh_cn";$userinfo = $this->http_curl($get_user_info_url); dump($userinfo); //打印用户信息 }
curl请求
function http_curl($url){//用curl传参$ch = curl_init(); curl_setopt($ch, curlopt_url, $url);curl_setopt($ch,curlopt_returntransfer,1);//关闭ssl验证 curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_ssl_verifyhost, false); curl_setopt($ch,curlopt_header, 0); $output = curl_exec($ch);curl_close($ch); return json_decode($output, true);}
本文讲解了如何通过php获取微信用户的openid和基本信息,更多相关内容请关注。
相关推荐:
php代码实现12306余票查询、价格查询功能
介绍php快速导出table数据相关教程
讲解php预定义接口之arrayaccess的使用方法
以上就是如何通过php获取微信用户的openid和基本信息的详细内容。
