wechat-user-get.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | WeChatDeveloper
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2020 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://think.ctolog.com
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | github开源项目:https://github.com/zoujingli/WeChatDeveloper
  12. // +----------------------------------------------------------------------
  13. try {
  14. // 1. 手动加载入口文件
  15. include "../include.php";
  16. // 2. 准备公众号配置参数
  17. $config = include "./config.php";
  18. // 3. 创建接口实例
  19. // $wechat = \We::WeChatUser($config);
  20. // $wechat = new \WeChat\User($config);
  21. $wechat = \WeChat\User::instance($config);
  22. // 4. 获取用户列表
  23. $result = $wechat->getUserList();
  24. echo '<pre>';
  25. var_export($result);
  26. // 5. 批量获取用户资料
  27. foreach (array_chunk($result['data']['openid'], 100) as $item) {
  28. $userList = $wechat->getBatchUserInfo($item);
  29. var_export($userList);
  30. }
  31. } catch (Exception $e) {
  32. // 出错啦,处理下吧
  33. echo $e->getMessage() . PHP_EOL;
  34. }