<?php
namespace Payment\Client; use Payment\Common\PayException; use Payment\Config; use Payment\Notify\PayNotifyInterface; use Payment\NotifyContext; class Notify { private static $supportChannel = [ Config::ALI_CHARGE, Config::WX_CHARGE, Config::CMB_CHARGE, 'applepay_upacp', ]; protected static $instance; protected static function getInstance($type, $config) { mb_internal_encoding("UTF-8"); if (is_null(self::$instance)) { static::$instance = new NotifyContext(); } try { static::$instance->initNotify($type, $config); } catch (PayException $e) { throw $e; } return static::$instance; } public static function run($type, $config, $callback) { if (! in_array($type, self::$supportChannel)) { throw new PayException('sdk当前不支持该异步方式，当前仅支持：' . implode(',', self::$supportChannel)); } try { $instance = self::getInstance($type, $config); $ret = $instance->notify($callback); } catch (PayException $e) { throw $e; } return $ret; } public static function getNotifyData($type, $config) { try { $instance = self::getInstance($type, $config); return $instance->getNotifyData(); } catch (PayException $e) { throw $e; } } } 