GroupRedpackGateway.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace Yansongda\Pay\Gateways\Wechat;
  3. use Yansongda\Pay\Events;
  4. use Yansongda\Pay\Exceptions\GatewayException;
  5. use Yansongda\Pay\Exceptions\InvalidArgumentException;
  6. use Yansongda\Pay\Exceptions\InvalidSignException;
  7. use Yansongda\Pay\Gateways\Wechat;
  8. use Yansongda\Supports\Collection;
  9. class GroupRedpackGateway extends Gateway
  10. {
  11. /**
  12. * Pay an order.
  13. *
  14. * @author yansongda <me@yansongda.cn>
  15. *
  16. * @param string $endpoint
  17. *
  18. * @throws GatewayException
  19. * @throws InvalidArgumentException
  20. * @throws InvalidSignException
  21. */
  22. public function pay($endpoint, array $payload): Collection
  23. {
  24. $payload['wxappid'] = $payload['appid'];
  25. $payload['amt_type'] = 'ALL_RAND';
  26. if (Wechat::MODE_SERVICE === $this->mode) {
  27. $payload['msgappid'] = $payload['appid'];
  28. }
  29. unset($payload['appid'], $payload['trade_type'],
  30. $payload['notify_url'], $payload['spbill_create_ip']);
  31. $payload['sign'] = Support::generateSign($payload);
  32. Events::dispatch(new Events\PayStarted('Wechat', 'Group Redpack', $endpoint, $payload));
  33. return Support::requestApi(
  34. 'mmpaymkttransfers/sendgroupredpack',
  35. $payload,
  36. true
  37. );
  38. }
  39. /**
  40. * Get trade type config.
  41. *
  42. * @author yansongda <me@yansongda.cn>
  43. */
  44. protected function getTradeType(): string
  45. {
  46. return '';
  47. }
  48. }