menu.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import, unicode_literals
  3. from wechatpy.client.api.base import BaseWeChatAPI
  4. class WeChatMenu(BaseWeChatAPI):
  5. """
  6. 自定义菜单
  7. https://work.weixin.qq.com/api/doc#90000/90135/90230
  8. """
  9. def create(self, agent_id, menu_data):
  10. """
  11. 创建菜单
  12. https://work.weixin.qq.com/api/doc#90000/90135/90231
  13. :param agent_id: 应用id
  14. """
  15. return self._post(
  16. 'menu/create',
  17. params={
  18. 'agentid': agent_id
  19. },
  20. data=menu_data
  21. )
  22. def get(self, agent_id):
  23. """
  24. 获取菜单
  25. https://work.weixin.qq.com/api/doc#90000/90135/90232
  26. :param agent_id: 应用id
  27. """
  28. return self._get(
  29. 'menu/get',
  30. params={
  31. 'agentid': agent_id
  32. }
  33. )
  34. def delete(self, agent_id):
  35. """
  36. 删除菜单
  37. https://work.weixin.qq.com/api/doc#90000/90135/90233
  38. :param agent_id: 应用id
  39. """
  40. return self._get(
  41. 'menu/delete',
  42. params={
  43. 'agentid': agent_id
  44. }
  45. )
  46. def update(self, agent_id, menu_data):
  47. self.delete(agent_id)
  48. return self.create(agent_id, menu_data)