Beispiel #1
0
def addcookies(req):
    ck = cookies(req)
    for nm in ck.codec:
        req.ohead.add("Set-Cookie", ck.codec[nm].OutputString())
Beispiel #2
0
def get(req, name, default=None):
    return cookies(req).get(name, default)
Beispiel #3
0
def add(req, name, value, **kw):
    cookies(req).add(name, value, **kw)
Beispiel #4
0
    def login(self,acc,pwd,vcode='',vcodestr=''):

        #url = 'https://passport.baidu.com/v2/api/?login' # 抄袭不如自己搞一遍
        url = 'http://wappass.baidu.com/wp/api/login'
        pubkey , rsakey = self._get_publickey()

        #print pubkey
        #print rsakey
        key = rsa.PublicKey.load_pkcs1_openssl_pem(pubkey)
        password_rsaed = base64.b64encode(rsa.encrypt(pwd, key))

        data = {}
        data[u'loginInitType']='0'
        data[u'logLoginType']= 'sdk_login'
        data[u'regLink'] = '1'
        data[u'loginLink'] = '1'
        data[u'isPhone'] = '0'
        data[u'dialogVcodestr'] = '0'
        data[u'code'] = ''
        data[u'gid']=GID
        data[u'countrycode']=''
        data[u'clientfrom']='native'
        data[u'regtype']='1'
        data[u'password']=password_rsaed
        # 可以传空
        data[u'verifycode'] = vcode
        data[u'client']='ios'
        data[u'action']='login'
        data[u'adapter']='1'
        data[u'dialogVerifyCode']=''
        data[u'servertime'] = '4cd9f60139'
        data[u'tpl']='tb'
        data[u'dialogVcodesign'] = ''
        data[u'smsLoginLink'] = '1'
        data[u'v'] = str(int(time.time()))
        data[u'login_share_strategy'] = 'silent'
        data[u'loginmerge']='1'
        data[u'username']=acc

        # start login
        data=http.request(url,data)
        data=json.loads(data)

        #err_no,code_string = self._check_login_error(data)
        err_no = data[u'errInfo'][u'no']
        err_msg = data[u'errInfo'][u'msg']
        print err_no + err_msg
        '''
        if data[u'errInfo'][u'no']=='0':
            #login success & need save bduss
            bduss=data['user']['BDUSS'].encode('utf-8')
            bduss = 'BDUSS='+bduss.decode()
            self.__writebduss__(bduss)
        '''
        '''
        if data[u'errInfo'][u'no']=='500001':
            url = 'http://wappass.baidu.com/cgi-bin/genimage?'+data[u'data'][u'codeString'] + '&v='+str(int(time.time()*1000))
            http.download(url,cur_dir()+u'/',u'vcode.jpg')
            vc = raw_input('请输入验证码:')
            return self.login(baiduUtf(acc),base64.b64encode(pwd.encode('utf-8')).decode(),vc,data[u'data'][u'codeString'])
        '''
        # 是否需要验证码
        '''
        if err_no=='257' or err_no=='6' :
            url = 'https://passport.baidu.com/cgi-bin/genimage?'+ code_string + '&v='+str(int(time.time()*1000))
            http.download(url,cur_dir()+u'/',u'vcode.jpg')
            vc = raw_input('请输入验证码:')
            self.login(acc,pwd,vc,code_string)
        '''
        if err_no=='0':
            # bduss = None
            for item in http.cookies():
                if item.name == 'BDUSS':
                    self.bduss = item.value
                if item.name == 'BAIDUID':
                    self.baiduid = item.value
            #self.bdauth = 'BAIDUID=' + self.baiduid + '; BDUSS=' + self.bduss
            #print self.bdauth
            self.__writebduss__(self.bduss,self.baiduid)
            print 'relogin access!'
Beispiel #5
0
    def login(self,acc,pwd,vcode='',vcodestr=''):

        url = 'https://passport.baidu.com/v2/api/?login'
        pubkey , rsakey = self._get_publickey()

        #print pubkey
        #print rsakey
        key = rsa.PublicKey.load_pkcs1_openssl_pem(pubkey)
        password_rsaed = base64.b64encode(rsa.encrypt(pwd, key))

        data = {}
        data[u'staticpage'] = 'https://passport.baidu.com/static/passpc-account/html/v3Jump.html'
        data[u'charset'] = 'UTF-8'
        data[u'token'] = self.token
        data[u'tpl']='tb'
        data[u'subpro'] = ''
        data[u'apiver'] = 'v3'
        data[u'tt']=str(int(time.time()))
        data[u'codestring']=vcodestr
        data[u'safeflg'] = 0
        data[u'u']='https://passport.baidu.com/'
        data[u'isPhone'] = ''
        data[u'detect']= 1
        data[u'gid']='6A3375C-5CE5-4696-A8C2-8BBE62516FAF'
        data[u'quick_user']=0
        data[u'logintype']='basicLogin'
        data[u'logLoginType']= 'pc_loginBasic'
        data[u'idc']=''
        data[u'loginmerge']='true'
        data[u'username']=acc
        data[u'password']=password_rsaed
        data[u'verifycode'] = vcode
        data[u'rsakey']=rsakey
        data[u'crypttype']=12
        data[u'countrycode']=''
        data[u'callback']=0

        # start login
        data=http.request(url,data)
        #data=json.loads(data)
        err_no,code_string = self._check_login_error(data)
        '''
        if data[u'errInfo'][u'no']=='0':
            #login success & need save bduss
            bduss=data['user']['BDUSS'].encode('utf-8')
            bduss = 'BDUSS='+bduss.decode()
            self.__writebduss__(bduss)
        '''
        '''
        if data[u'errInfo'][u'no']=='500001':
            url = 'http://wappass.baidu.com/cgi-bin/genimage?'+data[u'data'][u'codeString'] + '&v='+str(int(time.time()*1000))
            http.download(url,cur_dir()+u'/',u'vcode.jpg')
            vc = raw_input('请输入验证码:')
            return self.login(baiduUtf(acc),base64.b64encode(pwd.encode('utf-8')).decode(),vc,data[u'data'][u'codeString'])
        '''
        # 是否需要验证码
        if err_no=='257' or err_no=='6' :
            url = 'https://passport.baidu.com/cgi-bin/genimage?'+ code_string + '&v='+str(int(time.time()*1000))
            http.download(url,cur_dir()+u'/',u'vcode.jpg')
            vc = raw_input('请输入验证码:')
            self.login(acc,pwd,vc,code_string)
        if err_no=='0':
            # bduss = None
            for item in http.cookies():
                if item.name == 'BDUSS':
                    self.bduss = item.value
                if item.name == 'BAIDUID':
                    self.baiduid = item.value
            #self.bdauth = 'BAIDUID=' + self.baiduid + '; BDUSS=' + self.bduss
            #print self.bdauth
            self.__writebduss__(self.bduss,self.baiduid)
            print 'relogin access!'
Beispiel #6
0
def addcookies(req):
    ck = cookies(req)
    for nm in ck.codec:
        req.ohead.add("Set-Cookie", ck.codec[nm].OutputString())
Beispiel #7
0
def add(req, name, value, **kw):
    cookies(req).add(name, value, **kw)
Beispiel #8
0
def get(req, name, default=None):
    return cookies(req).get(name, default)