心理咨询网
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * @copyright (C)2016-2099 Hnaoyun Inc.
  4. * @author XingMeng
  5. * @email hnxsh@foxmail.com
  6. * @date 2019年5月27日
  7. *
  8. */
  9. namespace core\weixin;
  10. class WxUser
  11. {
  12. // 获取指定用户信息
  13. public function getUserInfo($openid)
  14. {
  15. $access_token = WxAccessToken::get();
  16. $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $access_token . "&openid=$openid&lang=zh_CN";
  17. $result = json_decode(get_url($url));
  18. if (isset($result->errcode) && $result->errcode) {
  19. error('获取微信用户信息发生错误:' . $result->errmsg . '(' . $result->errcode . ')');
  20. } else {
  21. return $result;
  22. }
  23. }
  24. // 获取用户列表
  25. public function getUserList($getinfo = false, $next_openid = '')
  26. {
  27. $access_token = WxAccessToken::get();
  28. $url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=" . $access_token . "&next_openid=" . $next_openid;
  29. $result = json_decode(get_url($url));
  30. if (isset($result->errcode) && $result->errcode) {
  31. error('获取微信用户列表发生错误:' . $result->errmsg . '(' . $result->errcode . ')');
  32. } else {
  33. if ($getinfo) {
  34. foreach ($result->data->openid as $key => $value) {
  35. $result->data->userinfo[] = $this->getUserInfo($value);
  36. }
  37. }
  38. return $result;
  39. }
  40. }
  41. // 设置用户标记
  42. public function setUserRemark($openid, $remark)
  43. {
  44. $access_token = WxAccessToken::get();
  45. $url = "https://api.weixin.qq.com/cgi-bin/user/info/updateremark?access_token=" . $access_token;
  46. $data = array(
  47. 'openid' => $openid,
  48. 'remark' => $remark
  49. );
  50. $result = json_decode(get_url($url, json_encode($data, JSON_UNESCAPED_UNICODE)));
  51. if (isset($result->errcode) && $result->errcode) {
  52. error('获取微信用户信息发生错误:' . $result->errmsg . '(' . $result->errcode . ')');
  53. } else {
  54. return true;
  55. }
  56. }
  57. }