作者 陈俊学

2.3.7

增加解封具体方式
@@ -4,5 +4,5 @@ SERVER: @@ -4,5 +4,5 @@ SERVER:
4 reconnect_interval: 3 4 reconnect_interval: 3
5 5
6 VERSION: 6 VERSION:
7 - code: 126  
8 - name: 2.3.6  
  7 + code: 127
  8 + name: 2.3.7
@@ -98,7 +98,7 @@ class CallBack(): @@ -98,7 +98,7 @@ class CallBack():
98 body={'event': 'onUpdateMyInfo', 'info': client.info()} 98 body={'event': 'onUpdateMyInfo', 'info': client.info()}
99 ) 99 )
100 100
101 - def onLoggingError(self, email, reason): 101 + def onLoggingError(self, email, reason, verification_method: list):
102 u = models.UserList.get(email=email) 102 u = models.UserList.get(email=email)
103 if u: u.set(status=common.Status.FAILED, token=None) 103 if u: u.set(status=common.Status.FAILED, token=None)
104 104
@@ -106,7 +106,7 @@ class CallBack(): @@ -106,7 +106,7 @@ class CallBack():
106 self._notify_( 106 self._notify_(
107 type_="account", 107 type_="account",
108 client=client, 108 client=client,
109 - body={'event': 'onLoginFailed', 'reason': reason} 109 + body={'event': 'onLoginFailed', 'reason': reason, 'verification_method': verification_method}
110 ) 110 )
111 111
112 def onLogout(self, client): 112 def onLogout(self, client):
@@ -29,6 +29,7 @@ from lib.facebook import FacebookClient @@ -29,6 +29,7 @@ from lib.facebook import FacebookClient
29 from lib.ttl_cache import lru_cache 29 from lib.ttl_cache import lru_cache
30 from lib.websock import Client 30 from lib.websock import Client
31 from utils import parameter, system_info 31 from utils import parameter, system_info
  32 +from utils.cache import cache
32 33
33 log = logging.getLogger(__name__) 34 log = logging.getLogger(__name__)
34 tostr = lambda x: (x) 35 tostr = lambda x: (x)
@@ -131,7 +132,9 @@ class Monitor(callback.CallBack): @@ -131,7 +132,9 @@ class Monitor(callback.CallBack):
131 self.onLoggedIn(client) 132 self.onLoggedIn(client)
132 return client.info() 133 return client.info()
133 except Exception as err: 134 except Exception as err:
134 - self.onLoggingError(email, str(err)) 135 + verification_method = cache.get(f'{email}:verification_method', [])
  136 + cache.delete(f'{email}:verification_method')
  137 + self.onLoggingError(email, str(err), verification_method)
135 raise err 138 raise err
136 139
137 def close_selenium(self, email, browser): 140 def close_selenium(self, email, browser):
@@ -17,6 +17,7 @@ from requests import Session as Session_ @@ -17,6 +17,7 @@ from requests import Session as Session_
17 17
18 from lib import common, graph 18 from lib import common, graph
19 from utils import parse_html, encpass 19 from utils import parse_html, encpass
  20 +from utils.cache import cache
20 21
21 22
22 class Session(Session_): 23 class Session(Session_):
@@ -37,7 +38,9 @@ class Session(Session_): @@ -37,7 +38,9 @@ class Session(Session_):
37 content = res.text 38 content = res.text
38 set_cookie = res.headers.get('Set-Cookie', None) 39 set_cookie = res.headers.get('Set-Cookie', None)
39 if 'checkpoint' in res.url: 40 if 'checkpoint' in res.url:
40 - # self.get_deal_lock_method(int(kwargs['data']['jazoest']), kwargs['data']['lsd']) 41 + way_list = self.get_verification_method(**kwargs)
  42 + email = kwargs['data']['email']
  43 + cache.set(key=f'{email}:verification_method', value=way_list)
