ホームページ  >  記事  >  バックエンド開発  >  PHP を使用して WeChat エンタープライズ アカウントのカスタム メニューを実装する際に問題が発生した場合は、アドバイスをお願いします。

PHP を使用して WeChat エンタープライズ アカウントのカスタム メニューを実装する際に問題が発生した場合は、アドバイスをお願いします。

WBOY
WBOYオリジナル
2016-06-23 13:45:43899ブラウズ

2 つのファイルがあり、1 つの response.php はメッセージに応答するために使用されます。
もう 1 つは最初のページ Sample.php です。問題は、メニューが作成されたのに、クリックしても応答のメッセージが表示されないことです。理由はわかりません。

<?phpinclude_once "Response.php";define("CORPID","wx5aae8fe610db907c");define("CORPSECRET","zmEbFeMuTwVJlUiZdv2-502ULoM0qJX3RUrXywMXnC_rqZgGuJIX3MUAnwWBQ6cQ");$token_access_url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=".CORPID."&corpsecret=".CORPSECRET;$wechatObj = new wechatCallbackapiTest();$wechatObj->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);?>



<?phpclass 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"];        $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 = "<xml>							<ToUserName><![CDATA[%s]]></ToUserName>							<FromUserName><![CDATA[%s]]></FromUserName>							<CreateTime>%s</CreateTime>							<MsgType><![CDATA[%s]]></MsgType>							<Content><![CDATA[%s]]></Content>							</xml>";       */                              $textTpl = "<xml>                           <ToUserName><![CDATA[%s]]></ToUserName>                           <FromUserName><![CDATA[%s]]></FromUserName>                           <CreateTime>%s</CreateTime>                           <MsgType><![CDATA[%s]]></MsgType>                           <Event><![CDATA[%s]]></Event>                           <EventKey><![CDATA[%s]]></EventKey>                           <AgentID>%s</AgentID>                           </xml>";				                $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 タイプを除いて、Web ページは通常どおりリダイレクトされます。

メニューのクリック時間が処理されているか、キーワードキーが正しいか確認してください。 。 。 。 php ファイルに構文エラーはありますか?

http://www.phpjm.net/encode.html

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。