Redpack.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | WeChatDeveloper
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2020 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://think.ctolog.com
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | github开源项目:https://github.com/zoujingli/WeChatDeveloper
  12. // +----------------------------------------------------------------------
  13. namespace WePay;
  14. use WeChat\Contracts\BasicWePay;
  15. /**
  16. * 微信红包支持
  17. * Class Redpack
  18. * @package WePay
  19. */
  20. class Redpack extends BasicWePay
  21. {
  22. /**
  23. * 发放普通红包
  24. * @param array $options
  25. * @return array
  26. * @throws \WeChat\Exceptions\InvalidResponseException
  27. * @throws \WeChat\Exceptions\LocalCacheException
  28. */
  29. public function create(array $options)
  30. {
  31. $this->params->offsetUnset('appid');
  32. $this->params->set('wxappid', $this->config->get('appid'));
  33. $url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack";
  34. return $this->callPostApi($url, $options, true, 'MD5', false);
  35. }
  36. /**
  37. * 发放裂变红包
  38. * @param array $options
  39. * @return array
  40. * @throws \WeChat\Exceptions\InvalidResponseException
  41. * @throws \WeChat\Exceptions\LocalCacheException
  42. */
  43. public function groups(array $options)
  44. {
  45. $this->params->offsetUnset('appid');
  46. $this->params->set('wxappid', $this->config->get('appid'));
  47. $url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendgroupredpack";
  48. return $this->callPostApi($url, $options, true, 'MD5', false);
  49. }
  50. /**
  51. * 查询红包记录
  52. * @param string $mchBillno 商户发放红包的商户订单号
  53. * @return array
  54. * @throws \WeChat\Exceptions\InvalidResponseException
  55. * @throws \WeChat\Exceptions\LocalCacheException
  56. */
  57. public function query($mchBillno)
  58. {
  59. $this->params->offsetUnset('wxappid');
  60. $this->params->set('appid', $this->config->get('appid'));
  61. $url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo";
  62. return $this->callPostApi($url, ['mch_billno' => $mchBillno, 'bill_type' => 'MCHT'], true, 'MD5', false);
  63. }
  64. }