You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

71 lines
2.1 KiB

  1. <?php
  2. //不加参数
  3. require_once '../Common/Config.php';
  4. require_once '../Common/Function.php';
  5. $dir="../Log";
  6. if (!is_dir($dir)){
  7. mkdir($dir);
  8. }
  9. $token_file=$dir.'/access_token';
  10. if (file_exists($token_file) && time()-filemtime($token_file)<4800){
  11. write_log("menu--文件中读取的token:".file_get_contents($token_file));
  12. $access_token= file_get_contents($token_file);
  13. }else{
  14. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".APPID."&secret=".APPSECRET;
  15. $result=http_request($url);
  16. if(!$result){
  17. write_log("menu-获取token出错");
  18. echo "menu-获取token出错";
  19. exit;
  20. }
  21. $result_obj=json_decode($result);
  22. file_put_contents($token_file, $result_obj->access_token);
  23. write_log("menu-url获取的token:".$result_obj->access_token);
  24. $access_token= $result_obj->access_token;
  25. }
  26. $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token;
  27. $jsonmenu = '{
  28. "button":[
  29. {
  30. "name":"出行预订",
  31. "type":"view",
  32. "url":"http://xmwxc.zhizhuchuxing.cn/index.html"
  33. },
  34. {
  35. "name":"我的订单",
  36. "type":"view",
  37. "url":"http://xmwxc.zhizhuchuxing.cn/core/my_order.asp"
  38. },
  39. {
  40. "name":"更多服务",
  41. "sub_button":[
  42. {
  43. "type":"click",
  44. "name":"蜘蛛免单",
  45. "key":"Push-Photo-List"
  46. },
  47. {
  48. "type":"view",
  49. "name":"普陀山门票",
  50. "url":"http://xmwxc.zhizhuchuxing.cn/bookingHomePage/mdidiDetail.html?prod_code=NSPTSM01"
  51. },
  52. {
  53. "type":"view",
  54. "name":"品牌介绍",
  55. "url":"http://mp.weixin.qq.com/s?__biz=MzIwNjI0MDAwOQ==&mid=502857759&idx=1&sn=0ba36df9d9db8ead5119082bbb5b9cca&scene=18#wechat_redirect"
  56. },
  57. {
  58. "type":"view",
  59. "name":"帮助中心",
  60. "url":"http://mp.weixin.qq.com/s?__biz=MzIwNjI0MDAwOQ==&mid=502857753&idx=1&sn=a9039c8508a05f08f41027307296995f&scene=18#wechat_redirect"
  61. }]
  62. }]
  63. }';
  64. $result = http_request($url, $jsonmenu);
  65. var_dump($result);