41 raise FBchatUserError('账号被封锁:' + parse_html.checkpoint_text(content)) 44 raise FBchatUserError('账号被封锁:' + parse_html.checkpoint_text(content))
42 elif 'ServerRedirect' in content and self._match_redirect_(content) == '\\/checkpoint\\/block\\/': 45 elif 'ServerRedirect' in content and self._match_redirect_(content) == '\\/checkpoint\\/block\\/':
43 raise FBchatUserError('账号被封锁') 46 raise FBchatUserError('账号被封锁')
@@ -61,7 +64,7 @@ class Session(Session_): @@ -61,7 +64,7 @@ class Session(Session_):
61 hasattr(self, 'logout_call') and self.logout_call() 64 hasattr(self, 'logout_call') and self.logout_call()
62 raise 65 raise
63 66
64 - def get_init_lock_args(self, jazoest: str, lsd: str): 67 + def verification_init(self, **kwargs):
65 """ 68 """
66 获取解封方式 所需要参数 69 获取解封方式 所需要参数
67 """ 70 """
@@ -73,26 +76,27 @@ class Session(Session_): @@ -73,26 +76,27 @@ class Session(Session_):
73 'modules': 'FormSubmit', 76 'modules': 'FormSubmit',
74 "dpr": 2, 77 "dpr": 2,
75 "fb_dtsg_ag": fb_dtsg_ag, 78 "fb_dtsg_ag": fb_dtsg_ag,
76 - "jazoest": jazoest, 79 + "jazoest": int(kwargs['data']['jazoest']),
77 "nh": nh, 80 "nh": nh,
78 - "lsd": lsd 81 + "lsd": kwargs['data']['lsd']
79 } 82 }
80 return params 83 return params
81 84
82 - def get_deal_lock_method(self, jazoest, lsd):  
83 - params = self.get_init_lock_args(jazoest, lsd)  
84 - res = super().request('GET', 'https://www.facebook.com/ajax/bootloader-endpoint',  
85 - params=params)  
86 -  
87 - res = super().request('POST', 'https://www.facebook.com/cookie/consent/',  
88 - params=params)  
89 - 85 + def get_verification_method(self, **kwargs):
  86 + """
  87 + 获取解封方法
  88 + """
  89 + try:
  90 + params = self.verification_init(**kwargs)
  91 + # res = super().request('POST', 'https://www.facebook.com/cookie/consent/',params=params)
  92 + # res = super().request('GET', 'https://www.facebook.com/ajax/bootloader-endpoint',params=params)
90 params['submit[Continue]'] = 'Continue' 93 params['submit[Continue]'] = 'Continue'
91 - res = super().request('POST',  
92 - 'https://www.facebook.com/checkpoint/async?next'  
93 - , data=params  
94 - )  
95 - pass 94 + res = super().request('POST', 'https://www.facebook.com/checkpoint/async?next', data=params)
  95 + res = super().request('GET', 'https://zh-cn.facebook.com/checkpoint/?next')
  96 + way_list = parse_html.get_verification_method(res.text)
  97 + return way_list # 解封方式在里面
  98 + except:
  99 + return []
96 100
97 101
98 class PCState(State): 102 class PCState(State):
@@ -162,7 +166,7 @@ class PCState(State): @@ -162,7 +166,7 @@ class PCState(State):
162 'lgnjs': int(time.time()), 166 'lgnjs': int(time.time()),
163 'timezone': '-480' 167 'timezone': '-480'
164 }) 168 })
165 - r = session.post('https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110', 169 + r = session.post('https://zh-cn.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110',
166 data=data) 170 data=data)
167 setCookie = r.headers.get('Set-Cookie') or '' 171 setCookie = r.headers.get('Set-Cookie') or ''
168 172
@@ -545,11 +545,13 @@ def checkpoint_text(text): @@ -545,11 +545,13 @@ def checkpoint_text(text):
545 try: 545 try:
546 b = bs4.BeautifulSoup(text, 'html.parser') 546 b = bs4.BeautifulSoup(text, 'html.parser')
547 c = b.find('form', class_='checkpoint') 547 c = b.find('form', class_='checkpoint')
548 - for mark in ['span', 'p', 'h3', 'strong']:  
549 - content = ''.join([k.text for k in c.find_all(mark)]) 548 + if 'captcha_persist_data' not in text:
  549 + for mark in ['span', 'p', 'h3', 'div']:
  550 + content = ''.join(set([k.text for k in c.find_all(mark)]))
550 if content: 551 if content:
551 return content 552 return content
552 - return "" 553 + else:
  554 + return '进行人机身份验证'
553 except: 555 except:
554 return "" 556 return ""
555 557
@@ -566,6 +568,19 @@ def get_lock_init(text): @@ -566,6 +568,19 @@ def get_lock_init(text):
566 return '' 568 return ''
567 569
568 570
  571 +def get_verification_method(text):
  572 + """
  573 + 获取facebook锁定后的解锁方式
  574 + """
  575 + try:
  576 + b = bs4.BeautifulSoup(text, 'html.parser')
  577 + c_list = b.find_all('div', class_='uiInputLabel clearfix')
  578 + span_list = [c.find_all('span')[1].text for c in c_list]
  579 + return span_list
  580 + except:
  581 + return []
  582 +
  583 +
569 def get_location_info(html): 584 def get_location_info(html):
570 try: 585 try:
571 selector = etree.HTML(html) 586 selector = etree.HTML(html)