template.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import, unicode_literals
  3. from library.wechatpy.client.api.base import BaseWeChatAPI
  4. class WeChatTemplate(BaseWeChatAPI):
  5. def set_industry(self, industry_id1, industry_id2):
  6. """
  7. 设置所属行业
  8. 详情请参考
  9. https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277
  10. :param industry_id1: 公众号模板消息所属行业编号
  11. :param industry_id2: 公众号模板消息所属行业编号
  12. :return: 返回的 JSON 数据包
  13. """
  14. return self._post(
  15. 'template/api_set_industry',
  16. data={
  17. 'industry_id1': industry_id1,
  18. 'industry_id2': industry_id2
  19. }
  20. )
  21. def get_industry(self):
  22. """
  23. 获取设置的行业信息
  24. 详情请参考
  25. https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277
  26. :return: 返回的 JSON 数据包
  27. """
  28. return self._get(
  29. 'template/get_industry'
  30. )
  31. def get(self, template_id_short):
  32. """
  33. 获得模板ID
  34. 详情请参考
  35. https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277
  36. :param template_id_short: 模板库中模板的编号,有“TM**”和“OPENTMTM**”等形式
  37. :return: 模板 ID
  38. """
  39. res = self._post(
  40. 'template/api_add_template',
  41. data={
  42. 'template_id_short': template_id_short
  43. },
  44. result_processor=lambda x: x['template_id']
  45. )
  46. return res
  47. add = get
  48. def get_all_private_template(self):
  49. """
  50. 获取模板列表
  51. 详情请参考
  52. https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277
  53. :return: 返回的 JSON 数据包
  54. """
  55. return self._get(
  56. 'template/get_all_private_template'
  57. )
  58. def del_private_template(self, template_id):
  59. """
  60. 删除模板
  61. 详情请参考
  62. https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751277
  63. :param template_id: 公众帐号下模板消息ID
  64. :return: 返回的 JSON 数据包
  65. """
  66. return self._post(
  67. 'template/del_private_template',
  68. data={
  69. 'template_id': template_id
  70. }
  71. )