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.
 
 
 
 
 
 

151 lines
3.5 KiB

  1. <?php
  2. /*
  3. * This file is part of the overtrue/wechat.
  4. *
  5. * (c) overtrue <i@overtrue.me>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. /**
  11. * Group.php.
  12. *
  13. * @author overtrue <i@overtrue.me>
  14. * @copyright 2015 overtrue <i@overtrue.me>
  15. *
  16. * @see https://github.com/overtrue
  17. * @see http://overtrue.me
  18. */
  19. namespace EasyWeChat\User;
  20. use EasyWeChat\Core\AbstractAPI;
  21. /**
  22. * Class Group.
  23. */
  24. class Group extends AbstractAPI
  25. {
  26. const API_GET = 'https://api.weixin.qq.com/cgi-bin/groups/get';
  27. const API_CREATE = 'https://api.weixin.qq.com/cgi-bin/groups/create';
  28. const API_UPDATE = 'https://api.weixin.qq.com/cgi-bin/groups/update';
  29. const API_DELETE = 'https://api.weixin.qq.com/cgi-bin/groups/delete';
  30. const API_USER_GROUP_ID = 'https://api.weixin.qq.com/cgi-bin/groups/getid';
  31. const API_MEMBER_UPDATE = 'https://api.weixin.qq.com/cgi-bin/groups/members/update';
  32. const API_MEMBER_BATCH_UPDATE = 'https://api.weixin.qq.com/cgi-bin/groups/members/batchupdate';
  33. /**
  34. * Create group.
  35. *
  36. * @param string $name
  37. *
  38. * @return \EasyWeChat\Support\Collection
  39. */
  40. public function create($name)
  41. {
  42. $params = [
  43. 'group' => ['name' => $name],
  44. ];
  45. return $this->parseJSON('json', [self::API_CREATE, $params]);
  46. }
  47. /**
  48. * List all groups.
  49. *
  50. * @return \EasyWeChat\Support\Collection
  51. */
  52. public function lists()
  53. {
  54. return $this->parseJSON('get', [self::API_GET]);
  55. }
  56. /**
  57. * Update a group name.
  58. *
  59. * @param int $groupId
  60. * @param string $name
  61. *
  62. * @return \EasyWeChat\Support\Collection
  63. */
  64. public function update($groupId, $name)
  65. {
  66. $params = [
  67. 'group' => [
  68. 'id' => $groupId,
  69. 'name' => $name,
  70. ],
  71. ];
  72. return $this->parseJSON('json', [self::API_UPDATE, $params]);
  73. }
  74. /**
  75. * Delete group.
  76. *
  77. * @param int $groupId
  78. *
  79. * @return \EasyWeChat\Support\Collection
  80. */
  81. public function delete($groupId)
  82. {
  83. $params = [
  84. 'group' => ['id' => $groupId],
  85. ];
  86. return $this->parseJSON('json', [self::API_DELETE, $params]);
  87. }
  88. /**
  89. * Get user group.
  90. *
  91. * @param string $openId
  92. *
  93. * @return \EasyWeChat\Support\Collection
  94. */
  95. public function userGroup($openId)
  96. {
  97. $params = ['openid' => $openId];
  98. return $this->parseJSON('json', [self::API_USER_GROUP_ID, $params]);
  99. }
  100. /**
  101. * Move user to a group.
  102. *
  103. * @param string $openId
  104. * @param int $groupId
  105. *
  106. * @return \EasyWeChat\Support\Collection
  107. */
  108. public function moveUser($openId, $groupId)
  109. {
  110. $params = [
  111. 'openid' => $openId,
  112. 'to_groupid' => $groupId,
  113. ];
  114. return $this->parseJSON('json', [self::API_MEMBER_UPDATE, $params]);
  115. }
  116. /**
  117. * Batch move users to a group.
  118. *
  119. * @param array $openIds
  120. * @param int $groupId
  121. *
  122. * @return \EasyWeChat\Support\Collection
  123. */
  124. public function moveUsers(array $openIds, $groupId)
  125. {
  126. $params = [
  127. 'openid_list' => $openIds,
  128. 'to_groupid' => $groupId,
  129. ];
  130. return $this->parseJSON('json', [self::API_MEMBER_BATCH_UPDATE, $params]);
  131. }
  132. }