<?php
reponseMsg();
// 接收事件推送并回复
function reponseMsg(){
//1.获取到微信推送过来post数据(xml格式)
$postArr = $GLOBALS[“HTTP_RAW_POST_DATA”];
//2.处理消息类型,并设置回复类型和内容
libxml_disable_entity_loader(true);
$postObj = simplexml_load_string($postArr, ‘SimpleXMLElement’, LIBXML_NOCDATA);
$template = “<xml><ToUserName><![CDATA[%s]]></ToUserName><FromUserName><![CDATA[%s]]></FromUserName><CreateTime>%s</CreateTime><MsgType><![CDATA[%s]]></MsgType><Content><![CDATA[%s]]></Content></xml>”;
$fromUser = $postObj->ToUserName;
$toUser = $postObj->FromUserName;
$time = time();
$content ="welcome to cck we chat ";
$msgType = “text”;
$resultStr = sprintf($template, $fromUser, $toUser, $time, $msgType, $content);
echo $resultStr;
} //reponseMsg end
?>