WechatUser.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | wechat-php-sdk
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2017 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方文档: https://www.kancloud.cn/zoujingli/wechat-php-sdk
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | github开源项目:https://github.com/zoujingli/wechat-php-sdk
  12. // +----------------------------------------------------------------------
  13. namespace Wechat;
  14. use Wechat\Lib\Common;
  15. use Wechat\Lib\Tools;
  16. /**
  17. * 微信粉丝操作SDK
  18. *
  19. * @author Anyon <zoujingli@qq.com>
  20. * @date 2016/06/28 11:20
  21. */
  22. class WechatUser extends Common
  23. {
  24. /** 获取粉丝列表 */
  25. const USER_GET_URL = '/user/get?';
  26. /* 获取粉丝信息 */
  27. const USER_INFO_URL = '/user/info?';
  28. /* 批量获取粉丝信息 */
  29. const USER_BATCH_INFO_URL = '/user/info/batchget?';
  30. /* 更新粉丝标注 */
  31. const USER_UPDATEREMARK_URL = '/user/info/updateremark?';
  32. /** 创建标签 */
  33. const TAGS_CREATE_URL = '/tags/create?';
  34. /* 获取标签列表 */
  35. const TAGS_GET_URL = '/tags/get?';
  36. /* 更新标签 */
  37. const TAGS_UPDATE_URL = '/tags/update?';
  38. /* 删除标签 */
  39. const TAGS_DELETE_URL = '/tags/delete?';
  40. /* 获取标签下的粉丝列表 */
  41. const TAGS_GET_USER_URL = '/user/tag/get?';
  42. /* 批量为粉丝打标签 */
  43. const TAGS_MEMBER_BATCHTAGGING = '/tags/members/batchtagging?';
  44. /* 批量为粉丝取消标签 */
  45. const TAGS_MEMBER_BATCHUNTAGGING = '/tags/members/batchuntagging?';
  46. /* 获取粉丝的标签列表 */
  47. const TAGS_LIST = '/tags/getidlist?';
  48. /** 获取分组列表 */
  49. const GROUP_GET_URL = '/groups/get?';
  50. /* 获取粉丝所在的分组 */
  51. const USER_GROUP_URL = '/groups/getid?';
  52. /* 创建分组 */
  53. const GROUP_CREATE_URL = '/groups/create?';
  54. /* 更新分组 */
  55. const GROUP_UPDATE_URL = '/groups/update?';
  56. /* 删除分组 */
  57. const GROUP_DELETE_URL = '/groups/delete?';
  58. /* 修改粉丝所在分组 */
  59. const GROUP_MEMBER_UPDATE_URL = '/groups/members/update?';
  60. /* 批量修改粉丝所在分组 */
  61. const GROUP_MEMBER_BATCHUPDATE_URL = '/groups/members/batchupdate?';
  62. /** 获取黑名单列表 */
  63. const BACKLIST_GET_URL = '/tags/members/getblacklist?';
  64. /* 批量拉黑粉丝 */
  65. const BACKLIST_ADD_URL = '/tags/members/batchblacklist?';
  66. /* 批量取消拉黑粉丝 */
  67. const BACKLIST_DEL_URL = '/tags/members/batchunblacklist?';
  68. /**
  69. * 批量获取关注粉丝列表
  70. * @param string $next_openid
  71. * @return bool|array
  72. */
  73. public function getUserList($next_openid = '')
  74. {
  75. if (!$this->access_token && !$this->getAccessToken()) {
  76. return false;
  77. }
  78. $result = Tools::httpGet(self::API_URL_PREFIX . self::USER_GET_URL . "access_token={$this->access_token}&next_openid={$next_openid}");
  79. if ($result) {
  80. $json = json_decode($result, true);
  81. if (empty($json) || !empty($json['errcode'])) {
  82. $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
  83. $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
  84. return $this->checkRetry(__FUNCTION__, func_get_args());
  85. }
  86. return $json;
  87. }
  88. return false;
  89. }
  90. /**
  91. * 获取关注者详细信息
  92. * @param string $openid
  93. * @return bool|array {subscribe,openid,nickname,sex,city,province,country,language,headimgurl,subscribe_time,[unionid]}
  94. * @注意:unionid字段 只有在粉丝将公众号绑定到微信开放平台账号后,才会出现。建议调用前用isset()检测一下
  95. */
  96. public function getUserInfo($openid)
  97. {
  98. if (!$this->access_token && !$this->getAccessToken()) {
  99. return false;
  100. }
  101. $result = Tools::httpGet(self::API_URL_PREFIX . self::USER_INFO_URL . "access_token={$this->access_token}&openid={$openid}");
  102. if ($result) {
  103. $json = json_decode($result, true);
  104. if (empty($json) || !empty($json['errcode'])) {
  105. $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
  106. $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
  107. return $this->checkRetry(__FUNCTION__, func_get_args());
  108. }
  109. return $json;
  110. }
  111. return false;
  112. }
  113. /**
  114. * 批量获取用户基本信息
  115. * @param array $openids 用户oepnid列表(最多支持100个openid)
  116. * @param string $lang 指定返回语言
  117. * @return bool|mixed
  118. */
  119. public function getUserBatchInfo(array $openids, $lang = 'zh_CN')
  120. {
  121. if (!$this->access_token && !$this->getAccessToken()) {
  122. return false;
  123. }
  124. $data = array('user_list' => array());
  125. foreach (array_unique($openids) as $openid) {
  126. $data['user_list'][] = array('openid' => $openid, 'lang' => $lang);
  127. }
  128. $result = Tools::httpPost(self::API_URL_PREFIX . self::USER_BATCH_INFO_URL . "access_token={$this->access_token}", Tools::json_encode($data));
  129. if ($result) {
  130. $json = json_decode($result, true);
  131. if (empty($json) || !empty($json['errcode']) || !isset($json['user_info_list'])) {
  132. $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
  133. $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
  134. return $this->checkRetry(__FUNCTION__, func_get_args());
  135. }
  136. return $json['user_info_list'];
  137. }
  138. return false;
  139. }
  140. /**
  141. * 设置粉丝备注名
  142. * @param string $openid
  143. * @param string $remark 备注名
  144. * @return bool|array
  145. */
  146. public function updateUserRemark($openid, $remark)
  147. {
  148. if (!$this->access_token && !$this->getAccessToken()) {
  149. return false;
  150. }
  151. $data = array('openid' => $openid, 'remark' => $remark);
  152. $result = Tools::httpPost(self::API_URL_PREFIX . self::USER_UPDATEREMARK_URL . "access_token={$this->access_token}", Tools::json_encode($data));
  153. if ($result) {
  154. $json = json_decode($result, true);
  155. if (empty($json) || !empty($json['errcode'])) {
  156. $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
  157. $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
  158. return $this->checkRetry(__FUNCTION__, func_get_args());
  159. }
  160. return $json;
  161. }
  162. return false;
  163. }
  164. /**
  165. * 获取粉丝分组列表
  166. * @return bool|array
  167. */
  168. public function getGroup()
  169. {
  170. if (!$this->access_token && !$this->getAccessToken()) {
  171. return false;
  172. }
  173. $result = Tools::httpGet(self::API_URL_PREFIX . self::GROUP_GET_URL . "access_token={$this->access_token}");
  174. if ($result) {
  175. $json = json_decode($result, true);
  176. if (empty($json) || !empty($json['errcode'])) {
  177. $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
  178. $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
  179. return $this->checkRetry(__FUNCTION__, func_get_args());
  180. }
  181. return $json;
  182. }
  183. return false;
  184. }
  185. /**
  186. * 删除粉丝分组
  187. * @param type $id
  188. * @return bool
  189. */
  190. public function delGroup($id)
  191. {
  192. if (!$this->access_token && !$this->getAccessToken()) {
  193. return false;
  194. }
  195. $data = array('group' => array('id' => $id));
  196. $result = Tools::httpPost(self::API_URL_PREFIX . self::GROUP_DELETE_URL . "access_token={$this->access_token}", Tools::json_encode($data));
  197. if ($result) {
  198. $json = json_decode($result, true);
  199. if (empty($json) || !empty($json['errcode'])) {
  200. $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
  201. $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
  202. return $this->checkRetry(__FUNCTION__, func_get_args());
  203. }
  204. return $json;
  205. }
  206. return false;
  207. }
  208. /**
  209. * 获取粉丝所在分组
  210. * @param string $openid
  211. * @return bool|int 成功则返回粉丝分组id
  212. */
  213. public function getUserGroup($openid)
  214. {
  215. if (!$this->access_token && !$this->getAccessToken()) {
  216. return false;
  217. }
  218. $data = array('openid' => $openid);
  219. $result = Tools::httpPost(self::API_URL_PREFIX . self::USER_GROUP_URL . "access_token={$this->access_token}", Tools::json_encode($data));
  220. if ($result) {
  221. $json = json_decode($result, true);
  222. if (empty($json) || !empty($json['errcode']) || !isset($json['groupid'])) {
  223. $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
  224. $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
  225. return $this->checkRetry(__FUNCTION__, func_get_args());
  226. }
  227. return $json['groupid'];
  228. }
  229. return false;
  230. }
  231. /**
  232. * 新增自定分组
  233. * @param string $name 分组名称
  234. * @return bool|array
  235. */
  236. public function createGroup($name)
  237. {
  238. if (!$this->access_token && !$this->getAccessToken()) {
  239. return false;
  240. }
  241. $data = array('group' => array('name' => $name));
  242. $result = Tools::httpPost(self::API_URL_PREFIX . self::GROUP_CREATE_URL . "access_token={$this->access_token}", Tools::json_encode($data));
  243. if ($result) {
  244. $json = json_decode($result, true);
  245. if (empty($json) || !empty($json['errcode'])) {
  246. $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
  247. $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
  248. return $this->checkRetry(__FUNCTION__, func_get_args());
  249. }
  250. return $json;
  251. }
  252. return false;
  253. }
  254. /**
  255. * 更改分组名称
  256. * @param int $groupid 分组id
  257. * @param string $name 分组名称
  258. * @return bool|array
  259. */
  260. public function updateGroup($groupid, $name)
  261. {
  262. if (!$this->access_token && !$this->getAccessToken()) {
  263. return false;
  264. }
  265. $data = array('group' => array('id' => $groupid, 'name' => $name));
  266. $result = Tools::httpPost(self::API_URL_PREFIX . self::GROUP_UPDATE_URL . "access_token={$this->access_token}", Tools::json_encode($data));
  267. if ($result) {
  268. $json = json_decode($result, true);
  269. if (empty($json) || !empty($json['errcode'])) {
  270. $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
  271. $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
  272. return $this->checkRetry(__FUNCTION__, func_get_args());
  273. }
  274. return $json;
  275. }
  276. return false;
  277. }
  278. /**
  279. * 移动粉丝分组
  280. * @param int $groupid 分组id
  281. * @param string $openid 粉丝openid
  282. * @return bool|array
  283. */
  284. public function updateGroupMembers($groupid, $openid)
  285. {
  286. if (!$this->access_token && !$this->getAccessToken()) {
  287. return false;
  288. }
  289. $data = array('openid' => $openid, 'to_groupid' => $groupid);
  290. $result = Tools::httpPost(self::API_URL_PREFIX . self::GROUP_MEMBER_UPDATE_URL . "access_token={$this->access_token}", Tools::json_encode($data));
  291. if ($result) {
  292. $json = json_decode($result, true);
  293. if (empty($json) || !empty($json['errcode'])) {
  294. $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
  295. $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
  296. return $this->checkRetry(__FUNCTION__, func_get_args());
  297. }
  298. return $json;
  299. }
  300. return false;
  301. }
  302. /**
  303. * 批量移动粉丝分组
  304. * @param string $groupid 分组ID
  305. * @param string $openid_list 粉丝openid数组(一次不能超过50个)
  306. * @return bool|array
  307. */
  308. public function batchUpdateGroupMembers($groupid, $openid_list)
  309. {
  310. if (!$this->access_token && !$this->getAccessToken()) {
  311. return false;
  312. }
  313. $data = array('openid_list' => $openid_list, 'to_groupid' => $groupid);
  314. $result = Tools::httpPost(self::API_URL_PREFIX . self::GROUP_MEMBER_BATCHUPDATE_URL . "access_token={$this->access_token}", Tools::json_encode($data));
  315. if ($result) {
  316. $json = json_decode($result, true);
  317. if (empty($json) || !empty($json['errcode'])) {
  318. $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
  319. $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
  320. return $this->checkRetry(__FUNCTION__, func_get_args());
  321. }
  322. return $json;
  323. }
  324. return false;
  325. }
  326. /**
  327. * 新增自定标签
  328. * @param string $name 标签名称
  329. * @return bool|array
  330. */
  331. public function createTags($name)
  332. {
  333. if (!$this->access_token && !$this->getAccessToken()) {
  334. return false;
  335. }
  336. $data = array('tag' => array('name' => $name));
  337. $result = Tools::httpPost(self::API_URL_PREFIX . self::TAGS_CREATE_URL . "access_token={$this->access_token}", Tools::json_encode($data));
  338. if ($result) {
  339. $json = json_decode($result, true);
  340. if (empty($json) || !empty($json['errcode'])) {
  341. $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
  342. $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
  343. return $this->checkRetry(__FUNCTION__, func_get_args());
  344. }
  345. return $json;
  346. }
  347. return false;
  348. }
  349. /**
  350. * 更新标签
  351. * @param string $id 标签id
  352. * @param string $name 标签名称
  353. * @return bool|array
  354. */
  355. public function updateTag($id, $name)
  356. {
  357. if (!$this->access_token && !$this->getAccessToken()) {
  358. return false;
  359. }
  360. $data = array('tag' => array('id' => $id, 'name' => $name));
  361. $result = Tools::httpPost(self::API_URL_PREFIX . self::TAGS_UPDATE_URL . "access_token={$this->access_token}", Tools::json_encode($data));
  362. if ($result) {
  363. $json = json_decode($result, true);
  364. if (empty($json) || !empty($json['errcode'])) {
  365. $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
  366. $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
  367. return $this->checkRetry(__FUNCTION__, func_get_args());
  368. }
  369. return $json;
  370. }
  371. return false;
  372. }
  373. /**
  374. * 获取粉丝标签列表
  375. * @return bool|array
  376. */
  377. public function getTags()
  378. {
  379. if (!$this->access_token && !$this->getAccessToken()) {
  380. return false;
  381. }
  382. $result = Tools::httpGet(self::API_URL_PREFIX . self::TAGS_GET_URL . "access_token={$this->access_token}");
  383. if ($result) {
  384. $json = json_decode($result, true);
  385. if (empty($json) || !empty($json['errcode'])) {
  386. $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
  387. $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
  388. return $this->checkRetry(__FUNCTION__, func_get_args());
  389. }
  390. return $json;
  391. }
  392. return false;
  393. }
  394. /**
  395. * 删除粉丝标签
  396. * @param string $id
  397. * @return bool
  398. */
  399. public function delTag($id)
  400. {
  401. if (!$this->access_token && !$this->getAccessToken()) {
  402. return false;
  403. }
  404. $data = array('tag' => array('id' => $id));
  405. $result = Tools::httpPost(self::API_URL_PREFIX . self::TAGS_DELETE_URL . "access_token={$this->access_token}", Tools::json_encode($data));
  406. if ($result) {
  407. $json = json_decode($result, true);
  408. if (empty($json) || !empty($json['errcode'])) {
  409. $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
  410. $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
  411. return $this->checkRetry(__FUNCTION__, func_get_args());
  412. }
  413. return $json;
  414. }
  415. return false;
  416. }
  417. /**
  418. * 获取标签下的粉丝列表
  419. * @param string $tagid
  420. * @param string $next_openid
  421. * @return bool
  422. */
  423. public function getTagUsers($tagid, $next_openid = '')
  424. {
  425. if (!$this->access_token && !$this->getAccessToken()) {
  426. return false;
  427. }
  428. $data = array('tagid' => $tagid, 'next_openid' => $next_openid);
  429. $result = Tools::httpPost(self::API_URL_PREFIX . self::TAGS_GET_USER_URL . "access_token={$this->access_token}", Tools::json_encode($data));
  430. if ($result) {
  431. $json = json_decode($result, true);
  432. if (empty($json) || !empty($json['errcode'])) {
  433. $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
  434. $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
  435. return $this->checkRetry(__FUNCTION__, func_get_args());
  436. }
  437. return $json;
  438. }
  439. return false;
  440. }
  441. /**
  442. * 批量为粉丝打标签
  443. * @param string $tagid 标签ID
  444. * @param array $openid_list 粉丝openid数组,一次不能超过50个
  445. * @return bool|array
  446. */
  447. public function batchAddUserTag($tagid, $openid_list)
  448. {
  449. if (!$this->access_token && !$this->getAccessToken()) {
  450. return false;
  451. }
  452. $data = array('openid_list' => $openid_list, 'tagid' => $tagid);
  453. $result = Tools::httpPost(self::API_URL_PREFIX . self::TAGS_MEMBER_BATCHTAGGING . "access_token={$this->access_token}", Tools::json_encode($data));
  454. if ($result) {
  455. $json = json_decode($result, true);
  456. if (empty($json) || !empty($json['errcode'])) {
  457. $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
  458. $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
  459. return $this->checkRetry(__FUNCTION__, func_get_args());
  460. }
  461. return $json;
  462. }
  463. return false;
  464. }
  465. /**
  466. * 批量为粉丝取消标签
  467. * @param string $tagid 标签ID
  468. * @param array $openid_list 粉丝openid数组,一次不能超过50个
  469. * @return bool|array
  470. */
  471. public function batchDeleteUserTag($tagid, $openid_list)
  472. {
  473. if (!$this->access_token && !$this->getAccessToken()) {
  474. return false;
  475. }
  476. $data = array('openid_list' => $openid_list, 'tagid' => $tagid);
  477. $result = Tools::httpPost(self::API_URL_PREFIX . self::TAGS_MEMBER_BATCHUNTAGGING . "access_token={$this->access_token}", Tools::json_encode($data));
  478. if ($result) {
  479. $json = json_decode($result, true);
  480. if (empty($json) || !empty($json['errcode'])) {
  481. $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
  482. $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
  483. return $this->checkRetry(__FUNCTION__, func_get_args());
  484. }
  485. return $json;
  486. }
  487. return false;
  488. }
  489. /**
  490. * 获取粉丝的标签列表
  491. * @param string $openid 粉丝openid
  492. * @return bool|array
  493. */
  494. public function getUserTags($openid)
  495. {
  496. if (!$this->access_token && !$this->getAccessToken()) {
  497. return false;
  498. }
  499. $data = array('openid' => $openid);
  500. $result = Tools::httpPost(self::API_URL_PREFIX . self::TAGS_LIST . "access_token={$this->access_token}", Tools::json_encode($data));
  501. if ($result) {
  502. $json = json_decode($result, true);
  503. if (empty($json) || !empty($json['errcode']) || !isset($json['tagid_list'])) {
  504. $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
  505. $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
  506. return $this->checkRetry(__FUNCTION__, func_get_args());
  507. }
  508. return $json['tagid_list'];
  509. }
  510. return false;
  511. }
  512. /**
  513. * 批量获取黑名单粉丝
  514. * @param string $begin_openid
  515. * @return bool|array
  516. */
  517. public function getBacklist($begin_openid = '')
  518. {
  519. if (!$this->access_token && !$this->getAccessToken()) {
  520. return false;
  521. }
  522. $data = empty($begin_openid) ? array() : array('begin_openid' => $begin_openid);
  523. $result = Tools::httpPost(self::API_URL_PREFIX . self::BACKLIST_GET_URL . "access_token={$this->access_token}", Tools::json_encode($data));
  524. if ($result) {
  525. $json = json_decode($result, true);
  526. if (empty($json) || !empty($json['errcode'])) {
  527. $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
  528. $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
  529. return $this->checkRetry(__FUNCTION__, func_get_args());
  530. }
  531. return $json;
  532. }
  533. return false;
  534. }
  535. /**
  536. * 批量拉黑粉丝
  537. * @param string $openids
  538. * @return bool|array
  539. */
  540. public function addBacklist($openids)
  541. {
  542. if (!$this->access_token && !$this->getAccessToken()) {
  543. return false;
  544. }
  545. $data = array('openid_list' => $openids);
  546. $result = Tools::httpPost(self::API_URL_PREFIX . self::BACKLIST_ADD_URL . "access_token={$this->access_token}", Tools::json_encode($data));
  547. if ($result) {
  548. $json = json_decode($result, true);
  549. if (empty($json) || !empty($json['errcode'])) {
  550. $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
  551. $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
  552. return $this->checkRetry(__FUNCTION__, func_get_args());
  553. }
  554. return $json;
  555. }
  556. return false;
  557. }
  558. /**
  559. * 批量取消拉黑粉丝
  560. * @param string $openids
  561. * @return bool|array
  562. */
  563. public function delBacklist($openids)
  564. {
  565. if (!$this->access_token && !$this->getAccessToken()) {
  566. return false;
  567. }
  568. $data = array('openid_list' => $openids);
  569. $result = Tools::httpPost(self::API_URL_PREFIX . self::BACKLIST_DEL_URL . "access_token={$this->access_token}", Tools::json_encode($data));
  570. if ($result) {
  571. $json = json_decode($result, true);
  572. if (empty($json) || !empty($json['errcode'])) {
  573. $this->errCode = isset($json['errcode']) ? $json['errcode'] : '505';
  574. $this->errMsg = isset($json['errmsg']) ? $json['errmsg'] : '无法解析接口返回内容!';
  575. return $this->checkRetry(__FUNCTION__, func_get_args());
  576. }
  577. return $json;
  578. }
  579. return false;
  580. }
  581. }