PayService.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace addons\shopro\library\pay;
  3. use think\Log;
  4. use addons\shopro\library\pay\provider\Base;
  5. class PayService
  6. {
  7. protected $payment;
  8. protected $platform;
  9. public function __construct($payment, $platform = null)
  10. {
  11. $this->payment = $payment;
  12. $this->platform = $platform ? : request()->header('platform', null);
  13. if (!$this->platform) {
  14. error_stop('缺少用户端平台参数');
  15. }
  16. }
  17. /**
  18. * 支付提供器
  19. *
  20. * @param string $type
  21. * @return Base
  22. */
  23. public function provider($payment = null)
  24. {
  25. $payment = $payment ?: $this->payment;
  26. $class = "\\addons\\shopro\\library\\pay\\provider\\" . \think\helper\Str::studly($payment);
  27. if (class_exists($class)) {
  28. return new $class($this, $this->platform);
  29. }
  30. error_stop('支付类型不支持');
  31. }
  32. public function __call($funcname, $arguments)
  33. {
  34. return $this->provider()->{$funcname}(...$arguments);
  35. }
  36. }