Micro-trust public platform development Introduction--php, to achieve automatic response text, graphics, click events

Source: Internet
Author: User
Tags exit sprintf trim valid

A page of code to achieve micro-letter basic response and click event Features, deployed to SAE or BAE, the complete basic free server

Don't understand the code are basically everyone can do their own micro-credit public number


 -->Valid ();

}else{//Reply message $wechatObj->responsemsg ();}
        Class Wechatcallbackapitest {public function valid () {$echoStr = $_get["Echostr"];
            if ($this->checksignature ()) {echo $echoStr;
        Exit
        The 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;
    }///Reply message public function responsemsg () {$postStr = $GLOBALS ["Http_raw_post_data"];
        if (!empty ($POSTSTR)) {$POSTOBJ = simplexml_load_string ($postStr, ' simplexmlelement ', libxml_nocdata);

     $RX _type = Trim ($postObj->msgtype);   Switch ($RX _type) {case "text": $resultStr = $this->receivetext ($POSTOBJ);
            Break
                Case "image": $resultStr = $this->receiveimage ($POSTOBJ);
            Break
                Case "Location": $resultStr = $this->receivelocation ($POSTOBJ);
            Break
                Case "Voice": $resultStr = $this->receivevoice ($POSTOBJ);
            Break
                Case "Video": $resultStr = $this->receivevideo ($POSTOBJ);
            Break
                Case "link": $resultStr = $this->receivelink ($POSTOBJ);
            Break
                Case "Event": $resultStr = $this->receiveevent ($POSTOBJ);
            Break
                Default: $resultStr = "Unknow msg type:". $RX _type;
        Break
    Echo $resultStr;
        }else {echo "";
  Exit  }///Receive text message Private function Receivetext ($object) {$keyword = Trim ($object->content);
        $url = "Http://api100.duapp.com/movie/?appkey=DIY_miaomiao&name=". $keyword;
        $output = file_get_contents ($url, $keyword);
        $CONTENTSTR = Json_decode ($output, true);
        if (Is_array ($CONTENTSTR)) {$resultStr = $this->transmitnews ($object, $CONTENTSTR);
        }else{$resultStr = $this->transmittext ($object, $CONTENTSTR);
    return $resultStr;
        //Receive event, attention, etc. private function receiveevent ($object) {$contentStr = "";    Switch ($object->event) {case "subscribe": $contentStr = "You pay attention to me";
            After the focus of response to the content break;
                Case "Unsubscribe": $contentStr = "";
            Break    Case "click": $contentStr = $this->receiveclick ($object); Click event BreaK
                Default: $CONTENTSTR = "Receive a new event:". $object->event;
        Break
    return $contentStr; //Receive picture Private function Receiveimage ($object) {$contentStr = "You sent the picture, address is:". $object->picurl
        ;
        $RESULTSTR = $this->transmittext ($object, $CONTENTSTR);
    return $resultStr; ///Receive Voice private function Receivevoice ($object) {$contentStr = "You are sending the voice, the media ID is:". $object ;
        MediaId;
        $RESULTSTR = $this->transmittext ($object, $CONTENTSTR);
    return $resultStr; ///Receive video Private function Receivevideo ($object) {$contentStr = "You are sending the video, the media ID is:". $object->medi
        AId;
        $RESULTSTR = $this->transmittext ($object, $CONTENTSTR);
    return $resultStr; }//Location message Private function ReceiveLocation ($object) {$contentStr = "You are sending the position, Latitude is:". $object->loc Ation_x. " ; The longitude is: ". $object->loCation_y. " ; The zoom level is: ". $object->scale."
        The location is: ". $object->label;
        $RESULTSTR = $this->transmittext ($object, $CONTENTSTR);
    return $resultStr; }//Link message private Function Receivelink ($object) {$contentStr = "You are sending a link with the title:". $object->title. " The content is: ". $object->description."
        , the link address is: ". $object->url;
        $RESULTSTR = $this->transmittext ($object, $CONTENTSTR);
    return $resultStr;
    
    
   }

//Click menu Message Private Function Receiveclick ($object) {switch ($object->eventkey) {case "1": $contentStr = "cat sauce personalized DIY clothing, Our professional custom Personalized "class uniforms, couples outfit, parent-child outfit and so on, have a short T-shirt, Wei clothing, long shorts" To print can be, to give you warm and lovely ta, something can be a direct message micro-letter "; Break Case "2": $contentStr = "You clicked on the menu:". $object->eventkey; Break Case "3": $contentStr = "is silly force"; Break Default: $contentStr = "You clicked on the menu:". $object->eventkey; Break ///Two reply if (Is_array ($CONTENTSTR)) {$resultStr = $this->transmitnews ($object, $CONTENTSTR); else{$resultStr = $this->transmittext ($object, $CONTENTSTR);} return $resultStr; }//Reply text message private function Transmittext ($object, $content) {$textTpl = " %s ; $RESULTSTR = sprintf ($TEXTTPL, $object->fromusername, $object->tousername, Time (), $content); return $resultStr; }

Reply Text Private function transmitnews ($object, $arr _item) {if (!is_array ($arr _item)) return;

$ITEMTPL = " "; $item _str = ""; foreach ($arr _item as $item) $item _str. = sprintf ($ITEMTPL, $item [' Title '], $item [' Description '], $item [' Picurl '], $item [' URL ']];

$NEWSTPL = ' %s %s $item _str ";

$RESULTSTR = sprintf ($NEWSTPL, $object->fromusername, $object->tousername, Time (), COUNT ($arr _item)); return $resultStr; }//Music message Private Function Transmitmusic ($object, $musicArray, $flag = 0) {$ITEMTPL = " ";

$item _str = sprintf ($ITEMTPL, $musicArray [' Title '], $musicArray [' Description '], $musicArray [' Musicurl '], $musicArray [' Hqmusicurl ']);

$TEXTTPL = " %s $item _str %d ";

$RESULTSTR = sprintf ($TEXTTPL, $object->fromusername, $object->tousername, Time (), $flag); return $resultStr; }}?>



Related Article

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.