V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
vincenth520
V2EX  ›  Python

有人做过模拟微信登录吗,登陆成功无法获取到好友列表

  •  
  •   vincenth520 ·
    vincenth520 · 2017-08-21 17:19:29 +08:00 · 4939 次点击
    这是一个创建于 2412 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如题,登录发送消息什么的都能实现,但是就是获取不到好友列表,我也看了好几个 github 模拟登陆的,发现他们代码里面都有一个这个代码,不清楚什么作用,想问问是不是这个问题导致的

    https://github.com/littlecodersh/ItChat/blob/bbcb8173b611137a6fd6ac8a4d0a96cb8892fbd6/itchat/components/login.py#L157

    for indexUrl, detailedUrl in (
                ("wx2.qq.com"      , ("file.wx2.qq.com", "webpush.wx2.qq.com")),
                ("wx8.qq.com"      , ("file.wx8.qq.com", "webpush.wx8.qq.com")),
                ("qq.com"          , ("file.wx.qq.com", "webpush.wx.qq.com")),
                ("web2.wechat.com" , ("file.web2.wechat.com", "webpush.web2.wechat.com")),
                ("wechat.com"      , ("file.web.wechat.com", "webpush.web.wechat.com"))):
            fileUrl, syncUrl = ['https://%s/cgi-bin/mmwebwx-bin' % url for url in detailedUrl]
            if indexUrl in core.loginInfo['url']:
                core.loginInfo['fileUrl'], core.loginInfo['syncUrl'] = \
                    fileUrl, syncUrl
                break
    

    https://github.com/0x5e/wechat-deleted-friends/blob/b37f324f9a4df68c3799da5b7dc2559921293e9b/wdf.py#L151

            # push_uri 与 base_uri 对应关系(排名分先后)(就是这么奇葩..)
            services = [
                ('wx2.qq.com', 'webpush2.weixin.qq.com'),
                ('qq.com', 'webpush.weixin.qq.com'),
                ('web1.wechat.com', 'webpush1.wechat.com'),
                ('web2.wechat.com', 'webpush2.wechat.com'),
                ('wechat.com', 'webpush.wechat.com'),
                ('web1.wechatapp.com', 'webpush1.wechatapp.com'),
            ]
            push_uri = base_uri
            for (searchUrl, pushUrl) in services:
                if base_uri.find(searchUrl) >= 0:
                    push_uri = 'https://%s/cgi-bin/mmwebwx-bin' % pushUrl
                    break
    

    这两处代码有什么作用呢

    第 1 条附言  ·  2017-08-22 10:09:16 +08:00
    已经找到问题了,原来是 cookie 没处理好。。。但是居然能够发消息。。。真神奇
    4 条回复    2017-08-22 21:30:07 +08:00
    lsido
        1
    lsido  
       2017-08-21 23:36:16 +08:00
    itchat 里有个 get_friends 方法用于获取好友列表

    itchat.get_friends()

    没有看源码吗,还是研究一下
    caspartse
        2
    caspartse  
       2017-08-22 06:21:31 +08:00
    通讯录的接口应该是 https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgetcontact。
    早前写了个简单的通讯录导出工具,好像还能用,可以参考下 http://kagent.applinzi.com/wx
    vincenth520
        3
    vincenth520  
    OP
       2017-08-22 09:04:07 +08:00
    @lsido 看了,很神奇,其他都没问题,就是获取好友为空
    lsido
        4
    lsido  
       2017-08-22 21:30:07 +08:00
    @vincenth520 用 get_friends 方法也是空? 调试一下看看
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2664 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 15:25 · PVG 23:25 · LAX 08:25 · JFK 11:25
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.