PHP Test Code

Source: Internet
Author: User

<?php/* This is an automatic reply to the Php*/header (' Content-type:text ');d efine ("TOKEN", "Weixin"); $wechatObj = new Wechatcallbackapitest (), if (!isset ($_get[' echostr ')) {$WECHATOBJ->responsemsg ();} else{$wechatObj->valid ();}        Class wechatcallbackapitest{//Verify signature Public Function valid () {$echoStr = $_get["Echostr"];        $signature = $_get["signature"];        $timestamp = $_get["timestamp"];        $nonce = $_get["nonce"];        $token = token;        $TMPARR = Array ($token, $timestamp, $nonce);        Sort ($TMPARR, sort_string);        $TMPSTR = implode ($TMPARR);        $TMPSTR = SHA1 ($TMPSTR);            if ($tmpStr = = $signature) {echo $echoStr;        Exit        }}//Response message Public Function responsemsg () {$postStr = $GLOBALS ["Http_raw_post_data"];            if (!empty ($POSTSTR)) {$this->logger ("R \ n". $postStr);            $POSTOBJ = simplexml_load_string ($postStr, ' simplexmlelement ', libxml_nocdata); $RX _type = TriM ($postObj->msgtype); Message type detach switch ($RX _type) {case "event": $result = $this->rec                    Eiveevent ($POSTOBJ);                Break                    Case "text": $result = $this->receivetext ($POSTOBJ);                Break                    Case "image": $result = $this->receiveimage ($POSTOBJ);                Break                    Case ' location ': $result = $this->receivelocation ($POSTOBJ);                Break                    Case "Voice": $result = $this->receivevoice ($POSTOBJ);                Break                    Case "video": Case "Shortvideo": $result = $this->receivevideo ($POSTOBJ);                Break                    Case "link": $result = $this->receivelink ($POSTOBJ);                Break                Default    $result = "Unknown msg type:" $RX _type;            Break            } $this->logger ("T \ r \ n". $result);        echo $result;            }else {echo "";        Exit        }}//Receive event message Private function Receiveevent ($object) {$content = ""; Switch ($object->event) {case "subscribe": $content = "Welcome to the Internet CAE Automatic data robot \ n Please reply to the following keywords: \ n                Text Emoticons single graphic multi-graphic music \ n Please press and hold the words or \ n Click + to send the following: Voice pictures small video My collection location "; $content. = (!empty ($object->eventkey))?                ("\ n from a two-dimensional code scene". Str_replace ("Qrscene_", "", $object->eventkey)): ""; The links later become clickable links $content. = "\ n".                <a href= "http://www.cnblogs.com/ironwang/p/6376873.html" > Internet cae elounda studio </a> ';            Break                Default: $content = "Receive a new event:". $object->event;        Break } if (Is_array ($content)) {$result = $this-> Transmitnews ($object, $content);        }else{$result = $this->transmittext ($object, $content);    } return $result;        }//Receive text message Private function Receivetext ($object) {$keyword = Trim ($object->content); Auto Reply mode if (Strstr ($keyword, "data")) {$content = ' click Database '. \ n "."                    <a href= "http://www.cnblogs.com/Elosithang/p/6401061.html" > Internet CAE sharing Data </a> '; }else if (strstr ($keyword, "emoticons")) {$content = "smile:/::) \ n Ping pong:/:oo\n China:". $this->bytes_to_emoji (0x1F 1E8). $this->bytes_to_emoji (0x1f1f3). "            \ n Cactus: ". $this->bytes_to_emoji (0x1f335); Here we start adding fluid-Related keywords}else if (strstr ($keyword, "CfD")) {$content = ' click on database '. " \ n "."            <a href= "http://www.cnblogs.com/Elosithang/p/6401061.html" > Internet cae-cfd sharing Information </a> '; }else if (strstr ($keyword, "fluid")) {$content = ' click on database '. " \ n "." <a href= "http://www.cnblogs.com/Elosithang/p/6401061. html "> Internet CAE-NVH sharing </a> '; Outflow field//vehicle//cabin//hvac//air conditioning comfort//battery pack//wading//foot This//latest software//}else if (Strstr ($keyword, "Star")) {$content = ' click Library '. " \ n "."            <a href= "http://www.cnblogs.com/Elosithang/p/6401061.html" > Internet cae-starccm+ sharing Information </a> '; }else if (strstr ($keyword, "star")) {$content = ' click on database '. " \ n "."            <a href= "http://www.cnblogs.com/Elosithang/p/6401061.html" > Internet cae-starccm+ sharing Information </a> '; }else if (strstr ($keyword, "STAR")) {$content = ' click on database '. " \ n "."                        <a href= "http://www.cnblogs.com/Elosithang/p/6401061.html" > Internet cae-starccm+ sharing Information </a> ';            Fluid added so far}else if (Strstr ($keyword, "single graphic")) {$content = array (); $content [] = Array ("title" + "single caption", "Description" + "single Graphic Content", "picurl" = "Http://discuz.comli.com/weixi"N/weather/icon/cartoon.jpg "," Url "=" http://m.cnblogs.com/?u=txw1958 ");            }else if (strstr ($keyword, "graphics") | | strstr ($KEYWORD, "multi-Text")) {$content = array (); $content [] = Array ("title" + "1 caption", "Description" and "" "," picurl "=" http://discuz.comli.com/weixin/"            Weather/icon/cartoon.jpg "," Url "=" http://m.cnblogs.com/?u=txw1958 "); $content [] = Array ("title" + "2 caption", "Description" and "" "," picurl "=" http://d.hiphotos.bdimg.com/wisegame/"            Pic/item/f3529822720e0cf3ac9f1ada0846f21fbe09aaa3.jpg "," Url "=" http://m.cnblogs.com/?u=txw1958 "); $content [] = Array ("title" + "3 caption", "Description" and "" "," picurl "=" http://g.hiphotos.bdimg.com/wisegame/"                    Pic/item/18cb0a46f21fbe090d338acc6a600c338644adfd.jpg "," Url "=" http://m.cnblogs.com/?u=txw1958 ");            }else if (strstr ($keyword, "Music")) {$content = array (); $content = Array ("Title" = "The most dazzling national wind", "Description" = "singer: Phoenix Legend","Musicurl" and "Http://mascot-music.stor.sinaapp.com/zxmzf.mp3", "hqmusicurl" and "="/http                     Mascot-music.stor.sinaapp.com/zxmzf.mp3 "); }else{//here to modify other content $content = ' Give you time: '. $this->bytes_to_emoji (0x1f1e8). " \ n ". Date (" Y-m-d h:i:s ", Time ())." \ n "." Click on the database '. ' \ n "."                    <a href= "http://www.cnblogs.com/Elosithang/p/6401061.html" > Internet CAE sharing Data </a> '; } if (Is_array ($content)) {if (isset ($content [0])) {$result = $this->transmitnews ($obje            CT, $content);            }else if (isset ($content [' Musicurl ')) {$result = $this->transmitmusic ($object, $content);        }}else{$result = $this->transmittext ($object, $content);    } return $result;        }//Receive picture message Private function Receiveimage ($object) {$content = Array ("mediaid" = + $object->mediaid);        $result = $this->transmitimage ($object, $content);    return $result;}//Receive Location message Private function ReceiveLocation ($object) {$content = "You are sending a location, Longitude:". $object->location_y. " ; Latitude: ". $object->location_x." ; The zoom level is: ". $object->scale."        ; The position is: ". $object->label;        $result = $this->transmittext ($object, $content);    return $result; }//Receive voice message private function Receivevoice ($object) {if (Isset ($object->recognition) &&!empty ($            object->recognition) {$content = "What you just said was:". $object->recognition;        $result = $this->transmittext ($object, $content);            }else{$content = Array ("mediaid" = = $object->mediaid);        $result = $this->transmitvoice ($object, $content);    } return $result;        }//Receive video message Private function Receivevideo ($object) {$content = "upload video type:". $object->msgtype;        $result = $this->transmittext ($object, $content);    return $result;      }//Receive link message private function Receivelink ($object) {  $content = "You are sending a link with the title:". $object->title. " The content is: ". $object->description."        The link address is: ". $object->url;        $result = $this->transmittext ($object, $content);    return $result;            }//Reply text message private function Transmittext ($object, $content) {if (!isset ($content) | | empty ($content)) {        Return ""; } $XMLTPL = "<xml> <tousername><! [cdata[%s]]></tousername> <fromusername><! [cdata[%s]]></fromusername> <CreateTime>%s</CreateTime> <msgtype><! [cdata[text]]></msgtype> <content><!        [cdata[%s]]></content></xml> ";        $result = sprintf ($XMLTPL, $object->fromusername, $object->tousername, Time (), $content);    return $result; }//Reply text message private function transmitnews ($object, $newsArray) {if (!is_array ($newsArray)) {Retu        RN ""; } $ITEMTPL = "<item> <title><! [cdata[%s]]></title> <description><! [cdata[%s]]></description> <picurl><! [cdata[%s]]></picurl> <url><!        [cdata[%s]]></url> </item> ";        $item _str = ""; foreach ($newsArray as $item) {$item _str. = sprintf ($ITEMTPL, $item [' Title '], $item [' Description '], $item [' PicU        RL '], $item [' Url ']); } $XMLTPL = "<xml> <tousername><! [cdata[%s]]></tousername> <fromusername><! [cdata[%s]]></fromusername> <CreateTime>%s</CreateTime> <msgtype><! [cdata[news]]></msgtype> <ArticleCount>%s</ArticleCount> <Articles> $item _str </arti        Cles></xml> ";        $result = sprintf ($XMLTPL, $object->fromusername, $object->tousername, Time (), Count ($newsArray));    return $result; }//Reply to Music message private function Transmitmusic ($object, $musicArray)   {if (!is_array ($musicArray)) {return ""; } $ITEMTPL = "<Music> <title><! [cdata[%s]]></title> <description><! [cdata[%s]]></description> <musicurl><! [cdata[%s]]></musicurl> 

  

PHP Test Code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.