/** * 获得WeChatTypeParse的单例模式。 */ public static function getInstance() { if (!self::$singleton instanceof self) { self::$singleton = new self(); } return self::$singleton; }
public function run($message) { if (!empty($message)) { //获得正确的类型处理器。有点类似获得一个工厂 $this->weChatMessageHandler = WeChatTypeParse::getInstance()->parse($message); //获得正确的消息响应对象。产生正确的产品。并处理消息 $this->weChatMessageHandler->doHandleMessage(); //获得输出 $str = $this->weChatMessageHandler->getResponseMessage(); return $str; } else { return ""; } }