There are two files, and a response.php is used to respond to messages.
The other is the initial page sample.php. The problem is, I created the menu, but after the click did not appear my response inside the message postback, do not know why.
Responsemsg (); $res = file_get_contents ($token _access_url), $arr _result = Json_decode ($res, True);d efine ("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 ":" Today's Song "," Key ":" V1001_today_music "},{" Typ E ":" Click "," Name ":" Singer Profile "," Key ":" V1001_today_singer "},{" name ":" Menu "," Sub_button ": [{" Type ":" View "," Name ":" Search "," url ":" http://www.soso.com/"},{" type ":" View "," Name ":" Video "," url ":" http://v.qq.com/"}, {"Type": "click", "Name": "Likes Us", "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, could 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 = "Developer ID:" $toUsername. " \ n "; $msg. = "User id:". $fromUsername. " \ n "; $msg. = "thingItem Message ID: ". $MsgId." \ n "; $msg. = "event message type ID:". $MsgType. " \ n "; $msg. = "Event Type:". $Event. " \ n "; $msg. = "Event key value corresponding to the key value in the custom menu interface:". $EventKey. " \ n "; $msg. = "Event sent over timestamp:". $CreateTime. " \ n "; $msg. = "message occurred at the exact time:" $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 ($tmp STR); if ($tmpStr = = $signature) {return true;} Else{return false;}}? >
Really depressed, enterprise number and service number is a little different.
Reply to discussion (solution)
menu item No matter what point, there is no reply. In addition to the URL type, the normal jump page is.
Look at the menu click time Processing, keyword key is right .... PHP file has no syntax errors or anything
Http://www.phpjm.net/encode.html