Client.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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\Redpack;
  11. use EasyWeChat\Kernel\Support;
  12. use EasyWeChat\Payment\Kernel\BaseClient;
  13. /**
  14. * Class Client.
  15. *
  16. * @author tianyong90 <412039588@qq.com>
  17. */
  18. class Client extends BaseClient
  19. {
  20. /**
  21. * Query redpack.
  22. *
  23. * @param mixed $mchBillno
  24. *
  25. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  26. *
  27. * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
  28. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  29. * @throws \GuzzleHttp\Exception\GuzzleException
  30. */
  31. public function info($mchBillno)
  32. {
  33. $params = is_array($mchBillno) ? $mchBillno : ['mch_billno' => $mchBillno];
  34. $base = [
  35. 'appid' => $this->app['config']->app_id,
  36. 'bill_type' => 'MCHT',
  37. ];
  38. return $this->safeRequest('mmpaymkttransfers/gethbinfo', array_merge($base, $params));
  39. }
  40. /**
  41. * Send miniprogram normal redpack.
  42. *
  43. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  44. *
  45. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  46. */
  47. public function sendMiniprogramNormal(array $params)
  48. {
  49. $base = [
  50. 'total_num' => 1,
  51. 'client_ip' => $params['client_ip'] ?? Support\get_server_ip(),
  52. 'wxappid' => $this->app['config']->app_id,
  53. ];
  54. return $this->safeRequest('mmpaymkttransfers/sendminiprogramhb', array_merge($base, $params));
  55. }
  56. /**
  57. * Send normal redpack.
  58. *
  59. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  60. *
  61. * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
  62. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  63. * @throws \GuzzleHttp\Exception\GuzzleException
  64. */
  65. public function sendNormal(array $params)
  66. {
  67. $base = [
  68. 'total_num' => 1,
  69. 'client_ip' => $params['client_ip'] ?? Support\get_server_ip(),
  70. 'wxappid' => $this->app['config']->app_id,
  71. ];
  72. return $this->safeRequest('mmpaymkttransfers/sendredpack', array_merge($base, $params));
  73. }
  74. /**
  75. * Send group redpack.
  76. *
  77. * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
  78. *
  79. * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
  80. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  81. * @throws \GuzzleHttp\Exception\GuzzleException
  82. */
  83. public function sendGroup(array $params)
  84. {
  85. $base = [
  86. 'amt_type' => 'ALL_RAND',
  87. 'wxappid' => $this->app['config']->app_id,
  88. ];
  89. return $this->safeRequest('mmpaymkttransfers/sendgroupredpack', array_merge($base, $params));
  90. }
  91. }