agent.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import, unicode_literals
  3. from optionaldict import optionaldict
  4. from wechatpy.client.api.base import BaseWeChatAPI
  5. class WeChatAgent(BaseWeChatAPI):
  6. """
  7. https://work.weixin.qq.com/api/doc#90000/90135/90226
  8. """
  9. def get(self, agent_id):
  10. """
  11. 获取指定的应用详情
  12. https://work.weixin.qq.com/api/doc#90000/90135/90227/获取指定的应用详情/
  13. :param agent_id: 应用id
  14. :return: 返回的 JSON 数据包
  15. """
  16. return self._get(
  17. 'agent/get',
  18. params={
  19. 'agentid': agent_id
  20. }
  21. )
  22. def list(self):
  23. """
  24. 获取access_token对应的应用列表
  25. https://work.weixin.qq.com/api/doc#90000/90135/90227/获取access_token对应的应用列表/
  26. :return: 应用概况列表
  27. """
  28. res = self._get('agent/list')
  29. return res['agentlist']
  30. def set(self,
  31. agent_id,
  32. name=None,
  33. description=None,
  34. redirect_domain=None,
  35. logo_media_id=None,
  36. report_location_flag=0,
  37. is_report_user=True,
  38. is_report_enter=True):
  39. """
  40. 设置应用
  41. https://work.weixin.qq.com/api/doc#90000/90135/90228
  42. :param agent_id: 企业应用的id
  43. :param name: 企业应用名称,长度不超过32个utf8字符
  44. :param description: 企业应用详情,长度为4至120个utf8字符
  45. :param redirect_domain: 企业应用可信域名。注意:域名需通过所有权校验,否则jssdk功能将受限,此时返回错误码85005
  46. :param logo_media_id: 企业应用头像的mediaid,通过素材管理接口上传图片获得mediaid,上传后会自动裁剪成方形和圆形两个头像
  47. :param report_location_flag: 企业应用是否打开地理位置上报 0:不上报;1:进入会话上报;
  48. :param is_report_enter: 是否上报用户进入应用事件。0:不接收;1:接收。
  49. :param is_report_user: 是否接收用户变更通知。0:不接收;1:接收。
  50. :return: 返回的 JSON 数据包
  51. """
  52. agent_data = optionaldict()
  53. agent_data['agentid'] = agent_id
  54. agent_data['name'] = name
  55. agent_data['description'] = description
  56. agent_data['redirect_domain'] = redirect_domain
  57. agent_data['logo_mediaid'] = logo_media_id
  58. agent_data['report_location_flag'] = report_location_flag
  59. agent_data['isreportenter'] = 1 if is_report_enter else 0
  60. agent_data['isreportuser'] = 1 if is_report_user else 0
  61. return self._post(
  62. 'agent/set',
  63. data=agent_data
  64. )