<?php
namespace Payment\Client; use Payment\Common\PayException; use Payment\Config; use Payment\HelperContext; class Helper { private static $supportChannel = [ Config::CMB_BIND, Config::CMB_PUB_KEY, ]; protected static $instance; protected static function getInstance($channel, $config) { mb_internal_encoding("UTF-8"); if (is_null(self::$instance)) { static::$instance = new HelperContext(); } try { static::$instance->initHelper($channel, $config); } catch (PayException $e) { throw $e; } return static::$instance; } public static function run($channel, $config, array $metadata = []) { if (! in_array($channel, self::$supportChannel)) { throw new PayException('sdk当前不支持该渠道，当前仅支持：' . implode(',', self::$supportChannel)); } try { $instance = self::getInstance($channel, $config); $ret = $instance->helper($metadata); } catch (PayException $e) { throw $e; } return $ret; } } 