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";