Group.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 allen05ren <allen05ren@outlook.com>
  14. * @copyright 2016 overtrue <i@overtrue.me>
  15. *
  16. * @see https://github.com/overtrue
  17. * @see http://overtrue.me
  18. */
  19. namespace EasyWeChat\ShakeAround;
  20. use EasyWeChat\Core\AbstractAPI;
  21. /**
  22. * Class Group.
  23. */
  24. class Group extends AbstractAPI
  25. {
  26. const API_ADD = 'https://api.weixin.qq.com/shakearound/device/group/add';
  27. const API_UPDATE = 'https://api.weixin.qq.com/shakearound/device/group/update';
  28. const API_DELETE = 'https://api.weixin.qq.com/shakearound/device/group/delete';
  29. const API_GET_LIST = 'https://api.weixin.qq.com/shakearound/device/group/getlist';
  30. const API_GET_DETAIL = 'https://api.weixin.qq.com/shakearound/device/group/getdetail';
  31. const API_ADD_DEVICE = 'https://api.weixin.qq.com/shakearound/device/group/adddevice';
  32. const API_DELETE_DEVICE = 'https://api.weixin.qq.com/shakearound/device/group/deletedevice';
  33. /**
  34. * Add device group.
  35. *
  36. * @param string $name
  37. *
  38. * @return \EasyWeChat\Support\Collection
  39. */
  40. public function add($name)
  41. {
  42. $params = [
  43. 'group_name' => $name,
  44. ];
  45. return $this->parseJSON('json', [self::API_ADD, $params]);
  46. }
  47. /**
  48. * Update a device group name.
  49. *
  50. * @param int $groupId
  51. * @param string $name
  52. *
  53. * @return \EasyWeChat\Support\Collection
  54. */
  55. public function update($groupId, $name)
  56. {
  57. $params = [
  58. 'group_id' => intval($groupId),
  59. 'group_name' => $name,
  60. ];
  61. return $this->parseJSON('json', [self::API_UPDATE, $params]);
  62. }
  63. /**
  64. * Delete device group.
  65. *
  66. * @param int $groupId
  67. *
  68. * @return \EasyWeChat\Support\Collection
  69. */
  70. public function delete($groupId)
  71. {
  72. $params = [
  73. 'group_id' => intval($groupId),
  74. ];
  75. return $this->parseJSON('json', [self::API_DELETE, $params]);
  76. }
  77. /**
  78. * List all device groups.
  79. *
  80. * @param int $begin
  81. * @param int $count
  82. *
  83. * @return \EasyWeChat\Support\Collection
  84. */
  85. public function lists($begin, $count)
  86. {
  87. $params = [
  88. 'begin' => intval($begin),
  89. 'count' => intval($count),
  90. ];
  91. return $this->parseJSON('json', [self::API_GET_LIST, $params]);
  92. }
  93. /**
  94. * Get details of a device group.
  95. *
  96. * @param int $groupId
  97. * @param int $begin
  98. * @param int $count
  99. *
  100. * @return \EasyWeChat\Support\Collection
  101. */
  102. public function getDetails($groupId, $begin, $count)
  103. {
  104. $params = [
  105. 'group_id' => intval($groupId),
  106. 'begin' => intval($begin),
  107. 'count' => intval($count),
  108. ];
  109. return $this->parseJSON('json', [self::API_GET_DETAIL, $params]);
  110. }
  111. /**
  112. * Add one or more devices to a device group.
  113. *
  114. * @param int $groupId
  115. * @param array $deviceIdentifiers
  116. *
  117. * @return \EasyWeChat\Support\Collection
  118. */
  119. public function addDevice($groupId, array $deviceIdentifiers)
  120. {
  121. $params = [
  122. 'group_id' => intval($groupId),
  123. 'device_identifiers' => $deviceIdentifiers,
  124. ];
  125. return $this->parseJSON('json', [self::API_ADD_DEVICE, $params]);
  126. }
  127. /**
  128. * Remove one or more devices from a device group.
  129. *
  130. * @param int $groupId
  131. * @param array $deviceIdentifiers
  132. *
  133. * @return \EasyWeChat\Support\Collection
  134. */
  135. public function removeDevice($groupId, array $deviceIdentifiers)
  136. {
  137. $params = [
  138. 'group_id' => intval($groupId),
  139. 'device_identifiers' => $deviceIdentifiers,
  140. ];
  141. return $this->parseJSON('json', [self::API_DELETE_DEVICE, $params]);
  142. }
  143. }