misc.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import, unicode_literals
  3. from 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_ips(self):
  25. """
  26. 获取微信服务器 IP 地址列表
  27. :return: IP 地址列表
  28. 使用示例::
  29. from wechatpy import WeChatClient
  30. client = WeChatClient('appid', 'secret')
  31. ips = client.misc.get_wechat_ips()
  32. """
  33. res = self._get(
  34. 'getcallbackip',
  35. result_processor=lambda x: x['ip_list']
  36. )
  37. return res