InvoiceClient.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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\OfficialAccount\Card;
  11. use EasyWeChat\Kernel\BaseClient;
  12. /**
  13. * Class InvoiceClient.
  14. *
  15. * @author overtrue <i@overtrue.me>
  16. */
  17. class InvoiceClient extends BaseClient
  18. {
  19. /**
  20. * 设置支付后开票信息接口.
  21. *
  22. * @param string $mchid
  23. * @param string $sPappid
  24. *
  25. * @return mixed
  26. */
  27. public function set(string $mchid, string $sPappid)
  28. {
  29. $params = [
  30. 'paymch_info' => [
  31. 'mchid' => $mchid,
  32. 's_pappid' => $sPappid,
  33. ],
  34. ];
  35. return $this->setBizAttr('set_pay_mch', $params);
  36. }
  37. /**
  38. * 查询支付后开票信息接口.
  39. *
  40. * @return mixed
  41. */
  42. public function get()
  43. {
  44. return $this->setBizAttr('get_pay_mch');
  45. }
  46. /**
  47. * 设置授权页字段信息接口.
  48. *
  49. * @param array $userData
  50. * @param array $bizData
  51. *
  52. * @return mixed
  53. */
  54. public function setAuthField(array $userData, array $bizData)
  55. {
  56. $params = [
  57. 'auth_field' => [
  58. 'user_field' => $userData,
  59. 'biz_field' => $bizData,
  60. ],
  61. ];
  62. return $this->setBizAttr('set_auth_field', $params);
  63. }
  64. /**
  65. * 查询授权页字段信息接口.
  66. *
  67. * @return mixed
  68. */
  69. public function getAuthField()
  70. {
  71. return $this->setBizAttr('get_auth_field');
  72. }
  73. /**
  74. * 查询开票信息.
  75. *
  76. * @param string $orderId
  77. * @param string $appId
  78. *
  79. * @return mixed
  80. */
  81. public function getAuthData(string $appId, string $orderId)
  82. {
  83. $params = [
  84. 'order_id' => $orderId,
  85. 's_appid' => $appId,
  86. ];
  87. return $this->httpPost('card/invoice/getauthdata', $params);
  88. }
  89. /**
  90. * @param string $action
  91. * @param array $params
  92. *
  93. * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
  94. *
  95. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  96. */
  97. private function setBizAttr(string $action, array $params = [])
  98. {
  99. return $this->httpPostJson('card/invoice/setbizattr', $params, ['action' => $action]);
  100. }
  101. }