Пример #1
0
    def _login(self, request):
        '''
        确认登陆之后,进行登陆
        '''
        count = 0
        while 1:
            if self.login_info == {} or not self.login_info:
                wx_login = Login(self.web_request_dict,
                                 redirect_uri=self.redirect_uri,
                                 is_text=self.is_text)
                self.login_info = wx_login.get_logininfo()
                self.status = 200
            else:
                self.status = self._check_login(request)
            print(self.status)

            if self.status == 222 or self.status >= 400:
                if self.status == 222:
                    self.friend_dict = self._get_friend_dict()
                    self.session_info_dict['login_stamptime'] = int(
                        time.time())
                break
            else:
                time.sleep(5)

            if count == 5:
                break
            count += 1

        self.session_info_dict['status'] = self.status
        self.session_info_dict['login_info'] = self.login_info
Пример #2
0
def receive_func(login_info, web_request_base_dict):
    wx_friend = Get_Friend(login_info, web_request_base_dict)
    friend_list = wx_friend.get_friend_list()

    while 1:
        try:
            wx_receive = Receive_Msg(login_info, web_request_base_dict,
                                     friend_list)
            wx_receive.receive()
            get_friend = Get_Friend(login_info,
                                    web_request_base_dict,
                                    friend_list=friend_list)
            friend_list = get_friend.update_friend_list()

            if int(time.time()) % 120 <= 5:
                try:
                    login = Login(web_request_base_dict, login_info=login_info)
                    check_login = login.check_login()
                    run_time = (int(time.time()) - int(starttime)) // 60
                    if check_login['Ret'] == 0:
                        print('登陆中,已经登陆了' + str(run_time) + '分钟')
                    else:
                        print('微信号被退出,保持登陆' + str(run_time) + '分钟,请重新执行程序')
                        print(check_login)
                        print(
                            time.strftime('%Y-%m-%d %H:%M:%S',
                                          time.localtime()))
                        break
                        exit(0)
                except:
                    pass
        except:
            pass

        time.sleep(5)
Пример #3
0
def checklogin_func(web_request_base_dict, login_info):
    while 1:
        try:
            login = Login(web_request_base_dict, login_info=login_info)
            check_login = login.check_login()
            if check_login['Ret'] == 0:
                print('OK')
                print(time.strftime(' %Y-%m-%d %H:%M:%S', time.localtime()))
            else:
                print('微信号被退出,请重新登录!')
                print(check_login)
                print(time.strftime(' %Y-%m-%d %H:%M:%S', time.localtime()))
                exit(0)
        except:
            pass

        time.sleep(60)
Пример #4
0
    def _check_login(self, request):
        '''
        检查是否保持登陆状态
        '''
        wx_login = Login(self.web_request_dict,
                         login_info=self.login_info,
                         is_text=self.is_text)
        status_dict = wx_login.check_login()
        status = status_dict['Ret']
        if status == 0:
            status = 222
            # 登陆成功状态
        elif status == 1101:
            status = 402
        elif status == 1205:
            status = 404
        else:
            status = 401

        return status
Пример #5
0
    def _init(self, request):
        '''
        确认登陆之后,进行登陆
        '''
        count = 0
        while 1:
            self.login_info = self.session_info_dict['login_info']
            if self.login_info == {} or not self.login_info:
                wx_login = Login(self.session_info_dict)
                self.session_info_dict = wx_login.init_login()
            else:
                wx_login = Login(self.session_info_dict)
                self.session_info_dict = wx_login.check_login()

            status = self.session_info_dict['status']
            if status == 222 or self.status >= 400 or count == 5:
                if status == 222:
                    self._get_friend_info()
                    self.session_info_dict['login_stamptime'] = int(
                        time.time())
                break
            else:
                time.sleep(5)

            count += 1
Пример #6
0
    def _checklogin(self):
        '''
        检查单个微信号信息
        '''
        try:
            login = Login(self.web_request_base_dict,
                          login_info=self.login_info)
            check_login = login.check_login()
            login_time = (int(time.time()) - int(self.login_stamptime)) // 60
            if login_time >= 60 * 24 * 7:
                login_time = 0
            if check_login['Ret'] == 0:
                print('登陆中,已经登陆了' + str(login_time) + '分钟')
            else:
                print('微信号被退出,保持登陆' + str(login_time) + '分钟,请重新执行程序')
                print(check_login)
                print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))
                cronwx_clearsession(uuid=self.uuid)
        except:
            pass

        exit(0)
