微信開發自動回複功能,訊息類型判斷失敗,PHP語言

來源:互聯網
上載者:User
編寫自動回複,針對使用者不同訊息類型做出回複,程式怎麼調都有問題額。
問題:無論我發送什麼訊息,文本也好,圖片也好,語音也好,都只回複“我只接收圖片訊息”,也就是說程式似乎不執行
if(strtolower($msgType) =="image"){..............}這一判斷.
求各位大神看一下~~~~
GetImageMsg();//這個要調用自動回複訊息!!$wechatObj->valid();class wechatCallbackapiTest{//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>介面驗證>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>public function valid()    {        $echoStr = $_GET["echostr"];        //valid signature , option        if($this->checkSignature()){            header('content-type:text');//在樣本代碼上添加了如此語句,因而介面接成功        echo $echoStr;        exit;        }    }        private function checkSignature()    {        // you must define TOKEN by yourself        if (!defined("TOKEN")) {            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;        }    }//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>自動回複訊息>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  public function GetImageMsg()//自動回複訊息    {           $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                            %s                            %s                            %s                            %s                            0                            ";                         if(strtolower($msgType) =="image")                {                                        if(!empty($picUrl)){                           $msgType ="text";                           $contentStr = "圖片連結:".$picUrl."\n";                           $contentStr =$contentStr."媒體ID:".$mediaId;                        }else{                            $contentStr = "請發送圖片哦";                        }                           }else{                    $msgType ="text";                    $contentStr = "我只接收圖片訊息";                    }                $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);                echo $resultStr;        }        else         {            echo "";            exit;        }    }     }?>


回複討論(解決方案)

可能65行應該是$msgType=$postObj->MsgType;這個吧
多了個$???

可能65行應該是$msgType=$postObj->MsgType;這個吧
多了個$???

謝謝~~~~很有用!虧我搞了半天,原來是這個呀
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.