AppGateway.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace Yansongda\Pay\Gateways\Alipay;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use Yansongda\Pay\Events;
  5. use Yansongda\Pay\Exceptions\InvalidArgumentException;
  6. use Yansongda\Pay\Exceptions\InvalidConfigException;
  7. use Yansongda\Pay\Gateways\Alipay;
  8. class AppGateway extends Gateway
  9. {
  10. /**
  11. * Pay an order.
  12. *
  13. * @author yansongda <me@yansongda.cn>
  14. *
  15. * @param string $endpoint
  16. *
  17. * @throws InvalidConfigException
  18. * @throws InvalidArgumentException
  19. */
  20. public function pay($endpoint, array $payload): Response
  21. {
  22. $payload['method'] = 'alipay.trade.app.pay';
  23. $biz_array = json_decode($payload['biz_content'], true);
  24. if ((Alipay::MODE_SERVICE === $this->mode) && (!empty(Support::getInstance()->pid))) {
  25. $biz_array['extend_params'] = is_array($biz_array['extend_params']) ? array_merge(['sys_service_provider_id' => Support::getInstance()->pid], $biz_array['extend_params']) : ['sys_service_provider_id' => Support::getInstance()->pid];
  26. }
  27. $payload['biz_content'] = json_encode(array_merge($biz_array, ['product_code' => 'QUICK_MSECURITY_PAY']));
  28. $payload['sign'] = Support::generateSign($payload);
  29. Events::dispatch(new Events\PayStarted('Alipay', 'App', $endpoint, $payload));
  30. return new Response(http_build_query($payload));
  31. }
  32. }