<?php/** * Micro-trust public Platform Interface PHP100 Package function class file * Author php100.com Zhang Enmin * Date 2013-4-9 prc:e+8 23:03-&NB Sp * Linkme QQ925939 chuangen.com * define ("TOKEN", "Chuangenit"); $WECHATOBJ = new Wechatcallbackapitest (); $WECHATOBJ->weixin_run (); Execute receiver method class Wechatcallbackapitest { private $fromUsername; private $toUsername; &nbs P private $times; private $keyword; public function Weixin_run () { $this->responsemsg (); $arr [ ]=array ("Creation grace is very reliable, PHP100 is also good!") "," AA "," Http://www.chuangen.com/pic/hj/s_4.png "," http://www.chuangen.com "); $arr []=array is very reliable, PHP100 is also good! "," AA "," Http://www.chuangen.com/pic/hj/s_4.png "," http://www.chuangen.com "); $arr []=array is very reliable, PHP100 is also good! "," AA "," Http://www.chuangen.com/pic/hj/s_4.png "," http://www.chuangen.com "); $this->fun_xml ("News", $arr, Array (2,0)); } function T ($n){ include ("t_api.php") $c _name= $t _api[$n] $json =file_get_contents ("http:// M.weather.com.cn/data/101110310.html "); return Json_decode ($json); } Public Function valid () { $EC Hostr = $_get["Echostr"]; //valid signature, option if ($this->checksignature ()) { echo $echoStr; exit; } { public Function responsemsg () {$POSTSTR = $GLOBALS ["Http_raw_post_data"]; if (!empty ($POSTSTR)) { $POSTOBJ = simplexml_load_string ($postStr, ' simple XmlElement ', libxml_nocdata); $this->fromusername = $POSTOBJ->fromusername; $this->tousername = $POSTOBJ->tousername; $this->keyword = Trim ($postObj->content); $this->times = time (); }else { echo "This a file for Weixin api!"; & nbsp Exit } / /micro Envelope loading class,//type:text text type, news type//text,array (content), array (ID)//ne Ws,array (title, Introduction, Picture, HYPERLINK),... Less than 10), array (number, ID) Private Function Fun_xml ($type, $value _arr, $o _arr=array (0)) { //=================xml header============ $con = "<xml> <tousername><! [cdata[{$this->fromusername}]]></tousername> <fromusername><! [cdata[{$this->tousername}]]></fromusername> <createtime>{$this->times}</createtime> <msgtype><! [cdata[{$type}]]></msgtype> "; //=================type content============ switch ($type) { case "text": $con. = "<content><![ cdata[{$value _arr[0]}]]></content> <funcflag>{$o _arr}</funcflag> "; break; Case "News": $con. = "<articlecount>{$o _arr[0]}</articlecount> <Articles>"; foreach ($value _arr as $id => $v) {if ($id >= $o _arr[0]) break; number of arrays not exceeding set &NBSP ; $con. = "<item> <title><! [cdata[{$v [0]}]]></title> <description><! [cdata[{$v [1]}]]></description> <picurl><! [cdata[{$v [2]}]]></picurl> <url><! [cdata[{$v [3]}]]></url> </item> "; $con. = "</Articles> <funcflag>{$o _arr[1]}</funcflag>"; break; &NBSP}//end switch //=================end return============ echo $con. " </xml> "; } Private Function checksignature () { $signature = $_get["signature"]; $timestamp = $_get["timestamp"]; $nonce = $_get["nonce"]; $token = token; $TMPARR = Array ($token, $timestamp, $nonce); Sort ($TMPARR); $TMPSTR = implode ($TMPARR); $TMPSTR = SHA1 ($TMPSTR); if ($tmpStr = = $signature) {return true;} else{return false;} } ?>