国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
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.

89 lines
2.9KB

  1. <?php
  2. namespace WeChat;
  3. if (!defined('DEDEINC')) exit('dedebiz');
  4. use WeChat\Contracts\BasicWeChat;
  5. /**
  6. * 微信菜单管理
  7. * Class Menu
  8. * @package WeChat
  9. */
  10. class Menu extends BasicWeChat
  11. {
  12. /**
  13. * 自定义菜单查询接口
  14. * @return array
  15. * @throws \WeChat\Exceptions\InvalidResponseException
  16. * @throws \WeChat\Exceptions\LocalCacheException
  17. */
  18. public function get()
  19. {
  20. $url = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=ACCESS_TOKEN";
  21. $this->registerApi($url, __FUNCTION__, func_get_args());
  22. return $this->httpGetForJson($url);
  23. }
  24. /**
  25. * 自定义菜单删除接口
  26. * @return array
  27. * @throws \WeChat\Exceptions\InvalidResponseException
  28. * @throws \WeChat\Exceptions\LocalCacheException
  29. */
  30. public function delete()
  31. {
  32. $url = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=ACCESS_TOKEN";
  33. $this->registerApi($url, __FUNCTION__, func_get_args());
  34. return $this->httpGetForJson($url);
  35. }
  36. /**
  37. * 自定义菜单创建
  38. * @param array $data
  39. * @return array
  40. * @throws \WeChat\Exceptions\InvalidResponseException
  41. * @throws \WeChat\Exceptions\LocalCacheException
  42. */
  43. public function create(array $data)
  44. {
  45. $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN";
  46. $this->registerApi($url, __FUNCTION__, func_get_args());
  47. return $this->httpPostForJson($url, $data);
  48. }
  49. /**
  50. * 创建个性化菜单
  51. * @param array $data
  52. * @return array
  53. * @throws \WeChat\Exceptions\InvalidResponseException
  54. * @throws \WeChat\Exceptions\LocalCacheException
  55. */
  56. public function addConditional(array $data)
  57. {
  58. $url = "https://api.weixin.qq.com/cgi-bin/menu/addconditional?access_token=ACCESS_TOKEN";
  59. $this->registerApi($url, __FUNCTION__, func_get_args());
  60. return $this->httpPostForJson($url, $data);
  61. }
  62. /**
  63. * 删除个性化菜单
  64. * @param string $menuid
  65. * @return array
  66. * @throws \WeChat\Exceptions\InvalidResponseException
  67. * @throws \WeChat\Exceptions\LocalCacheException
  68. */
  69. public function delConditional($menuid)
  70. {
  71. $url = "https://api.weixin.qq.com/cgi-bin/menu/delconditional?access_token=ACCESS_TOKEN";
  72. $this->registerApi($url, __FUNCTION__, func_get_args());
  73. return $this->httpPostForJson($url, ['menuid' => $menuid]);
  74. }
  75. /**
  76. * 测试个性化菜单匹配结果
  77. * @param string $openid
  78. * @return array
  79. * @throws \WeChat\Exceptions\InvalidResponseException
  80. * @throws \WeChat\Exceptions\LocalCacheException
  81. */
  82. public function tryConditional($openid)
  83. {
  84. $url = "https://api.weixin.qq.com/cgi-bin/menu/trymatch?access_token=ACCESS_TOKEN";
  85. $this->registerApi($url, __FUNCTION__, func_get_args());
  86. return $this->httpPostForJson($url, ['user_id' => $openid]);
  87. }
  88. }
  89. ?>