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.