|
- <?php
- //不加参数
- require_once '../Common/Config.php';
- require_once '../Common/Function.php';
- $dir="../Log";
- if (!is_dir($dir)){
- mkdir($dir);
- }
- $token_file=$dir.'/access_token';
- if (file_exists($token_file) && time()-filemtime($token_file)<4800){
- write_log("menu--文件中读取的token:".file_get_contents($token_file));
- $access_token= file_get_contents($token_file);
- }else{
- $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".APPID."&secret=".APPSECRET;
- $result=http_request($url);
- if(!$result){
- write_log("menu-获取token出错");
- echo "menu-获取token出错";
- exit;
- }
-
- $result_obj=json_decode($result);
- file_put_contents($token_file, $result_obj->access_token);
- write_log("menu-url获取的token:".$result_obj->access_token);
- $access_token= $result_obj->access_token;
- }
-
- $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token;
- $jsonmenu = '{
- "button":[
- {
- "name":"出行预订",
- "type":"view",
- "url":"http://xmwxc.zhizhuchuxing.cn/index.html"
-
- },
- {
- "name":"我的订单",
- "type":"view",
- "url":"http://xmwxc.zhizhuchuxing.cn/core/my_order.asp"
-
- },
- {
- "name":"更多服务",
- "sub_button":[
- {
- "type":"click",
- "name":"蜘蛛免单",
- "key":"Push-Photo-List"
- },
- {
- "type":"view",
- "name":"普陀山门票",
- "url":"http://xmwxc.zhizhuchuxing.cn/bookingHomePage/mdidiDetail.html?prod_code=NSPTSM01"
- },
- {
- "type":"view",
- "name":"品牌介绍",
- "url":"http://mp.weixin.qq.com/s?__biz=MzIwNjI0MDAwOQ==&mid=502857759&idx=1&sn=0ba36df9d9db8ead5119082bbb5b9cca&scene=18#wechat_redirect"
- },
- {
- "type":"view",
- "name":"帮助中心",
- "url":"http://mp.weixin.qq.com/s?__biz=MzIwNjI0MDAwOQ==&mid=502857753&idx=1&sn=a9039c8508a05f08f41027307296995f&scene=18#wechat_redirect"
- }]
-
-
- }]
- }';
- $result = http_request($url, $jsonmenu);
- var_dump($result);
|