POI.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. * POI.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\POI;
  20. use EasyWeChat\Core\AbstractAPI;
  21. /**
  22. * Class POI.
  23. */
  24. class POI extends AbstractAPI
  25. {
  26. const API_CREATE = 'https://api.weixin.qq.com/cgi-bin/poi/addpoi';
  27. const API_GET = 'https://api.weixin.qq.com/cgi-bin/poi/getpoi';
  28. const API_LIST = 'https://api.weixin.qq.com/cgi-bin/poi/getpoilist';
  29. const API_UPDATE = 'https://api.weixin.qq.com/cgi-bin/poi/updatepoi';
  30. const API_DELETE = 'https://api.weixin.qq.com/cgi-bin/poi/delpoi';
  31. const API_GET_CATEGORIES = 'https://api.weixin.qq.com/cgi-bin/poi/getwxcategory';
  32. /**
  33. * Get POI supported categories.
  34. *
  35. * @return \EasyWeChat\Support\Collection
  36. */
  37. public function getCategories()
  38. {
  39. return $this->parseJSON('get', [self::API_GET_CATEGORIES]);
  40. }
  41. /**
  42. * Get POI by ID.
  43. *
  44. * @param int $poiId
  45. *
  46. * @return \EasyWeChat\Support\Collection
  47. */
  48. public function get($poiId)
  49. {
  50. return $this->parseJSON('json', [self::API_GET, ['poi_id' => $poiId]]);
  51. }
  52. /**
  53. * List POI.
  54. *
  55. * @param int $offset
  56. * @param int $limit
  57. *
  58. * @return \EasyWeChat\Support\Collection
  59. */
  60. public function lists($offset = 0, $limit = 10)
  61. {
  62. $params = [
  63. 'begin' => $offset,
  64. 'limit' => $limit,
  65. ];
  66. return $this->parseJSON('json', [self::API_LIST, $params]);
  67. }
  68. /**
  69. * Create a POI.
  70. *
  71. * @param array $data
  72. *
  73. * @return bool
  74. */
  75. public function create(array $data)
  76. {
  77. $params = [
  78. 'business' => ['base_info' => $data],
  79. ];
  80. return $this->parseJSON('json', [self::API_CREATE, $params]);
  81. }
  82. /**
  83. * @param array $data
  84. *
  85. * @return int
  86. */
  87. public function createAndGetId(array $data)
  88. {
  89. return $this->create($data)['poi_id'];
  90. }
  91. /**
  92. * Update a POI.
  93. *
  94. * @param int $poiId
  95. * @param array $data
  96. *
  97. * @return bool
  98. */
  99. public function update($poiId, array $data)
  100. {
  101. $data = array_merge($data, ['poi_id' => $poiId]);
  102. $params = [
  103. 'business' => ['base_info' => $data],
  104. ];
  105. return $this->parseJSON('json', [self::API_UPDATE, $params]);
  106. }
  107. /**
  108. * Delete a POI.
  109. *
  110. * @param int $poiId
  111. *
  112. * @return bool
  113. */
  114. public function delete($poiId)
  115. {
  116. $params = ['poi_id' => $poiId];
  117. return $this->parseJSON('json', [self::API_DELETE, $params]);
  118. }
  119. }