Esempio n. 1
0
 def _login_check(self, token, account):
     '''
     登陆检查,访问该页面主要是为了获取cookie
     '''
     cbs = 'bd__cbs__%s' % util.random_hex_str(6)
     url = 'https://passport.baidu.com/v2/api/?logincheck'
     query = [('token', token), ('tpl', 'netdisk'), ('apiver', 'v3'),
              ('tt', util.timstamp()), ('username', account),
              ('isphone', 'false'), ('callback', cbs)]
     self.execute_request(url, query)
Esempio n. 2
0
 def _do_login(self, account, password, token, key_info):
     url = 'https://passport.baidu.com/v2/api/?login'
     form = {
         'staticpage':
         'http://pan.baidu.com/res/static/thirdparty/pass_v3_jump.html',
         'charset': 'utf-8',
         'tpl': 'netdisk',
         'subpro': '',
         'apiver': 'v3',
         'tt': util.timstamp(),
         'codestring': '',
         'safeflg': '0',
         'u': 'http://pan.baidu.com/',
         'isPhone': 'false',
         'quick_user': '******',
         'logintype': 'basicLogin',
         'logLoginType': 'pc_loginBasic',
         'loginmerge': 'true',
         'verifycode': '',
         'mem_pass': '******',
         'crypttype': '12',
         'ppui_logintime': random.randint(5000, 10000),
         'callback': 'parent.bd__cbs__%s' % util.random_hex_str(6),
         'username': account,
         'token': token,
         'rsakey': key_info['key']
     }
     # 使用rsa加密密码
     pubkey = key_info['pubkey'].replace('-----BEGIN PUBLIC KEY-----\n',
                                         '').replace(
                                             '\n-----END PUBLIC KEY-----',
                                             '')
     pubkey = rsa.key.PublicKey.load_pkcs1_openssl_der(
         base64.decodestring(pubkey))
     form['password'] = base64.b64encode(rsa.encrypt(password, pubkey))
     # 发送登陆请求
     resp = self.execute_request(url, None, form)
     # 解析登陆结果
     body = resp.read()
     m = re.search('err_no=(\d+)&', body)
     if m is not None:
         err_no = int(m.group(1))
         # err_no=18 表示需要手机认证,这个错误目前可忽略
         if err_no != 0 and err_no != 18:
             raise APIException('login', err_no)
     else:
         raise APIException('login', -1)
     _logger.debug('login successed!')
Esempio n. 3
0
 def _get_public_key(self, token):
     '''
     获取加密密码用的rsa公钥
     '''
     cbs = 'bd__cbs__%s' % util.random_hex_str(6)
     url = 'https://passport.baidu.com/v2/getpublickey'
     query = [
              ('token', token),
              ('tpl', 'netdisk'),
              ('apiver', 'v3'),
              ('tt', util.timstamp()),
              ('callback', cbs),
              ]
     resp = self.execute_request(url, query)
     result = (resp.read()[len(cbs)+1:-1]).replace('\'', '"')
     return json.loads(result)
Esempio n. 4
0
 def _login_check(self, token, account):
     '''
     登陆检查,访问该页面主要是为了获取cookie
     '''
     cbs = 'bd__cbs__%s' % util.random_hex_str(6)
     url = 'https://passport.baidu.com/v2/api/?logincheck'
     query = [
              ('token', token),
              ('tpl', 'netdisk'),
              ('apiver', 'v3'),
              ('tt', util.timstamp()),
              ('username', account),
              ('isphone', 'false'),
              ('callback', cbs)
              ]
     self.execute_request(url, query)
Esempio n. 5
0
 def _get_public_key(self, token):
     '''
     获取加密密码用的rsa公钥
     '''
     cbs = 'bd__cbs__%s' % util.random_hex_str(6)
     url = 'https://passport.baidu.com/v2/getpublickey'
     query = [
         ('token', token),
         ('tpl', 'netdisk'),
         ('apiver', 'v3'),
         ('tt', util.timstamp()),
         ('callback', cbs),
     ]
     resp = self.execute_request(url, query)
     result = (resp.read()[len(cbs) + 1:-1]).replace('\'', '"')
     return json.loads(result)
Esempio n. 6
0
 def _get_login_token(self):
     '''
     获取登陆用token
     '''
     # 需要先访问网盘首页,获得一个cookie
     self.execute_request('http://pan.baidu.com/')
     # 请求token
     cbs = 'bd__cbs__%s' % util.random_hex_str(6)
     url = 'https://passport.baidu.com/v2/api/?getapi'
     query = [('tpl', 'netdisk'), ('apiver', 'v3'), ('tt', util.timstamp()),
              ('class', 'login'), ('logintype', 'basicLogin'),
              ('callback', cbs)]
     resp = self.execute_request(url, query)
     result = (resp.read()[len(cbs) + 1:-1]).replace('\'', '"')
     result = json.loads(result)
     return result['data']['token']
Esempio n. 7
0
 def _do_login(self, account, password, token, key_info):
     url = 'https://passport.baidu.com/v2/api/?login'
     form = {
             'staticpage' : 'http://pan.baidu.com/res/static/thirdparty/pass_v3_jump.html',
             'charset' : 'utf-8',
             'tpl' : 'netdisk',
             'subpro' : '',
             'apiver' : 'v3',
             'tt' : util.timstamp(),
             'codestring' : '',
             'safeflg' : '0',
             'u' : 'http://pan.baidu.com/',
             'isPhone' : 'false',
             'quick_user' : '0',
             'logintype' : 'basicLogin',
             'logLoginType' : 'pc_loginBasic',
             'loginmerge' : 'true',
             'verifycode' : '',
             'mem_pass' : 'on',
             'crypttype' : '12',
             'ppui_logintime' : random.randint(5000, 10000),
             'callback' : 'parent.bd__cbs__%s' % util.random_hex_str(6),
             'username' : account,
             'token' : token,
             'rsakey' : key_info['key']
             }
     # 使用rsa加密密码
     pubkey = key_info['pubkey'].replace('-----BEGIN PUBLIC KEY-----\n', '').replace('\n-----END PUBLIC KEY-----', '')
     pubkey = rsa.key.PublicKey.load_pkcs1_openssl_der(base64.decodestring(pubkey))
     form['password'] = base64.b64encode(rsa.encrypt(password, pubkey))
     # 发送登陆请求
     resp = self.execute_request(url, None, form)
     # 解析登陆结果
     body = resp.read()
     m = re.search('err_no=(\d+)&', body)
     if m is not None:
         err_no = int(m.group(1))
         # err_no=18 表示需要手机认证,这个错误目前可忽略
         if err_no != 0 and err_no != 18:
             raise APIException('login', err_no)
     else:
         raise APIException('login', -1)
     _logger.debug('login successed!')
Esempio n. 8
0
 def _get_login_token(self):
     '''
     获取登陆用token
     '''
     # 需要先访问网盘首页,获得一个cookie
     self.execute_request('http://pan.baidu.com/')
     # 请求token
     cbs = 'bd__cbs__%s' % util.random_hex_str(6)
     url = 'https://passport.baidu.com/v2/api/?getapi'
     query = [
              ('tpl', 'netdisk'),
              ('apiver', 'v3'),
              ('tt', util.timstamp()),
              ('class', 'login'),
              ('logintype', 'basicLogin'),
              ('callback', cbs)
              ]
     resp = self.execute_request(url, query)
     result = (resp.read()[len(cbs)+1:-1]).replace('\'', '"')
     result = json.loads(result)
     return result['data']['token']