<?php
namespace Payment; use Payment\Notify\AliNotify; use Payment\Notify\CmbNotify; use Payment\Notify\NotifyStrategy; use Payment\Notify\PayNotifyInterface; use Payment\Notify\WxNotify; use Payment\Common\PayException; class NotifyContext { protected $notify; public function initNotify($channel, array $config) { try { switch ($channel) { case Config::ALI_CHARGE: $this->notify = new AliNotify($config); break; case Config::WX_CHARGE: $this->notify = new WxNotify($config); break; case Config::CMB_CHARGE: $this->notify = new CmbNotify($config); break; default: throw new PayException('当前仅支持：ALI_CHARGE WX_CHARGE CMB_CHARGE 常量'); } } catch (PayException $e) { throw $e; } } public function getNotifyData() { return $this->notify->getNotifyData(); } public function notify(PayNotifyInterface $notify) { if (! $this->notify instanceof NotifyStrategy) { throw new PayException('请检查初始化是否正确'); } return $this->notify->handle($notify); } } 