Пример #7
0
    def _checklogin(self, request):
        '''
        检查登陆状态
        '''
        wx_login = Login(self.session_info_dict)
        self.session_info_dict = wx_login.check_login()
        status = self.session_info_dict['status']

        if status == 222:
            self._get_friend_info()
            if request.method == 'POST':
                try:
                    tousername = request.POST['username']
                    try:
                        # nowtime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
                        content = request.POST['content']
                        content = 'lykchat web页面推送:' + content
                        self.send_result = self._send_msg(tousername, content)
                    except:
                        self.send_result = '<div class="alert alert-danger text-center">发送内容为空</div>'
                except:
                    self.send_result = '<div class="alert alert-danger text-center">发送内容为空</div>'
            else:
                self.send_result = ''
Пример #8
0
    def check_login(self, request):
        '''
        检查所有微信号登陆状态
        '''
        request_dict = {}
        for key in ['username', 'pwd']:
            # post或者get字段是否正确
            try:
                if request.method == 'GET':
                    request_dict[key] = request.GET[key]
                else:
                    request_dict[key] = request.POST[key]
            except:
                send_result = '账号或者密码不能为空'

        try:
            # 验证用户的接口密码是否正确
            username = request_dict['username']
            pwd = request_dict['pwd']
            password = self.user_mess_dict[username]['interface_pwd']

            if pwd != password:
                send_result = {
                    'username': username,
                    'check_time': int(time.time()),
                    'login_time': '',
                    'login_min': '',
                    'alias': '',
                    'nickname': '',
                    'longtime': '0',
                    'status': '账号或者密码错误'
                }
            else:
                send_result = {}
        except:
            send_result = {
                'username': '',
                'check_time': int(time.time()),
                'login_min': '',
                'login_time': '',
                'alias': '',
                'nickname': '',
                'status': '账号或者密码错误'
            }

        if send_result == {}:
            from library.config.wechat import login_status_code_dict
            op_info = Manage_Logininfo()
            session_info_dict = op_info.get_info(username)
            status = session_info_dict['status']
            if status == 222:
                wx_login = Login(session_info_dict)
                session_info_dict = wx_login.check_login()
                status = session_info_dict['status']

                op_info.update(session_info_dict)
                request.session['username'] = username

                login_stamptime = session_info_dict['login_stamptime']
                if login_stamptime and login_stamptime != '':
                    login_min = (int(time.time()) - int(login_stamptime)) // 60
                else:
                    login_min = 0
                if login_min > 60 * 24 * 365:
                    login_min = 0

                if login_min >= 60 * 24:
                    login_min = str(login_min // 60 // 24) + '天' + str(
                        login_min // 60 % 24) + '小时' + str(
                            login_min % 60) + '分钟'
                elif login_min >= 60:
                    login_min = str(login_min // 60) + '小时' + str(
                        login_min % 60) + '分钟'
                else:
                    login_min = str(login_min) + '分钟'

                send_result = {
                    'username': username,
                    'check_time': int(time.time()),
                    'login_time': session_info_dict['login_stamptime'],
                    'login_min': login_min,
                    'alias': session_info_dict['alias'],
                    'nickname': session_info_dict['nickname'],
                    'status': login_status_code_dict[status]['descript']
                }
            else:
                send_result = {
                    'username': username,
                    'check_time': int(time.time()),
                    'login_min': '',
                    'login_time': '',
                    'alias': '',
                    'nickname': '',
                    'status': login_status_code_dict[status]['descript']
                }

        return render(request, 'result.html', {'result': send_result})
Пример #9
0
status = -1
ready = Ready()
(uuid, web_request_base_dict) = ready.return_basicinfo_dict()
# web请求基础参数

while 1:
    if status == 200:
        break
    else:
        (status, redirect_uri) = ready.check_status()
        time.sleep(5)
# 以上操作仅仅登陆,不会获取微信号任何信息,在电脑端或者web页面登陆不会退出
# 但是下一步就不同了

login = Login(web_request_base_dict, redirect_uri=redirect_uri)
login_info = login.get_logininfo()

starttime = int(time.time())
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))


def receive_func(login_info, web_request_base_dict):
    wx_friend = Get_Friend(login_info, web_request_base_dict)
    friend_list = wx_friend.get_friend_list()

    while 1:
        try:
            wx_receive = Receive_Msg(login_info, web_request_base_dict,
                                     friend_list)
            wx_receive.receive()