💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
#### **1、获取用户信息用什么函数?** 下面介绍两种传参方式 (1) `getUserInfo($uid, $update = false, $field = ''); 或 getUserInfo($openid, $update = false, $field = '');` (2) `$uid = get_mid(); //用户uid获取方法 $openid = get_openid(); //用户openid获取方法 $update和$field为非必填参数` #### **2、获取用户信息的示例展示** (1)控制器代码部分 `<?php namespace Addons\MengVote\Controller; use Home\Controller\AddonsController; class MengVoteController extends AddonsController{ public function index(){ $info = getUserInfo(get_mid()); //var_dump($info); 此处可以打印调试,查看$info数据的所有字段信息 $this->assign('info',$info); } }` (2)前端渲染 ` <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no"> <meta name="format-detection" content="telephone=no"> <title>洛杉矶豪哥</title> <link rel="stylesheet" href="css/frozen.css"> <script src="js/zepto.min.js"></script> <script src="js/frozen.js"></script> </head> <body class="main"> <header class="ui-header ui-header-stable ui-border-b"> <img src="{$info['headimgurl']}"> <h1>{$info['nickname']}</h1> <i class="ui-icon-return"></i> <a href="xufei.html"><button class="ui-btn">续费</button></a> </header> </body> </html>` >说明 **{$info['headimgurl']} 获取个人图片地址** **{$info['nickname']} 获取个人昵称** **......以此类推可以获取$info数组的所有信息** >var_dump($info);打印$info结果如下: `array (size=39) 'uid' => string '2' (length=1) //用户id 'nickname' => string '北北' (length=9) //用户昵称 'password' => null //密码 当为管理员时有 'truename' => null //真实姓名 'mobile' => null //手机号码 'email' => null //邮箱 'sex' => string '1' (length=1) //性别 0:保密 1:男 2:女 'headimgurl' => string //头像链接 'http://wx.qlogo.cn/mmopen/AhLk989Zrl06FmvQyLHwRTollf4IJzgU2O7zzBX3X9JMLheTE25zC6eXH5icJkOOsk4Xr963tiak0RxOkYicBdxow/0' (length=117) 'city' => string 'Xiangtan' (length=8) //所在城市 'province' => string 'Hunan' (length=5) //所在身份 'country' => string 'China' (length=5) //所在国家 'language' => string 'zh_CN' (length=5) //语言 'score' => string '100' (length=3) //积分 'experience' => string '100' (length=3) 'unionid' => string 'o11POw3MnY9lAJGZYJpbNs_XAMVU' (length=28) //用户unionid 统一开发者账户下的所有公众号中的同一用户unionid相同 'login_count' => string '0' (length=1) 'reg_ip' => null 'reg_time' => string '1451656809' (length=10) 'last_login_ip' => null 'last_login_time' => null 'status' => string '1' (length=1) 'is_init' => string '1' (length=1) 'is_audit' => string '1' (length=1) 'subscribe_time' => string '1451656809' (length=10) 'remark' => string '' (length=0) 'groupid' => string '0' (length=1) 'come_from' => string '0' (length=1) 'login_name' => null 'login_password' => null 'manager_id' => string '0' (length=1) 'level' => string '0' (length=1) 'membership' => string '0' (length=1) 'public_count' => null 'groups' => array (size=0) empty 'tokens' => array (size=1) 'wx1ff336758fc06f1d' => string 'ob8oYv3rrZuh-7ScINExlsrwJuhI' (length=28) 'remarks' => array (size=1) 'wx1ff336758fc06f1d' => null 'has_subscribe' => array (size=1) 'wx1ff336758fc06f1d' => string '1' (length=1) 'is_root' => boolean false 'sex_name' => string '男' (length=3)` #### **3、获取用户信息的示例效果图** ![](https://box.kancloud.cn/2016-01-24_56a3cbef2c8c5.png)