misc.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import, unicode_literals
  3. from library.wechatpy.client.api.base import BaseWeChatAPI
  4. class WeChatMisc(BaseWeChatAPI):
  5. def short_url(self, long_url):
  6. """
  7. 将一条长链接转成短链接
  8. 详情请参考
  9. http://mp.weixin.qq.com/wiki/10/165c9b15eddcfbd8699ac12b0bd89ae6.html
  10. :param long_url: 长链接地址
  11. :return: 返回的 JSON 数据包
  12. 使用示例::
  13. from wechatpy import WeChatClient
  14. client = WeChatClient('appid', 'secret')
  15. res = client.misc.short_url('http://www.qq.com')
  16. """
  17. return self._post(
  18. 'shorturl',
  19. data={
  20. 'action': 'long2short',
  21. 'long_url': long_url
  22. }
  23. )
  24. def get_wechat_callback_ips(self):
  25. """
  26. 获取微信服务器回跳地址列表
  27. :return: 回跳地址列表
  28. 使用示例::
  29. from wechatpy import WeChatClient
  30. client = WeChatClient('appid', 'secret')
  31. ips = client.misc.get_wechat_callback_ips()
  32. """
  33. res = self._get(
  34. 'getcallbackip',
  35. result_processor=lambda x: x['ip_list']
  36. )
  37. return res
  38. def get_wechat_access_ips(self):
  39. """
  40. 获取微信服务器API接入入口地址列表
  41. :return: API接入入口地址列表
  42. 使用示例::
  43. from wechatpy import WeChatClient
  44. client = WeChatClient('appid', 'secret')
  45. ips = client.misc.get_wechat_access_ips()
  46. """
  47. res = self._get(
  48. 'get_api_domain_ip',
  49. result_processor=lambda x: x['ip_list']
  50. )
  51. return res