Create.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace app\index\controller;
  3. require_once('function.php');
  4. use think\Controller;
  5. use \app\index\controller\Common;
  6. class Create extends Common
  7. {
  8. //创建菜单项
  9. public function creatMenu()
  10. {
  11. //组装请求的url地址
  12. $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$this->accessToken;
  13. $data = array(
  14. // button下的每一个元素
  15. "button"=>array(
  16. //第一个一级菜单
  17. array(
  18. "name"=>"报修管理",
  19. "sub_button"=>array(
  20. array("name"=>'我要报修',"type"=>"view",
  21. 'url'=>"http://ceshi.kamihu.com/index/index/repairs"),
  22. array('name'=>'报修记录',"type"=>"view",
  23. 'url'=>"http://ceshi.kamihu.com/index/index/repairsList"),
  24. )
  25. ),
  26. array(
  27. "name"=>"维修管理",
  28. "sub_button"=>array(
  29. array("name"=>'维修记录',"type"=>"view",
  30. 'url'=>"http://ceshi.kamihu.com/index/index/polist")
  31. )
  32. ),
  33. array(
  34. "name"=>"个人中心",
  35. "sub_button"=>array(
  36. array("name"=>'个人信息',"type"=>"view",
  37. 'url'=>"http://ceshi.kamihu.com/index/index/myinfo"),
  38. array('name'=>'个人注册',"type"=>"view",
  39. 'url'=>"http://ceshi.kamihu.com/index/index/register"),
  40. array('name'=>'分享注册',"type"=>"view",
  41. 'url'=>"http://ceshi.kamihu.com/index/index/sharepage")
  42. )
  43. )
  44. )
  45. );
  46. // 将数据转换为json格式
  47. $data = json_encode($data,JSON_UNESCAPED_UNICODE);
  48. $result = http_curl($url,$data,'post');
  49. dump($result);
  50. }
  51. }