public function getMessage()
{
static $message = null;
if ($message == null) {
//微信提交过来的xml
$xmlStr = file_get_contents('php://input');
if (empty($xmlStr)) {
throw new WechatException('http raw post data is empty.');
}
//自动识别是否需要解密
$xmlStr = $this->attemptDecrypt($xmlStr);
$xmlElement = @simplexml_load_string($xmlStr, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOBLANKS);
if ($xmlElement === false) {
throw new WechatException('load xml error. ' . $xmlStr);
}
//将SimpleXMLElement对象转为Receive对象
$message = new Receive();
foreach ((array) $xmlElement as $key => $value) {
$message->{$key} = $value;
}
}
return $message;
}