Menu.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | WeChatDeveloper
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2023 ThinkAdmin [ thinkadmin.top ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: https://thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // | 免责声明 ( https://thinkadmin.top/disclaimer )
  11. // +----------------------------------------------------------------------
  12. // | gitee 代码仓库:https://gitee.com/zoujingli/WeChatDeveloper
  13. // | github 代码仓库:https://github.com/zoujingli/WeChatDeveloper
  14. // +----------------------------------------------------------------------
  15. namespace WeChat;
  16. use WeChat\Contracts\BasicWeChat;
  17. /**
  18. * 微信菜单管理
  19. * Class Menu
  20. * @package WeChat
  21. */
  22. class Menu extends BasicWeChat
  23. {
  24. /**
  25. * 自定义菜单查询接口
  26. * @return array
  27. * @throws \WeChat\Exceptions\InvalidResponseException
  28. * @throws \WeChat\Exceptions\LocalCacheException
  29. */
  30. public function get()
  31. {
  32. $url = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=ACCESS_TOKEN";
  33. $this->registerApi($url, __FUNCTION__, func_get_args());
  34. return $this->httpGetForJson($url);
  35. }
  36. /**
  37. * 自定义菜单删除接口
  38. * @return array
  39. * @throws \WeChat\Exceptions\InvalidResponseException
  40. * @throws \WeChat\Exceptions\LocalCacheException
  41. */
  42. public function delete()
  43. {
  44. $url = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=ACCESS_TOKEN";
  45. $this->registerApi($url, __FUNCTION__, func_get_args());
  46. return $this->httpGetForJson($url);
  47. }
  48. /**
  49. * 自定义菜单创建
  50. * @param array $data
  51. * @return array
  52. * @throws \WeChat\Exceptions\InvalidResponseException
  53. * @throws \WeChat\Exceptions\LocalCacheException
  54. */
  55. public function create(array $data)
  56. {
  57. $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN";
  58. $this->registerApi($url, __FUNCTION__, func_get_args());
  59. return $this->httpPostForJson($url, $data);
  60. }
  61. /**
  62. * 创建个性化菜单
  63. * @param array $data
  64. * @return array
  65. * @throws \WeChat\Exceptions\InvalidResponseException
  66. * @throws \WeChat\Exceptions\LocalCacheException
  67. */
  68. public function addConditional(array $data)
  69. {
  70. $url = "https://api.weixin.qq.com/cgi-bin/menu/addconditional?access_token=ACCESS_TOKEN";
  71. $this->registerApi($url, __FUNCTION__, func_get_args());
  72. return $this->httpPostForJson($url, $data);
  73. }
  74. /**
  75. * 删除个性化菜单
  76. * @param string $menuid
  77. * @return array
  78. * @throws \WeChat\Exceptions\InvalidResponseException
  79. * @throws \WeChat\Exceptions\LocalCacheException
  80. */
  81. public function delConditional($menuid)
  82. {
  83. $url = "https://api.weixin.qq.com/cgi-bin/menu/delconditional?access_token=ACCESS_TOKEN";
  84. $this->registerApi($url, __FUNCTION__, func_get_args());
  85. return $this->httpPostForJson($url, ['menuid' => $menuid]);
  86. }
  87. /**
  88. * 测试个性化菜单匹配结果
  89. * @param string $openid
  90. * @return array
  91. * @throws \WeChat\Exceptions\InvalidResponseException
  92. * @throws \WeChat\Exceptions\LocalCacheException
  93. */
  94. public function tryConditional($openid)
  95. {
  96. $url = "https://api.weixin.qq.com/cgi-bin/menu/trymatch?access_token=ACCESS_TOKEN";
  97. $this->registerApi($url, __FUNCTION__, func_get_args());
  98. return $this->httpPostForJson($url, ['user_id' => $openid]);
  99. }
  100. }