關於微信開發模式的PHP代碼

來源:互聯網
上載者:User
valid();$wechatObj->responseMsg();class wechatCallbackapiTest{public function valid()    {        $echoStr = $_GET["echostr"];        //valid signature , option        if($this->checkSignature()){        echo $echoStr;        exit;        }    }    public function responseMsg()    {//get post data, May be due to the different environments$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];      //extract post dataif (!empty($postStr)){                              $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);                $fromUsername = $postObj->FromUserName;                $toUsername = $postObj->ToUserName;$type =$postObj->MsgType;$customevent = $postObj->Event;$latitude =$postObj->Location_X;$longitude =$postObj->Location_Y;                $keyword = trim($postObj->Content);                $time = time();                $textTpl = "%s%s%s%s%s0";             switch($type){case "event";if($customevent == "subscribe"){$contentStr = "感謝關注"}break;case "image"$contentStr ="圖片很棒";    break;case "location";$contentStr ="{$latitude},{longitude}";break;case "text";switch($keyword){case "1" $contentStr="1" break; case "2" $contentStr ="2" break; default; $contentStr= "hi";} break; } $msgType = "text"; $resultStr = sprintf($textTpl,$fromUsername,$toUsername,$time,$msgType,$contentStr); echo $resultStr; }else                           {        echo "";        exit;        }    }private function checkSignature(){        $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 ){return true;}else{return false;}}}?>

代碼檢查了N遍但是功能一個都不能實現 !球大神幫幫~另外怎麼也做不出來調用百度地圖來實現導航如果能一起協助就更好了


回複討論(解決方案)

$keyword
輸出看看

public function valid()    {        $echoStr = $_GET["echostr"];         //valid signature , option        if($this->checkSignature()){            echo $echoStr;            exit;        }    }
這代碼是為了填寫url 通過驗證, 通過之後 ,可以把這個代碼改了。如改成
public function valid()    {        $echoStr = $_GET["echostr"];         //valid signature , option        if($this->checkSignature()){            //echo $echoStr;            //exit;responseMsg();        }    }
就行了、

公眾帳號,只能看作一種特殊的能識別使用者身份的瀏覽器,你想要識現的功能,大多都像你做網站一下,只是入口不同而已,如果想要百度的導航,就要你的網站接入百度介面 http://api.map.baidu.com/lbsapi/cloud/webservice-placeapi.htm 只是使用者的當前位置,可以讓使用者發地理位置訊息。

如果 要做菜單,可以看這裡 http://pan.baidu.com/s/1eQd12wy

代碼有問題啊,case “1”:應該是冒號而不是讀號啊,其他的沒什麼問題

 switch($type)            {            case "event":            if($customevent == "subscribe")            {$contentStr = "感謝關注";}            break;            case "image":            $contentStr ="圖片很棒";            break;            case "location":            $contentStr ="{$latitude},{longitude}";            break;            case "text":            switch($keyword)            {case "1":             $contentStr="1";             break;             case "2":             $contentStr ="2";             break;             default;             $contentStr= "hi";}             break;             }

也要改下

default:
$contentStr= "hi";

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.