<?php
namespace Payment; use Payment\Common\BaseStrategy; use Payment\Common\PayException; use Payment\Refund\AliRefund; use Payment\Refund\CmbRefund; use Payment\Refund\WxRefund; class RefundContext { protected $refund; public function initRefund($channel, array $config) { try { switch ($channel) { case Config::ALI_REFUND: $this->refund = new AliRefund($config); break; case Config::WX_REFUND: $this->refund = new WxRefund($config); break; case Config::CMB_REFUND: $this->refund = new CmbRefund($config); break; default: throw new PayException('当前仅支持：ALI WEIXIN CMB'); } } catch (PayException $e) { throw $e; } } public function refund(array $data) { if (! $this->refund instanceof BaseStrategy) { throw new PayException('请检查初始化是否正确'); } try { return $this->refund->handle($data); } catch (PayException $e) { throw $e; } } } 