def check_sync(cls, session): """Check sync status.""" api_path = cls.api_url_template.format( schema=cls.schema, endpoint=cls.get_push_endpoint(session), url=cls.sync_check_url) wx_session_data = session.get_wx_session_data() wxuin = wx_session_data['wxuin'] wxsid = wx_session_data['wxsid'] skey = wx_session_data['skey'] sync_key = wx_session_data['sync_key'] sync_key_str = '|'.join('_'.join(map(str, ( k_pair['Key'], k_pair['Val']))) for k_pair in sync_key['List']) device_id = cls.get_device_id() params = { 'uin': wxuin, 'sid': wxsid, 'skey': skey, 'deviceid': device_id, '_': cls.get_client_msg_id(), 'synckey': sync_key_str} res = session.get(api_path, params=params, timeout=cls.middle_timeout) _logger.debug('check wechat session sync res %s', res.content) data = ParseWxRes.parse_sync_check(res.content) if not data or data['retcode'] != '0': if data['retcode'] == '1101': raise SessionExpiredError raise APIResponseError return data
def new_login_page(cls, session, login_api_path): """Create login page.""" now_timestamp = int(time.time()) params = {'scan': now_timestamp, 'version': 2, 'fun': 'new'} res = session.get( login_api_path, params=params, timeout=cls.middle_timeout) _logger.debug('wechat new login page res %s', res.content) data = ParseWxRes.parse_new_login_page(res.content) if data['ret'] != '0': raise LoginError(data['message']) return data
def get_qrcode_uuid(cls, session): """Get login qrcode uuid.""" api_path = cls.api_url_template.format( schema=cls.schema, endpoint=cls.get_login_endpoint(session), url=cls.qrcode_uuid_url) params = { 'appid': cls.appid, 'fun': 'new', '_': cls.get_client_msg_id()} res = session.get(api_path, params=params, timeout=cls.middle_timeout) data = ParseWxRes.parse_qrcode_uuid(res.content) return data['uuid']
def get_login_info(cls, session, uuid): """Get login authorize info.""" api_path = cls.api_url_template.format( schema=cls.schema, endpoint=cls.get_login_endpoint(session), url=cls.login_url) msg_id = cls.get_client_msg_id() params = { 'loginicon': 'true', 'uuid': uuid, 'tip': 0, '_': msg_id, 'r': msg_id // 1992} res = session.get(api_path, params=params, timeout=cls.middle_timeout) _logger.debug('wechat login info res %s', res.content) data = ParseWxRes.parse_login(res.content) return data