用php實現微信企業號自訂菜單遇到問題,請大神指點!

來源:互聯網
上載者:User
有兩個檔案,一個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

  • 聯繫我們

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