<? Php/*** public platform interface PHP100 encapsulate function files * author * date 2013-4-9 PRC: E + 8 */define ("TOKEN", "chuangenit "); $ wechatObj = new wechatCallbackapiTest (); $ wechatObj-> weixin_run (); // execute the receiver class wechatCallbackapiTest {private $ fromUsername; private $ toUsername; private $ times; private $ keyword; public function weixin_run () {$ this-> responseMsg (); $ arr [] = array ("very reliable, good! "," Aa "," http://www.chuangen.com/pic/hj/s_4.png "," http://www.baidu.com "); $ arr [] = array (" very reliable, good! "," Aa "," http://www.chuangen.com/pic/hj/s_4.png "," http://www.baidu.com "); $ arr [] = array (" very reliable, good! "," Aa "," http://www.chuangen.com/pic/hj/s_4.png "," http://www.baidu.com "); $ this-> fun_xml (" news ", $ arr, array ));} 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 () {$ echoStr = $ _ GET ["echostr"]; // valid signature, option if ($ this-> checkSignature () {echo $ echoStr; ex It ;}} public function responseMsg () {$ postStr = $ GLOBALS ["HTTP_RAW_POST_DATA"]; if (! Empty ($ postStr) {$ postObj = simplexml_load_string ($ postStr, 'simplexmlelement', 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! "; Exit ;}/// encapsulation class, // type: text type, news text type // text, array (content), array (ID) // news, array (title, Introduction, image, 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; else null; // judge whether the number of arrays cannot exceed the set number $ 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 ;} // 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); $ t MpStr = sha1 ($ tmpStr); if ($ tmpStr ==$ signature) {return true;} else {return false ;}}?>