1 <?php 2 3 4 /*echo $_GET['echostr']; 5 exit;*/ 6 7 8 //接收xml数据 9 $postStr = $GLOBALS['HTTP_RAW_POST_DATA']; 10 //把xml数据转化成对象 11 $postObj = simplexml_load_string($postStr); 12 //接收post的值 13 $fromuserName = $postObj->FromUserName; 14 $touserName = $postObj->ToUserName; 15 $time = time(); 16 $msgType = $postObj->MsgType; 17 $keywords = $postObj->Content; 18 19 20 //自动回复 21 $textTpl = "<xml> 22 <ToUserName><![CDATA[%s]]></ToUserName> 23 <FromUserName><![CDATA[%s]]></FromUserName> 24 <CreateTime>%s</CreateTime> 25 <MsgType><![CDATA[%s]]></MsgType> 26 <Content><![CDATA[%s]]></Content> 27 </xml>"; 28 29 //关键词自动回复 30 if($postObj->MsgType == "text" ){ 31 if($postObj->Content == '1'){ 32 $content = '111!!!!'; 33 $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); 34 echo $resultful; 35 }else if($postObj->Content == '2'){ 36 37 $content = '222!!!!'; 38 $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); 39 echo $resultful; 40 }else{ 41 $content = 'hello world!'; 42 $resultful = sprintf($textTpl,$fromuserName,$touserName,$time,$msgType,$content); 43 echo $resultful; 44 45 } 46 47 48 } 49 50 ?>
微信自动回复功能!