MpGateway.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace Yansongda\Pay\Gateways\Wechat;
  3. use Yansongda\Pay\Exceptions\InvalidArgumentException;
  4. class MpGateway 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 'JSAPI';
  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('app_id'))) {
  29. throw new InvalidArgumentException('Missing Config -- [app_id]');
  30. }
  31. $payRequest = [
  32. 'appId' => $this->user_config->get('app_id'),
  33. 'timeStamp' => strval(time()),
  34. 'nonceStr' => $this->createNonceStr(),
  35. 'package' => 'prepay_id='.$this->preOrder($config_biz)['prepay_id'],
  36. 'signType' => 'MD5',
  37. ];
  38. $payRequest['paySign'] = $this->getSign($payRequest);
  39. return $payRequest;
  40. }
  41. }