WapGateway.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace Yansongda\Pay\Gateways\Wechat;
  3. use Symfony\Component\HttpFoundation\RedirectResponse;
  4. use Yansongda\Pay\Events;
  5. use Yansongda\Pay\Exceptions\GatewayException;
  6. use Yansongda\Pay\Exceptions\InvalidArgumentException;
  7. use Yansongda\Pay\Exceptions\InvalidSignException;
  8. class WapGateway extends Gateway
  9. {
  10. /**
  11. * Pay an order.
  12. *
  13. * @author yansongda <me@yansongda.cn>
  14. *
  15. * @param string $endpoint
  16. *
  17. * @throws GatewayException
  18. * @throws InvalidArgumentException
  19. * @throws InvalidSignException
  20. */
  21. public function pay($endpoint, array $payload): RedirectResponse
  22. {
  23. $payload['trade_type'] = $this->getTradeType();
  24. Events::dispatch(new Events\PayStarted('Wechat', 'Wap', $endpoint, $payload));
  25. $mweb_url = $this->preOrder($payload)->get('mweb_url');
  26. $url = is_null(Support::getInstance()->return_url) ? $mweb_url : $mweb_url.
  27. '&redirect_url='.urlencode(Support::getInstance()->return_url);
  28. return new RedirectResponse($url);
  29. }
  30. /**
  31. * Get trade type config.
  32. *
  33. * @author yansongda <me@yansongda.cn>
  34. */
  35. protected function getTradeType(): string
  36. {
  37. return 'MWEB';
  38. }
  39. }