Using PHP to implement the WeChat enterprise custom menu encountered problems, please big God guidance!

Source: Internet
Author: User
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

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.