<?php
namespace Payment\Client; use Payment\ChargeContext; use Payment\Common\PayException; use Payment\Config; class Charge { private static $supportChannel = [ Config::ALI_CHANNEL_APP, Config::ALI_CHANNEL_WAP, Config::ALI_CHANNEL_WEB, Config::ALI_CHANNEL_QR, Config::ALI_CHANNEL_BAR, Config::WX_CHANNEL_APP, Config::WX_CHANNEL_PUB, Config::WX_CHANNEL_QR, Config::WX_CHANNEL_BAR, Config::WX_CHANNEL_WAP, Config::WX_CHANNEL_LITE, Config::CMB_CHANNEL_APP, 'applepay_upacp', ]; protected static $instance; protected static function getInstance($channel, $config) { mb_internal_encoding("UTF-8"); if (is_null(self::$instance)) { static::$instance = new ChargeContext(); } try { static::$instance->initCharge($channel, $config); } catch (PayException $e) { throw $e; } return static::$instance; } public static function run($channel, $config, $metadata) { if (! in_array($channel, self::$supportChannel)) { throw new PayException('sdk当前不支持该支付渠道，当前仅支持：' . implode(',', self::$supportChannel)); } try { $instance = self::getInstance($channel, $config); $ret = $instance->charge($metadata); } catch (PayException $e) { throw $e; } return $ret; } } 