WeChat Development Auto-reply function, message type judgment failed, PHP language

Source: Internet
Author: User
Tags cdata auto reply message
Write the automatic reply, for the user different message type to reply, the program How to adjust all have the problem amount.
Question: No matter what message I send, text or picture, or voice, I only reply "I only receive the picture message", that is, the program does not seem to execute
if (Strtolower ($msgType) = = = "image") {...}} This judgment.
Please look at the great God ~ ~ ~
 Getimagemsg ();//This is to invoke the automatic reply message!! $WECHATOBJ->valid (); class wechatcallbackapitest{//>>>>>>>>>>>>>> >>>>>>>>>>>>>>> Interface Verification >>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>        >>>>>>>public function Valid () {$echoStr = $_get["Echostr"]; Valid signature, option if ($this->checksignature ()) {header (' content-type:text ');//Add such a statement to the sample code, as        And the interface successfully echo $ECHOSTR;        Exit }} Private Function Checksignature () {//must define TOKEN by yourself if (!defined ("TOKE        N ")) {throw new Exception (' TOKEN is not defined! ');        } $signature = $_get["signature"];        $timestamp = $_get["timestamp"];                        $nonce = $_get["nonce"];        $token = token; $TMPARR = ArraY ($token, $timestamp, $nonce);        Use sort_string rule SORT ($TMPARR, sort_string);        $TMPSTR = implode ($TMPARR);                $TMPSTR = SHA1 ($TMPSTR);        if ($tmpStr = = $signature) {return true;        }else{return false; }}//>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>//>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>> automatically reply to messages >>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>> Public Function getimagemsg ()//Auto reply message {$postStr = $GLOBALS ["Http_raw_post_data"];                if (!empty ($POSTSTR)) {Libxml_disable_entity_loader (true);                $POSTOBJ = simplexml_load_string ($postStr, ' simplexmlelement ', libxml_nocdata);                $fromUsername = $POSTOBJ->fromusername;                $toUsername = $POSTOBJ->tousername;                $msgType = $POSTOBJ $MsgType;                $picUrl =trim ($postObj->picurl);                $mediaId =trim ($postObj->mediaid);                $time = time (); $TEXTTPL = "
 
   
    %s 
    
   
    ! [cdata[%s]]> 
    
   
    %s 
                               
 msgtype> %s  
    %s 
    
   
     0 
    
  
 ";                           if (Strtolower ($msgType) = = "image") {if (!empty ($PICURL)) {                           $msgType = "text"; $contentStr = "Picture link:". $picUrl. "                           \ n "; $CONTENTSTR = $contentStr. "                        Media ID: ". $mediaId;                        }else{$contentStr = "Please send picture oh";                    }}else{$msgType = "text";                    $CONTENTSTR = "I only receive picture messages";                } $resultStr = sprintf ($TEXTTPL, $fromUsername, $toUsername, $time, $msgType, $CONTENTSTR);        Echo $resultStr;            } else {echo "";        Exit }}}?>


Reply to discussion (solution)

Maybe 65 lines should be $msgtype= $postObj->msgtype; this.
A $??? more.

Maybe 65 lines should be $msgtype= $postObj->msgtype; this.
A $??? more.

Thank you ~ ~ ~ ~ Very useful! I've been doing this for a while.
  • 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.