1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace huolib\pay;
- use huolib\status\OrderStatus;
- use think\Exception;
- use think\Log;
- class Pay {
- static $ins;
- private $payway_map
- = [
- 'default' => 'Alipay',
- 'alipay' => 'Alipay',
- 'wxpay' => 'Wxpay',
- 'shengpay' => 'Shengpay',
- 'balance' => 'Balancepay'
- ];
- public static function ins() {
- if (self::$ins == null) {
- self::$ins = new self();
- }
- return self::$ins;
- }
-
- public function get($payway = '') {
- if (empty($payway)) {
- return $this->register('default');
- }
- $_pay_obj = $this->register($payway);
- if (!isset($_pay_obj)) {
- Log::write(
- "func=".__FUNCTION__."&class=".__CLASS__."&errmsg=registerError&payway=".$payway
- .'objName='.$this->payway_map[$payway], 'info'
- );
- throw new Exception(OrderStatus::getMsg(OrderStatus::PAYWAY_INCORRECT), OrderStatus::PAYWAY_INCORRECT);
- }
- return $_pay_obj;
- }
-
- protected function register($payway = '') {
- $payway = strtolower($payway);
- $_class = '\\huolib\\pay\\driver\\'.$this->payway_map[$payway];
- return new $_class();
- }
- }
|