wechat-user-get.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | WeChatDeveloper
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2023 ThinkAdmin [ thinkadmin.top ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: https://thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // | 免责声明 ( https://thinkadmin.top/disclaimer )
  11. // +----------------------------------------------------------------------
  12. // | gitee 代码仓库:https://gitee.com/zoujingli/WeChatDeveloper
  13. // | github 代码仓库:https://github.com/zoujingli/WeChatDeveloper
  14. // +----------------------------------------------------------------------
  15. try {
  16. // 1. 手动加载入口文件
  17. include "../include.php";
  18. // 2. 准备公众号配置参数
  19. $config = include "./config.php";
  20. // 3. 创建接口实例
  21. // $wechat = \We::WeChatUser($config);
  22. // $wechat = new \WeChat\User($config);
  23. $wechat = \WeChat\User::instance($config);
  24. // 4. 获取用户列表
  25. $result = $wechat->getUserList();
  26. echo '<pre>';
  27. var_export($result);
  28. // 5. 批量获取用户资料
  29. foreach (array_chunk($result['data']['openid'], 100) as $item) {
  30. $userList = $wechat->getBatchUserInfo($item);
  31. var_export($userList);
  32. }
  33. } catch (Exception $e) {
  34. // 出错啦,处理下吧
  35. echo $e->getMessage() . PHP_EOL;
  36. }