<?php
namespace Payment; use Payment\Common\BaseStrategy; use Payment\Common\PayException; use Payment\Red\WxRed; class RedContext { protected $red; public function initRed($channel, array $config) { try { switch ($channel) { case Config::ALI_RED: $this->red = new AliRed($config); break; case Config::WX_RED: $this->red = new WxRed($config); break; default: throw new PayException('当前仅支持：ALI WEIXIN两个常量'); } } catch (PayException $e) { throw $e; } } public function red(array $data) { if (! $this->red instanceof BaseStrategy) { throw new PayException('请检查初始化是否正确'); } try { return $this->red->handle($data); } catch (PayException $e) { throw $e; } } } 