AppGateway.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace Yansongda\Pay\Gateways\Wechat;
  3. use Yansongda\Pay\Exceptions\InvalidArgumentException;
  4. class AppGateway extends Wechat
  5. {
  6. /**
  7. * get trade type config.
  8. *
  9. * @author yansongda <me@yansongda.cn>
  10. *
  11. * @return string
  12. */
  13. protected function getTradeType()
  14. {
  15. return 'APP';
  16. }
  17. /**
  18. * pay a order.
  19. *
  20. * @author yansongda <me@yansongda.cn>
  21. *
  22. * @param array $config_biz
  23. *
  24. * @return array
  25. */
  26. public function pay(array $config_biz = [])
  27. {
  28. if (is_null($this->user_config->get('appid'))) {
  29. throw new InvalidArgumentException('Missing Config -- [appid]');
  30. }
  31. $this->config['appid'] = $this->user_config->get('appid');
  32. $payRequest = [
  33. 'appid' => $this->user_config->get('appid'),
  34. 'partnerid' => $this->user_config->get('mch_id'),
  35. 'prepayid' => $this->preOrder($config_biz)['prepay_id'],
  36. 'timestamp' => strval(time()),
  37. 'noncestr' => $this->createNonceStr(),
  38. 'package' => 'Sign=WXPay',
  39. ];
  40. $payRequest['sign'] = $this->getSign($payRequest);
  41. return $payRequest;
  42. }
  43. }