Yii开发微信时如何接受Post请求 解析Xml

微信给yii发来的文件是xml格式


<xml>

 <ToUserName><![CDATA[toUser]]></ToUserName>

 <FromUserName><![CDATA[fromUser]]></FromUserName> 

 <CreateTime>1348831860</CreateTime>

 <MsgType><![CDATA[text]]></MsgType>

 <Content><![CDATA[this is a test]]></Content>

 <MsgId>1234567890123456</MsgId>

 </xml>

微信类是用这样方式获取数据的


public function getRev()

{

if ($this->_receive) return $this;

$postStr = file_get_contents("php://input");

$this->log($postStr);

if (!empty($postStr)) {

$this->_receive = (array)simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);

}

return $this;

}



我想问一下在yii要如设置才能实现上述功能,在控制器中设置还是在模型中设置。

关健是这个语句我的设置中获取不到值

$postStr = file_get_contents("php://input");

请帮助这个放在什么位置能获取微信post 过来的xml内容

正在做类似的工作,相互交流 q群:172064693, my wechat: Hehb2005





	protected function getPostStr() 

	{

		if ($this->localTest)		

		{

				//return self::getDemoRequestXml(Wechat::MSGTYPE_TEXT);

				//return self::getDemoRequestXml(Wechat::MSGTYPE_EVENT, Wechat::EVENT_CLICK);

				return self::getDemoRequestXml(Wechat::MSGTYPE_EVENT, Wechat::EVENT_SUBSCRIBE);

				//return self::getDemoRequestXml(Wechat::MSGTYPE_EVENT, Wechat::EVENT_UNSUBSCRIBE);				

				//return self::getDemoRequestXml(Wechat::MSGTYPE_IMAGE);

				//return self::getDemoRequestXml(Wechat::MSGTYPE_LOCATION);

				//return self::getDemoRequestXml(Wechat::MSGTYPE_LINK);

				//return self::getDemoRequestXml(Wechat::MSGTYPE_VOICE);

				//return self::getDemoRequestXml(Wechat::MSGTYPE_VIDEO);				

				//return self::getDemoRequestXml(Wechat::MSGTYPE_EVENT, Wechat::EVENT_SCAN);

				//return self::getDemoRequestXml(Wechat::MSGTYPE_EVENT, Wechat::EVENT_LOCATION);

				//return self::getDemoRequestXml(Wechat::MSGTYPE_EVENT, Wechat::EVENT_VIEW);

		}

		else

		{

			return file_get_contents("php://input");

		}

	}

	

	protected function getRequest($key=false) 

	{

		if ($this->_request === null)

		{

			$postStr = $this->getPostStr();

			$this->log($postStr);	

			$arr = (array) simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);

			$this->_request = $arr;

		}

		if ($key === false)

			return $this->_request;

		if (isset($this->_request[$key])) 

			return $this->_request[$key];

		else

			return null;

	}