国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

125 行
4.5KB

  1. <?php
  2. namespace WeChat;
  3. if (!defined('DEDEINC')) exit('dedebiz');
  4. use WeChat\Contracts\BasicWeChat;
  5. /**
  6. * 微信粉丝管理
  7. * Class User
  8. * @package WeChat
  9. */
  10. class User extends BasicWeChat
  11. {
  12. /**
  13. * 设置会员备注名
  14. * @param string $openid
  15. * @param string $remark
  16. * @return array
  17. * @throws Exceptions\InvalidResponseException
  18. * @throws \WeChat\Exceptions\LocalCacheException
  19. */
  20. public function updateMark($openid, $remark)
  21. {
  22. $url = 'https://api.weixin.qq.com/cgi-bin/user/info/updateremark?access_token=ACCESS_TOKEN';
  23. $this->registerApi($url, __FUNCTION__, func_get_args());
  24. return $this->httpPostForJson($url, ['openid' => $openid, 'remark' => $remark]);
  25. }
  26. /**
  27. * 获取会员基本信息(包括UnionID机制)
  28. * @param string $openid
  29. * @param string $lang
  30. * @return array
  31. * @throws Exceptions\InvalidResponseException
  32. * @throws Exceptions\LocalCacheException
  33. */
  34. public function getUserInfo($openid, $lang = 'zh_CN')
  35. {
  36. $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid={$openid}&lang={$lang}";
  37. $this->registerApi($url, __FUNCTION__, func_get_args());
  38. return $this->httpGetForJson($url);
  39. }
  40. /**
  41. * 批量获取会员基本信息
  42. * @param array $openids
  43. * @param string $lang
  44. * @return array
  45. * @throws Exceptions\InvalidResponseException
  46. * @throws Exceptions\LocalCacheException
  47. */
  48. public function getBatchUserInfo(array $openids, $lang = 'zh_CN')
  49. {
  50. $url = 'https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=ACCESS_TOKEN';
  51. $data = ['user_list' => []];
  52. foreach ($openids as $openid) {
  53. $data['user_list'][] = ['openid' => $openid, 'lang' => $lang];
  54. }
  55. $this->registerApi($url, __FUNCTION__, func_get_args());
  56. return $this->httpPostForJson($url, $data);
  57. }
  58. /**
  59. * 获取会员列表
  60. * @param string $next_openid
  61. * @return array
  62. * @throws Exceptions\InvalidResponseException
  63. * @throws Exceptions\LocalCacheException
  64. */
  65. public function getUserList($next_openid = '')
  66. {
  67. $url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&next_openid={$next_openid}";
  68. $this->registerApi($url, __FUNCTION__, func_get_args());
  69. return $this->httpGetForJson($url);
  70. }
  71. /**
  72. * 获取标签下粉丝列表
  73. * @param integer $tagid 标签ID
  74. * @param string $next_openid 第一个拉取的OPENID
  75. * @return array
  76. * @throws Exceptions\InvalidResponseException
  77. * @throws Exceptions\LocalCacheException
  78. */
  79. public function getUserListByTag($tagid, $next_openid = '')
  80. {
  81. $url = 'https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token=ACCESS_TOKEN';
  82. $this->registerApi($url, __FUNCTION__, func_get_args());
  83. return $this->httpPostForJson($url, ['tagid' => $tagid, 'next_openid' => $next_openid]);
  84. }
  85. /**
  86. * 获取公众号的黑名单列表
  87. * @param string $begin_openid
  88. * @return array
  89. * @throws Exceptions\InvalidResponseException
  90. * @throws Exceptions\LocalCacheException
  91. */
  92. public function getBlackList($begin_openid = '')
  93. {
  94. $url = "https://api.weixin.qq.com/cgi-bin/tags/members/getblacklist?access_token=ACCESS_TOKEN";
  95. $this->registerApi($url, __FUNCTION__, func_get_args());
  96. return $this->httpPostForJson($url, ['begin_openid' => $begin_openid]);
  97. }
  98. /**
  99. * 批量拉黑会员
  100. * @param array $openids
  101. * @return array
  102. * @throws Exceptions\InvalidResponseException
  103. * @throws Exceptions\LocalCacheException
  104. */
  105. public function batchBlackList(array $openids)
  106. {
  107. $url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchblacklist?access_token=ACCESS_TOKEN";
  108. $this->registerApi($url, __FUNCTION__, func_get_args());
  109. return $this->httpPostForJson($url, ['openid_list' => $openids]);
  110. }
  111. /**
  112. * 批量取消拉黑会员
  113. * @param array $openids
  114. * @return array
  115. * @throws Exceptions\InvalidResponseException
  116. * @throws Exceptions\LocalCacheException
  117. */
  118. public function batchUnblackList(array $openids)
  119. {
  120. $url = "https://api.weixin.qq.com/cgi-bin/tags/members/batchunblacklist?access_token=ACCESS_TOKEN";
  121. $this->registerApi($url, __FUNCTION__, func_get_args());
  122. return $this->httpPostForJson($url, ['openid_list' => $openids]);
  123. }
  124. }
  125. ?>