Client.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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\Payment\Bill;
  11. use EasyWeChat\Kernel\Http\StreamResponse;
  12. use EasyWeChat\Payment\Kernel\BaseClient;
  13. class Client extends BaseClient
  14. {
  15. /**
  16. * Download bill history as a table file.
  17. *
  18. * @return \EasyWeChat\Kernel\Http\StreamResponse|\Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  19. *
  20. * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
  21. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  22. * @throws \GuzzleHttp\Exception\GuzzleException
  23. */
  24. public function get(string $date, string $type = 'ALL', array $optional = [])
  25. {
  26. $params = [
  27. 'appid' => $this->app['config']->app_id,
  28. 'bill_date' => $date,
  29. 'bill_type' => $type,
  30. ] + $optional;
  31. $response = $this->requestRaw($this->wrap('pay/downloadbill'), $params);
  32. if (0 === strpos($response->getBody()->getContents(), '<xml>')) {
  33. return $this->castResponseToType($response, $this->app['config']->get('response_type'));
  34. }
  35. return StreamResponse::buildFromPsrResponse($response);
  36. }
  37. }