Redpack.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 WePay;
  16. use WeChat\Contracts\BasicWePay;
  17. /**
  18. * 微信红包支持
  19. * Class Redpack
  20. * @package WePay
  21. */
  22. class Redpack extends BasicWePay
  23. {
  24. /**
  25. * 发放普通红包
  26. * @param array $options
  27. * @return array
  28. * @throws \WeChat\Exceptions\InvalidResponseException
  29. * @throws \WeChat\Exceptions\LocalCacheException
  30. */
  31. public function create(array $options)
  32. {
  33. $this->params->offsetUnset('appid');
  34. $this->params->set('wxappid', $this->config->get('appid'));
  35. $url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack";
  36. return $this->callPostApi($url, $options, true, 'MD5', false);
  37. }
  38. /**
  39. * 发放裂变红包
  40. * @param array $options
  41. * @return array
  42. * @throws \WeChat\Exceptions\InvalidResponseException
  43. * @throws \WeChat\Exceptions\LocalCacheException
  44. */
  45. public function groups(array $options)
  46. {
  47. $this->params->offsetUnset('appid');
  48. $this->params->set('wxappid', $this->config->get('appid'));
  49. $url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendgroupredpack";
  50. return $this->callPostApi($url, $options, true, 'MD5', false);
  51. }
  52. /**
  53. * 查询红包记录
  54. * @param string $mchBillno 商户发放红包的商户订单号
  55. * @return array
  56. * @throws \WeChat\Exceptions\InvalidResponseException
  57. * @throws \WeChat\Exceptions\LocalCacheException
  58. */
  59. public function query($mchBillno)
  60. {
  61. $this->params->offsetUnset('wxappid');
  62. $this->params->set('appid', $this->config->get('appid'));
  63. $url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo";
  64. return $this->callPostApi($url, ['mch_billno' => $mchBillno, 'bill_type' => 'MCHT'], true, 'MD5', false);
  65. }
  66. }