Client.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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\Express;
  11. use EasyWeChat\Kernel\BaseClient;
  12. use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
  13. /**
  14. * Class Client.
  15. *
  16. * @author kehuanhuan <1152018701@qq.com>
  17. */
  18. class Client extends BaseClient
  19. {
  20. /**
  21. * 绑定、解绑物流账号
  22. * @param array $params
  23. * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
  24. * @throws InvalidArgumentException
  25. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  26. */
  27. public function bind(array $params = [])
  28. {
  29. if (empty($params['type']) || empty($params['biz_id']) || empty($params['delivery_id'])) {
  30. throw new InvalidArgumentException('Missing parameter.');
  31. }
  32. return $this->httpPostJson('cgi-bin/express/business/account/bind', $params);
  33. }
  34. /**
  35. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  36. *
  37. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  38. */
  39. public function listProviders()
  40. {
  41. return $this->httpGet('cgi-bin/express/business/delivery/getall');
  42. }
  43. /**
  44. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  45. *
  46. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  47. */
  48. public function getAllAccount()
  49. {
  50. return $this->httpGet('cgi-bin/express/business/account/getall');
  51. }
  52. /**
  53. * @param array $params
  54. *
  55. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  56. *
  57. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  58. * @throws \GuzzleHttp\Exception\GuzzleException
  59. */
  60. public function createWaybill(array $params = [])
  61. {
  62. return $this->httpPostJson('cgi-bin/express/business/order/add', $params);
  63. }
  64. /**
  65. * @param array $params
  66. *
  67. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  68. *
  69. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  70. * @throws \GuzzleHttp\Exception\GuzzleException
  71. */
  72. public function deleteWaybill(array $params = [])
  73. {
  74. return $this->httpPostJson('cgi-bin/express/business/order/cancel', $params);
  75. }
  76. /**
  77. * @param array $params
  78. *
  79. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  80. *
  81. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  82. * @throws \GuzzleHttp\Exception\GuzzleException
  83. */
  84. public function getWaybill(array $params = [])
  85. {
  86. return $this->httpPostJson('cgi-bin/express/business/order/get', $params);
  87. }
  88. /**
  89. * @param array $params
  90. *
  91. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  92. *
  93. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  94. * @throws \GuzzleHttp\Exception\GuzzleException
  95. */
  96. public function getWaybillTrack(array $params = [])
  97. {
  98. return $this->httpPostJson('cgi-bin/express/business/path/get', $params);
  99. }
  100. /**
  101. * @param string $deliveryId
  102. * @param string $bizId
  103. *
  104. * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
  105. *
  106. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  107. * @throws \GuzzleHttp\Exception\GuzzleException
  108. */
  109. public function getBalance(string $deliveryId, string $bizId)
  110. {
  111. return $this->httpPostJson('cgi-bin/express/business/quota/get', [
  112. 'delivery_id' => $deliveryId,
  113. 'biz_id' => $bizId,
  114. ]);
  115. }
  116. /**
  117. * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
  118. *
  119. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  120. * @throws \GuzzleHttp\Exception\GuzzleException
  121. */
  122. public function getPrinter()
  123. {
  124. return $this->httpPostJson('cgi-bin/express/business/printer/getall');
  125. }
  126. /**
  127. * @param string $openid
  128. *
  129. * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
  130. *
  131. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  132. * @throws \GuzzleHttp\Exception\GuzzleException
  133. */
  134. public function bindPrinter(string $openid)
  135. {
  136. return $this->httpPostJson('cgi-bin/express/business/printer/update', [
  137. 'update_type' => 'bind',
  138. 'openid' => $openid,
  139. ]);
  140. }
  141. /**
  142. * @param string $openid
  143. *
  144. * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
  145. *
  146. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  147. * @throws \GuzzleHttp\Exception\GuzzleException
  148. */
  149. public function unbindPrinter(string $openid)
  150. {
  151. return $this->httpPostJson('cgi-bin/express/business/printer/update', [
  152. 'update_type' => 'unbind',
  153. 'openid' => $openid,
  154. ]);
  155. }
  156. /**
  157. * 创建退货 ID
  158. * @param array $params
  159. * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
  160. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  161. */
  162. public function createReturn(array $params = [])
  163. {
  164. return $this->httpPostJson('cgi-bin/express/delivery/return/add', $params);
  165. }
  166. /**
  167. * 查询退货 ID 状态
  168. * @param string $returnId
  169. * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
  170. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  171. */
  172. public function getReturn(string $returnId)
  173. {
  174. return $this->httpPostJson('cgi-bin/express/delivery/return/get', [
  175. 'return_id' => $returnId
  176. ]);
  177. }
  178. /**
  179. * 解绑退货 ID
  180. * @param string $returnId
  181. * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
  182. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  183. */
  184. public function unbindReturn(string $returnId)
  185. {
  186. return $this->httpPostJson('cgi-bin/express/delivery/return/unbind', [
  187. 'return_id' => $returnId
  188. ]);
  189. }
  190. }