/** * @group testResponse */ public function testResponse() { $_SERVER['REQUEST_TIME'] = '123456'; $wechatOutMessageText = new Wechat_OutMessage_Text(); $wechatOutMessageText->setContent('phupnit'); $wechatOutMessageText->setToUserName('123'); $wechatOutMessageText->setFromUserName('456'); $rs = $wechatOutMessageText->response(); $expRs = '<xml> <ToUserName><![CDATA[456]]></ToUserName> <FromUserName><![CDATA[123]]></FromUserName> <CreateTime>123456</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content><![CDATA[phupnit]]></Content> <FuncFlag>0</FuncFlag> </xml>'; $this->assertEquals($expRs, $rs); }
public function response() { try { $rs = $this->run(); if ($rs === NULL) { throw new PhalApi_Exception_BadRequest(T('coming soon!')); } return $rs; } catch (PhalApi_Exception $ex) { $inMessage = new Wechat_InMessage(); $outMessage = new Wechat_OutMessage_Text(); $outMessage->setFromUserName($inMessage->getFromUserName()); $outMessage->setToUserName($inMessage->getToUserName()); $outMessage->setContent($ex->getMessage()); return $outMessage; } catch (Exception $ex) { DI()->logger->error('Wechat Lite caught an exception', $ex->getMessage()); throw new $ex(); } }