有兩個檔案,一個response.php是用來響應訊息的。
另一個是初始頁面Sample.php。問題在於,我菜單建立出來了,但是點擊之後沒有出現我response裡面的訊息回傳,不知道為什麼。
responseMsg();$res = file_get_contents($token_access_url);$arr_result = json_decode($res,true);define("ACCESS_TOKEN",$arr_result['access_token']);$make_menu_url = "https://qyapi.weixin.qq.com/cgi-bin/menu/get?access_token=".ACCESS_TOKEN."&agentid=2";$menudata = '{"button":[{ "type":"click", "name":"今日歌曲", "key":"V1001_TODAY_MUSIC" },{ "type":"click", "name":"歌手簡介", "key":"V1001_TODAY_SINGER" },{ "name":"菜單", "sub_button":[{ "type":"view", "name":"搜尋", "url":"http://www.soso.com/" },{ "type":"view", "name":"視頻", "url":"http://v.qq.com/" },{ "type":"click", "name":"贊一下我們", "key" :"V1001_GOOD" }] }] }'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $make_menu_url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,FALSE); curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (compatible; MSIE 5.01;Windows NT 5.0)'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); curl_setopt($ch, CURLOPT_AUTOREFERER,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $menudata); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); $info = curl_exec($ch); if(curl_errno($ch)){ echo 'Errno'.curl_error($ch); } curl_close($ch); print_r($info);?>
checkSignature()){ echo $echoStr; exit; } } public function responseMsg() {//get post data, May be due to the different environments$postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; $sendmsg = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=".ACCESS_TOKEN; //extract post data$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); $fromUsername = $postObj->FromUserName; $toUsername = $postObj->ToUserName; $MsgType = $postObj->MsgType; $MsgId = $postObj->MsgId; $Event = $postObj->Event; $EventKey = $postObj->EventKey; $CreateTime = intval($postObj->CreateTime); $formTime = date("Y-m-d H:i:s",$CreateTime); $agentid = $postObj->AgentID; $msg = "開發人員id:".$toUsername."\n"; $msg .= "使用者id:".$fromUsername."\n"; $msg .= "事件訊息id:".$MsgId."\n"; $msg .= "事件訊息類型id:".$MsgType."\n"; $msg .= "事件類型:".$Event."\n"; $msg .= "事件KEY值,與自訂菜單介面中KEY值對應:".$EventKey."\n"; $msg .= "事件發送過來的時間戳記:".$CreateTime."\n"; $msg .= "訊息發生具體時間:".$formTime."\n"; /* $textTpl = "%s%s%s%s%s"; */ $textTpl = " %s %s %s %s %s %s %s "; $contentStr = $msg; $resultStr = sprintf($textTpl,$fromUsername,$toUsername,$formTime,$MsgType,$Event,$EventKey, $agentid); echo $resultStr; }private function checkSignature(){ $signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; $token = TOKEN;$tmpArr = array($token, $timestamp, $nonce);sort($tmpArr);$tmpStr = implode( $tmpArr );$tmpStr = sha1( $tmpStr );if( $tmpStr == $signature ){return true;}else{return false;}}}?>
真是非常鬱悶,企業號和服務號還是有點不同的。
回複討論(解決方案)
功能表項目不管怎麼點,就是沒有回複。除了url類型的會正常跳轉網頁。
看看 菜單的click時間處理了麼, 關鍵詞 key對不對 。。。。php檔案有沒有 文法 錯誤什麼的
http://www.phpjm.net/encode.html