文档介绍:<?php/*doufudiyortCopyRight2014AllRightsReserved*/define("TOKEN","doufudiy");define("AppID","wx9b24c99e83238b21");define("EncodingAESKey","ww1bzDRcAy84UOGNaxL230A9tdBBOWgKQkYviIc6CFc");define("APP_SECRET","267980781c9addd54fcf811ea7acb59d");//改成自己的APPSECRET$wechatObj=newwechatCallbackapiTest();$wechatObj->responseMsg();classwechatCallbackapiTest{ private$app_id; private$app_secret; publicfunctionvalid(){$echoStr=$_GET["echostr"];//validsignature,optionif($this->checkSignature()){ ob_clean();echo$echoStr;exit;}}functiontxt($fu,$tu,$content,$flag=0){ $tpl = "<xml> <ToUserName><![CDATA[".$fu."]]></ToUserName> <FromUserName><![CDATA[".$tu."]]></FromUserName> <CreateTime>".$_SERVER['REQUEST_TIME']."</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content><![CDATA[".$content."]]></Content> <FuncFlag>".$flag."</FuncFlag> </xml>"; echo$tpl;}functionnews($fu,$tu,$data,$flag=0){ $num = count($data); if($num>1){ $add=$this->news_add($data); $tpl="<xml> <ToUserName><![CDATA[".$fu."]]></ToUserName> <FromUserName><![CDATA[".$tu."]]></FromUserName> <CreateTime>".$_SERVER['REQUEST_TIME']."</CreateTime> <MsgType><![CDATA[news]]></MsgType> <Content><![CDATA[%s]]></Content> <ArticleCount>".$num."</ArticleCount> <Articles> ".$add." </Articles> <FuncFlag>".$flag."</FuncFlag> </xml>"; echo$tpl; }else{ $tpl="<xml> <ToUserName><![CDATA[".$fu."]]></ToUserName> <FromUserName><![CDATA[".$tu."]]></FromUserName> <CreateTime>".$_SERVER['REQUEST_TIME']."</CreateTime> <MsgType><![CDATA[news]]></MsgType> <Content><![CDATA[%s]]></Content> <ArticleCount>1</ArticleCount> <Articles> <item> <Title><![CDATA[".$data[0]['title']."]]></Title> <Description><![CDATA[".$data[0]['intro']."]]></Description> <PicUrl><![CDATA[".$data[0]['pic']."]]></PicUrl> <Url><![CDATA[".$data[0]['url']."]]></Url> </item> </Articles> <FuncFlag>".$flag."</FuncFlag> </xml>"; echo$tpl; }}functionnews_add($data){ $add = ""; foreach($dataas$k){ $add .="<item> <Title><![CDATA[".$k['title']."]]></Title> <Description><![CDATA[".$k['in