MiniappGateway.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Yansongda\Pay\Gateways\Wechat;
  3. use Yansongda\Pay\Exceptions\InvalidArgumentException;
  4. class MiniappGateway extends Wechat
  5. {
  6. /**
  7. * get trade type config.
  8. *
  9. * @author yansongda <me@yansongda.cn>
  10. *
  11. * @return string [description]
  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('miniapp_id'))) {
  29. throw new InvalidArgumentException('Missing Config -- [miniapp_id]');
  30. }
  31. $this->config['appid'] = $this->user_config->get('miniapp_id');
  32. $payRequest = [
  33. 'appId' => $this->user_config->get('miniapp_id'),
  34. 'timeStamp' => strval(time()),
  35. 'nonceStr' => $this->createNonceStr(),
  36. 'package' => 'prepay_id='.$this->preOrder($config_biz)['prepay_id'],
  37. 'signType' => 'MD5',
  38. ];
  39. $payRequest['paySign'] = $this->getSign($payRequest);
  40. return $payRequest;
  41. }
  42. }