Client.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. namespace EasyWeChat\MiniProgram\NearbyPoi;
  11. use EasyWeChat\Kernel\BaseClient;
  12. use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
  13. /**
  14. * Class Client.
  15. *
  16. * @author joyeekk <xygao2420@gmail.com>
  17. */
  18. class Client extends BaseClient
  19. {
  20. /**
  21. * Add nearby poi.
  22. *
  23. * @param array $params
  24. *
  25. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  26. *
  27. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  28. */
  29. public function add(array $params)
  30. {
  31. $params = array_merge([
  32. 'is_comm_nearby' => '1',
  33. 'poi_id' => '',
  34. ], $params);
  35. return $this->httpPostJson('wxa/addnearbypoi', $params);
  36. }
  37. /**
  38. * Update nearby poi.
  39. *
  40. * @param string $poiId
  41. * @param array $params
  42. *
  43. * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
  44. *
  45. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  46. */
  47. public function update(string $poiId, array $params)
  48. {
  49. $params = array_merge([
  50. 'is_comm_nearby' => '1',
  51. 'poi_id' => $poiId,
  52. ], $params);
  53. return $this->httpPostJson('wxa/addnearbypoi', $params);
  54. }
  55. /**
  56. * Delete nearby poi.
  57. *
  58. * @param string $poiId
  59. *
  60. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  61. */
  62. public function delete(string $poiId)
  63. {
  64. return $this->httpPostJson('wxa/delnearbypoi', [
  65. 'poi_id' => $poiId,
  66. ]);
  67. }
  68. /**
  69. * Get nearby poi list.
  70. *
  71. * @param int $page
  72. * @param int $pageRows
  73. *
  74. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  75. */
  76. public function list(int $page, int $pageRows)
  77. {
  78. return $this->httpGet('wxa/getnearbypoilist', [
  79. 'page' => $page,
  80. 'page_rows' => $pageRows,
  81. ]);
  82. }
  83. /**
  84. * Set nearby poi show status.
  85. *
  86. * @param string $poiId
  87. * @param int $status
  88. *
  89. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  90. */
  91. public function setVisibility(string $poiId, int $status)
  92. {
  93. if (!in_array($status, [0, 1], true)) {
  94. throw new InvalidArgumentException('status should be 0 or 1.');
  95. }
  96. return $this->httpPostJson('wxa/setnearbypoishowstatus', [
  97. 'poi_id' => $poiId,
  98. 'status' => $status,
  99. ]);
  100. }
  101. }