Transfers.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | WeChatDeveloper
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2023 ThinkAdmin [ thinkadmin.top ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: https://thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // | 免责声明 ( https://thinkadmin.top/disclaimer )
  11. // +----------------------------------------------------------------------
  12. // | gitee 代码仓库:https://gitee.com/zoujingli/WeChatDeveloper
  13. // | github 代码仓库:https://github.com/zoujingli/WeChatDeveloper
  14. // +----------------------------------------------------------------------
  15. namespace WePayV3;
  16. use WePayV3\Contracts\BasicWePay;
  17. /**
  18. * 普通商户商家转账到零钱
  19. * @class Transfers
  20. * @package WePayV3
  21. */
  22. class Transfers extends BasicWePay
  23. {
  24. /**
  25. * 发起商家批量转账
  26. * @param array $body
  27. * @return array
  28. * @throws \WeChat\Exceptions\InvalidDecryptException
  29. * @throws \WeChat\Exceptions\InvalidResponseException
  30. * @link https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_1.shtml
  31. */
  32. public function batchs($body)
  33. {
  34. if (empty($body['appid'])) {
  35. $body['appid'] = $this->config['appid'];
  36. }
  37. if (isset($body['transfer_detail_list']) && is_array($body['transfer_detail_list'])) {
  38. foreach ($body['transfer_detail_list'] as &$item) if (isset($item['user_name'])) {
  39. $item['user_name'] = $this->rsaEncode($item['user_name']);
  40. }
  41. }
  42. if (empty($body['total_num'])) {
  43. $body['total_num'] = count($body['transfer_detail_list']);
  44. }
  45. return $this->doRequest('POST', '/v3/transfer/batches', json_encode($body, JSON_UNESCAPED_UNICODE), true);
  46. }
  47. /**
  48. * 通过微信批次单号查询批次单
  49. * @param string $batchId 微信批次单号(二选一)
  50. * @param string $outBatchNo 商家批次单号(二选一)
  51. * @param boolean $needQueryDetail 查询指定状态
  52. * @param integer $offset 请求资源的起始位置
  53. * @param integer $limit 最大明细条数
  54. * @param string $detailStatus 查询指定状态
  55. * @return array
  56. * @throws \WeChat\Exceptions\InvalidResponseException
  57. */
  58. public function query($batchId = '', $outBatchNo = '', $needQueryDetail = true, $offset = 0, $limit = 20, $detailStatus = 'ALL')
  59. {
  60. if (empty($batchId)) {
  61. $pathinfo = "/v3/transfer/batches/out-batch-no/{$outBatchNo}";
  62. } else {
  63. $pathinfo = "/v3/transfer/batches/batch-id/{$batchId}";
  64. }
  65. $params = http_build_query([
  66. 'limit' => $limit,
  67. 'offset' => $offset,
  68. 'detail_status' => $detailStatus,
  69. 'need_query_detail' => $needQueryDetail ? 'true' : 'false',
  70. ]);
  71. return $this->doRequest('GET', "{$pathinfo}?{$params}", '', true);
  72. }
  73. /**
  74. * 通过微信明细单号查询明细单
  75. * @param string $batchId 微信批次单号
  76. * @param string $detailId 微信支付系统内部区分转账批次单下不同转账明细单的唯一标识
  77. * @return array
  78. * @throws \WeChat\Exceptions\InvalidResponseException
  79. */
  80. public function detailBatchId($batchId, $detailId)
  81. {
  82. $pathinfo = "/v3/transfer/batches/batch-id/{$batchId}/details/detail-id/{$detailId}";
  83. return $this->doRequest('GET', $pathinfo, '', true);
  84. }
  85. /**
  86. * 通过商家明细单号查询明细单
  87. * @param string $outBatchNo 商户系统内部的商家批次单号,在商户系统内部唯一
  88. * @param string $outDetailNo 商户系统内部区分转账批次单下不同转账明细单的唯一标识
  89. * @return array
  90. * @throws \WeChat\Exceptions\InvalidResponseException
  91. */
  92. public function detailOutBatchNo($outBatchNo, $outDetailNo)
  93. {
  94. $pathinfo = "/v3/transfer/batches/out-batch-no/{$outBatchNo}/details/out-detail-no/{$outDetailNo}";
  95. return $this->doRequest('GET', $pathinfo, '', true);
  96. }
  97. }