WeChatAssistant icon indicating copy to clipboard operation
WeChatAssistant copied to clipboard

网页版本

Open chenqiuyuan opened this issue 7 years ago • 16 comments

这个功能我觉得作为Windows程序并不方便,有没有兴趣做成一个网页?我最近玩程序在看django

chenqiuyuan avatar Nov 22 '17 09:11 chenqiuyuan

可以呀,欢迎fork然后开一个网页的branch然后自己先试试

SLiNv avatar Nov 22 '17 12:11 SLiNv

@chenqiuyuan 欢迎~ 记得做好测试 ~

ZKeeer avatar Nov 22 '17 15:11 ZKeeer

想的主要实现逻辑是在网页上显示二维码登录,然后多开几个线程就能在后台并发运行了,但是今天看了半天源码发现这是itchat里面封装的,定位到了具体的位置,需要更改itchat的源码,把登录的流程分开来。先mark之后有空了继续做。

chenqiuyuan avatar Nov 29 '17 14:11 chenqiuyuan

我觉得可以不用这么麻烦,每个登陆是个session,itchat只是当library/module来用。微信登出之后清空聊天信息和文件就行了

SLiNv avatar Nov 29 '17 16:11 SLiNv

主要要用在网页上的话需要网页的逻辑,进入网页-显示二维码-登录-显示成功-开始运行这几个流程。二维码和登录是耦合在itchat里面的

chenqiuyuan avatar Nov 29 '17 17:11 chenqiuyuan

通过API,我们可以调用不同步骤的function。这样每个步骤都是可以分开的

进入网页 -- Django View -->调用 itchat.login() --> 把二维码显示到网页上,

itchat.check_login() 检测登陆状态

def check_login(self, uuid=None):
    ''' check login status
        for options:
            - uuid: if uuid is not set, latest uuid you fetched will be used
        for return values:
            - a string will be returned
            - for meaning of return values
                - 200: log in successfully
                - 201: waiting for press confirm
                - 408: uuid timed out
                - 0  : unknown error
        for processing:
            - syncUrl and fileUrl is set
            - BaseRequest is set
        blocks until reaches any of above status
        it is defined in components/login.py
    '''
    raise NotImplementedError()

然后剩下的其他操作可以参考itchat的源代码 components/register.py等其他文件。Since itchat开放了不同步骤的API所以我觉得不需要修改itchat的源码。

SLiNv avatar Nov 30 '17 00:11 SLiNv

@chenqiuyuan @SLiNv 我要来打击各位大佬了。我从多方得到消息,微信为整治机器人泛滥,要逐步关闭微信网页版,换句话说itchat没多久可能不能用了。开发工作要不要先停停

ZKeeer avatar Nov 30 '17 02:11 ZKeeer

这么可怕的吗,不过应该不至于吧,毕竟微信网页版需求量那么大,哪怕封禁到时候itchat还是会有相应修改吧

chenqiuyuan avatar Nov 30 '17 02:11 chenqiuyuan

@SLiNv 我换了个思路,开了一个线程来获得二维码登录,这样就不会阻塞登录界面的渲染了。已经写好了一个本地测试的版本,现在在我的分支里面,在WebVersion中的weixin下面使用python manage.py runserver就能启动,访问地址是本地127.0.0.1:8000.现在碰到的问题是windows版本的本地测试没问题,我想放在服务器上,就会报错,服务器是linux,实现逻辑一模一样,只是把cmdQR关了。

chenqiuyuan avatar Nov 30 '17 02:11 chenqiuyuan

报错信息是这个 Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner self.run() File "/usr/lib/python2.7/threading.py", line 754, in run self.__target(*self.__args, **self.__kwargs) File "/root/qiuyuan/WebVersion/weixin/revo/main.py", line 165, in run itchat.auto_login(hotReload=True, picDir=dir) File "/usr/local/lib/python2.7/dist-packages/itchat/components/register.py", line 29, in auto_login loginCallback=loginCallback, exitCallback=exitCallback): File "/usr/local/lib/python2.7/dist-packages/itchat/components/hotreload.py", line 54, in load_login_status self.loginInfo['User'] = templates.User(self.loginInfo['User']) KeyError: 'User'

chenqiuyuan avatar Nov 30 '17 02:11 chenqiuyuan

一样的代码win上面没有问题,python3.5也已经尝试过了

chenqiuyuan avatar Nov 30 '17 02:11 chenqiuyuan

啊,我搞定了,重写了itchat源码,把linux自动开二维码的关了,网址在这里120.79.8.4:8000,现在登个浏览器就可以防撤回了。不过还不能并发使用。。。就当练练手玩,有空再写一个并发使用的版本。

chenqiuyuan avatar Nov 30 '17 03:11 chenqiuyuan

@chenqiuyuan 那个,itchat不是本身支持用户多开嘛?

SLiNv avatar Nov 30 '17 18:11 SLiNv

@ZKeeer 完全关停网页版那就结束了233,如果是修改登陆机制和调整API的话itchat应该会重新抓包分析然后更新…

SLiNv avatar Nov 30 '17 18:11 SLiNv

@SLiNv 是网页的设计问题。。。需要并发多个线程和数据库,这样就可以作为一个服务让很多人用了。但是很麻烦的样子

chenqiuyuan avatar Dec 05 '17 01:12 chenqiuyuan

@chenqiuyuan 我现在用三个脚本简单实现了Web登录并实现状态监控,至于撤回消息可以用数据库传回去

这是视图函数中的一部分,websocket通信 ` @require_websocket def wlp(request): WebSocket=request.websocket isLogging = True while isLogging: uuid = itchat.get_QRuuid() while uuid is None: uuid = itchat.get_QRuuid();time.sleep(1) qr = itchat.get_QR(enableCmdQR=True) base64qr="data:image/png;base64," + base64.b64encode(qr.getvalue()).decode('utf-8') qrjson={"m":1,"qr":base64qr} WebSocket.send(json.dumps(qrjson).encode('utf-8')) isLoggedIn = False while not isLoggedIn: WebSocket.send(json.dumps({"m":3}).encode('utf-8')) #print("Heartbeat#") status = itchat.check_login(uuid) if status == '200': isLoggedIn = True elif status == '201': if isLoggedIn is not None: cfjson={"m":2} WebSocket.send(json.dumps(cfjson).encode('utf-8')) #logger.info('Please press confirm on your phone.') isLoggedIn = None elif status != '408': break if isLoggedIn: break elif isLogging: WebSocket.send(json.dumps({"m":3}).encode('utf-8')) #print("Heartbeat#") pass #logger.info('Log in time out, reloading QR code.') #logger.info('Loading the contact, this may take a little while.') okjson={"m":6} WebSocket.send(json.dumps(okjson).encode('utf-8')) itchat.web_init() itchat.show_mobile_login() itchat.get_contact(True)

XAS-712 avatar Aug 05 '18 10:08 XAS-712