def zanting(self): TimeoutMsgBox("暂停", desc=f"{self.address}暂停中\n账号:{self.account}", join=True, geo="200x60")
def do_login(self, ac, pwd): # 执行登陆逻辑 """ :param ac: :param pwd: :return: """ for retry in range(30): if self.d(resourceId= "com.bilibili.priconne:id/bsgamesdk_id_tourist_switch" ).exists(): self.d(resourceId= "com.bilibili.priconne:id/bsgamesdk_id_tourist_switch" ).click() time.sleep(2) continue if not self.d( resourceId= "com.bilibili.priconne:id/bsgamesdk_edit_username_login" ).exists(): time.sleep(2) else: break else: raise Exception("进入登陆页面失败!") self.d( resourceId="com.bilibili.priconne:id/bsgamesdk_edit_username_login" ).click() self.d.clear_text() self.d.send_keys(str(ac)) self.d( resourceId="com.bilibili.priconne:id/bsgamesdk_edit_password_login" ).click() self.d.clear_text() self.d.send_keys(str(pwd)) self.d(resourceId="com.bilibili.priconne:id/bsgamesdk_buttonLogin" ).click() time.sleep(13) def SkipAuth(): if debug: print("等待认证") while self.d(text="请滑动阅读协议内容").exists(): if debug: print("发现协议") self.d.touch.down(814, 367).sleep(1).up(814, 367) self.d(text="同意").click() time.sleep(6) if debug: print("结束认证") SkipAuth() flag = False if self.d(text="Geetest").exists(): flag = True self.phone_privacy() _time = 1 def AutoCaptcha(): nonlocal _time screen = self.getscreen() screen = screen[22:512, 254:711] # 456, 489 if self.d(textContains="下图").exists(): print(">>>检测到图字结合题") # 结果出来为四个字的坐标 answer_result, _len, _id = skip_caption( captcha_img=screen, question_type="X6004") for i in range(0, _len): if i % 2 == 0: # Y轴 self.click(round(answer_result[i] / 0.905, 2), post_delay=1) elif i % 2 != 0: # X轴 self.click(round(answer_result[i] / 0.475, 2), post_delay=1) print(">验证码坐标识别:", answer_result) elif self.d(textContains="请点击").exists(): print(">>>检测到图形题") answer_result, _len, _id = skip_caption( captcha_img=screen, question_type="X6001") x = round(int(answer_result[0]) / 0.475, 2) y = round(int(answer_result[1]) / 0.905, 2) print(">验证码坐标识别:", x, ',', y) print(type(x)) self.click(x, y, post_delay=1) sc1 = self.getscreen() def PopFun(): sc2 = self.getscreen() p = self.img_equal(sc1, sc2, at=START_UI["imgbox"]) if p < 0.85: return True else: return False state = self.lock_fun(PopFun, elseclick=START_UI["queren"], elsedelay=8, retry=5, is_raise=False) if self.d(text="Geetest").exists() and _time <= 5: # 如果次数大于两次,则申诉题目 if _time > 2 and captcha_senderror: print("——申诉题目:", _id) send_error(_id) _time = +1 time.sleep(4) # 如果还有验证码就返回重试 return AutoCaptcha() return state manual_captcha = captcha_skip if captcha_skip is False: for retry in range(3): if self.d(text="Geetest").exists(): state = AutoCaptcha() time.sleep(5) if not state: manual_captcha = True else: SkipAuth() flag = False break else: manual_captcha = True if manual_captcha: if self.d(text="Geetest").exists(): self.log.write_log("error", message='%s账号出现了验证码,请在%d秒内手动输入验证码' % (self.account, captcha_wait_time)) if captcha_popup: TimeoutMsgBox( "!", f"{self.address}出现验证码\n账号:{self.account}", geo="200x80", timeout=captcha_wait_time) now_time = time.time() while time.time() - now_time < captcha_wait_time: time.sleep(1) if not self.d(text="Geetest").exists(): flag = False break time.sleep(1) if not self.d(text="Geetest").exists(): flag = False SkipAuth() if flag: return -1 if self.d(resourceId= "com.bilibili.priconne:id/bsgamesdk_edit_authentication_name" ).exists(timeout=0.1): return 1 # 说明要进行认证 else: return 0 # 正常
def do_login(self, ac, pwd): # 执行登陆逻辑 """ :param ac: :param pwd: :return: """ # 也许你已经注意到,这个整个登陆函数已经成了屎山了, # 每次只要出现登陆部分的BUG都要改半天 # 你永远不知道你程序当前运行在哪个函数里,auth?login_auth?login?do_login?init_home?lock_home? # 如果你想知道,建议在config中把disable_timeout_raise给开启, # 然后在程序运行时按Ctrl+C,如果你运气好,你会看到你程序卡在哪里。 # 我放弃了。 新增自动点击“下载”,自动下载新增数据功能, 2020-11-23 By TheAutumnOfRice for retry in range(30): if self.d(resourceId= "com.bilibili.priconne:id/bsgamesdk_id_tourist_switch" ).exists(): self.d(resourceId= "com.bilibili.priconne:id/bsgamesdk_id_tourist_switch" ).click() time.sleep(2) continue if not self.d( resourceId= "com.bilibili.priconne:id/bsgamesdk_edit_username_login" ).exists(): time.sleep(2) else: break else: raise Exception("进入登陆页面失败!") self.d( resourceId="com.bilibili.priconne:id/bsgamesdk_edit_username_login" ).click() self.d.clear_text() self.d.send_keys(str(ac)) self.d( resourceId="com.bilibili.priconne:id/bsgamesdk_edit_password_login" ).click() self.d.clear_text() self.d.send_keys(str(pwd)) self.d(resourceId="com.bilibili.priconne:id/bsgamesdk_buttonLogin" ).click() time.sleep(12) while True: # 快速响应 time.sleep(1) sc = self.getscreen() if self.is_exists(MAIN_BTN["xiazai"], screen=sc): self.click(MAIN_BTN["xiazai"]) if self.d(text="请滑动阅读协议内容").exists() or self.d( description="请滑动阅读协议内容").exists(): break elif self.is_exists(MAIN_BTN["liwu"], screen=sc): break elif self.d(text="Geetest").exists() or self.d( description="Geetest").exists(): break self.click(MAIN_BTN["zhuye"]) def SkipAuth(): for _ in range(2): # 有两个协议需要同意 if debug: print("等待认证") while self.d(text="请滑动阅读协议内容").exists() or self.d( description="请滑动阅读协议内容").exists(): if debug: print("发现协议") self.d.touch.down(814, 367).sleep(1).up(814, 367) if self.d(text="请滑动阅读协议内容").exists(): self.d(text="同意").click() if self.d(description="请滑动阅读协议内容").exists(): # 雷电三 self.d(description="同意").click() time.sleep(6) if debug: print("结束认证") SkipAuth() flag = False if self.d(text="Geetest").exists() or self.d( description="Geetest").exists(): flag = True self.phone_privacy() _time = 1 _id = 0 def AutoCaptcha(): # 初始化接码 cs = CaptionSkip() nonlocal _time nonlocal _id time.sleep(5) screen = self.getscreen() screen = screen[22:512, 254:711] # 456, 489 if self.d(textContains="请在下图依次").exists(): print(f">>>{self.account}-检测到图字结合题!") print("当出现这玩意时,请仔细核对你的账号密码是否已被更改找回!") # 结果出来为四个字的坐标 # answer_result, _len, _id = skip_caption(captcha_img=screen, question_type="X6004") # for i in range(0, _len): # # Y轴 # self.click(answer_result[i][1] + 22, post_delay=1) # # X轴 # self.click(answer_result[i][0] + 254, post_delay=1) # print(">验证码坐标识别:", answer_result) elif self.d(textContains="请点击").exists(): print(f">>>{self.account}-检测到图形题") answer_result, _len, _id = cs.skip_caption( captcha_img=screen, question_type="X6001") x = int(answer_result[0]) + 254 y = int(answer_result[1]) + 22 print(f">{self.account}-验证码坐标识别:", x, ',', y) # print(type(x)) self.click(x, y, post_delay=1) else: print( f"{self.account}-存在未知领域,无法识别到验证码(或许已经进入主页面了),请加群带图联系开发者" ) sc1 = self.getscreen() def PopFun(): sc2 = self.getscreen() p = self.img_equal(sc1, sc2, at=START_UI["imgbox"]) if p < 0.85: return True else: return False if _id == 0: time.sleep(4) # 检测到题目id为0就重新验证 return AutoCaptcha() state = self.lock_fun(PopFun, elseclick=START_UI["queren"], elsedelay=8, retry=5, is_raise=False) if (self.d(text="Geetest").exists() or self.d(description="Geetest").exists()): if _time >= 5: print("重试次数太多啦,休息15s") time.sleep(15) _time = 0 return AutoCaptcha() # 如果次数大于两次,则申诉题目 elif _time > captcha_senderror_times and captcha_senderror: print("—申诉题目:", _id) cs.send_error(_id) _time = +1 time.sleep(4) # 如果还有验证码就返回重试 return AutoCaptcha() return state manual_captcha = captcha_skip if captcha_skip is False: for retry in range(3): if self.d(text="Geetest").exists() or self.d( description="Geetest").exists(): state = AutoCaptcha() time.sleep(5) if not state: manual_captcha = True else: SkipAuth() flag = False break else: manual_captcha = True if manual_captcha: if self.d(text="Geetest").exists() or self.d( description="Geetest").exists(): self.log.write_log("error", message='%s账号出现了验证码,请在%d秒内手动输入验证码' % (self.account, captcha_wait_time)) if captcha_popup: TimeoutMsgBox( "!", f"{self.address}出现验证码\n账号:{self.account}", geo="200x80", timeout=captcha_wait_time) now_time = time.time() while time.time() - now_time < captcha_wait_time: time.sleep(1) if not (self.d(text="Geetest").exists() or self.d(description="Geetest").exists()): flag = False break time.sleep(1) if not (self.d(text="Geetest").exists() or self.d(description="Geetest").exists()): flag = False SkipAuth() if flag: return -1 if self.d(resourceId= "com.bilibili.priconne:id/bsgamesdk_edit_authentication_name" ).exists(timeout=0.1): return 1 # 说明要进行认证 else: return 0 # 正常
def do_login(self, ac, pwd): # 执行登陆逻辑 """ :param ac: :param pwd: :return: """ # 也许你已经注意到,这个整个登陆函数已经成了屎山了, # 每次只要出现登陆部分的BUG都要改半天 # 你永远不知道你程序当前运行在哪个函数里,auth?login_auth?login?do_login?init_home?lock_home? # 如果你想知道,建议在config中把disable_timeout_raise给开启, # 然后在程序运行时按Ctrl+C,如果你运气好,你会看到你程序卡在哪里。 # 我放弃了。 新增自动点击“下载”,自动下载新增数据功能, 2020-11-23 By TheAutumnOfRice # 结构梳理下为:auth -> login_auth(是否需要实名认证<->login<->do_login[验证码处理]) -> init_home(lock_home) for retry in range(300): self._move_check() self.click(945, 13) # 防止卡住 if self.d(resourceId= "com.bilibili.priconne:id/bsgamesdk_id_tourist_switch" ).exists(): self.d(resourceId= "com.bilibili.priconne:id/bsgamesdk_id_tourist_switch" ).click() time.sleep(0.8) continue if not self.d( resourceId= "com.bilibili.priconne:id/bsgamesdk_edit_username_login" ).exists(): time.sleep(0.8) else: break else: raise Exception("进入登陆页面失败!") self.d( resourceId="com.bilibili.priconne:id/bsgamesdk_edit_username_login" ).click() self.d.clear_text() self.d.send_keys(str(ac)) self.d( resourceId="com.bilibili.priconne:id/bsgamesdk_edit_password_login" ).click() self.d.clear_text() self.d.send_keys(str(pwd)) self.d(resourceId="com.bilibili.priconne:id/bsgamesdk_buttonLogin" ).click() toast_message = self.d.toast.get_message() while True: # 快速响应 # 很容易在这里卡住 time.sleep(1) sc = self.getscreen() if self.is_exists(MAIN_BTN["xiazai"], screen=sc): self.click(MAIN_BTN["xiazai"]) if self.d(text="请滑动阅读协议内容").exists() or self.d( description="请滑动阅读协议内容").exists(): break elif self.is_exists(MAIN_BTN["liwu"], screen=sc): break elif self.d(text="Geetest").exists() or self.d( description="Geetest").exists(): break elif self.d(resourceId= "com.bilibili.priconne:id/bsgamesdk_fl_realname_web" ).exists(): return 1 # 说明要进行认证 elif toast_message is "密码错误": raise Exception("密码错误!") elif not self.d(resourceId="com.bilibili.priconne:id/bsgamesdk_buttonLogin").exists() and \ not self.d(resourceId="com.bilibili.priconne:id/bsgamesdk_fl_realname_web").exists(): break def SkipAuth(): for _ in range(2): # 有两个协议需要同意 if debug: print("等待认证") while self.d(text="请滑动阅读协议内容").exists() or self.d( description="请滑动阅读协议内容").exists(): if debug: print("发现协议") self._move_check() self.d.touch.down(814, 367).sleep(1).up(814, 367) if self.d(text="请滑动阅读协议内容").exists(): self.d(text="同意").click() if self.d(description="请滑动阅读协议内容").exists(): # 雷电三 self.d(description="同意").click() time.sleep(6) if debug: print("结束认证") SkipAuth() flag = False if self.d(text="Geetest").exists() or self.d( description="Geetest").exists(): flag = True _time = 1 _id = 0 _pop = False def AutoCaptcha(): # 初始化接码 cs = CaptionSkip() nonlocal _time nonlocal _id nonlocal _pop time.sleep(5) screen = self.getscreen() screen = screen[1:575, 157:793] # 原来的 456, 489 # 不要了,这是新的分辨率,需要包含游戏一部分截图 636,539 if self.d(textContains="请点击此处重试").exists(): print(f">>>{self.account}-请点击此处重试") # 点重试 self.click(482, 315, post_delay=3) elif self.d(textContains="异常").exists() or self.d( textContains="返回").exists(): print(f">>>{self.account}-网络异常,刷新验证码") self.click(476, 262) self.d(text="返回").click() elif self.d(textContains="请在下图依次").exists(): print(f">>>{self.account}-检测到图字结合题") print("当出现这玩意时,请仔细核对你的账号密码是否已被更改找回!") # 这是关闭验证码 self.click(667, 65, post_delay=3) # 结果出来为四个字的坐标 answer_result, _len, _id = cs.skip_caption( captcha_img=screen, question_type="X6004") for i in range(0, _len + 1): x = int(answer_result[i].split(',')[0]) + 157 y = int(answer_result[i].split(',')[1]) + 1 print(f">{self.account}-验证码第{i}坐标识别:", x, ',', y) self.click(x, y, post_delay=1) elif self.d(textContains="请点击").exists(): print(f">>>{self.account}-检测到图形题") answer_result, _len, _id = cs.skip_caption( captcha_img=screen, question_type="X6001") x = int(answer_result[0]) + 157 y = int(answer_result[1]) + 1 print(f">{self.account}-验证码坐标识别:", x, ',', y) # print(type(x)) self.click(x, y, post_delay=1) elif self.d(textContains="拖动滑块").exists(): print(f">>>{self.account}-检测到滑块题") answer_result, _len, _id = cs.skip_caption( captcha_img=screen, question_type="X8006") x = int(answer_result[0]) + 157 y = int(answer_result[1]) + 1 print(f">{self.account}-滑块坐标识别:", x, 386) # print(type(x)) # 从322,388 滑动到 x,y self.d.drag_to(322, 388, x, 386, 3.6) else: print( f"{self.account}-存在未知领域,无法识别到验证码(或许已经进入主页面了),有问题请加群带图联系开发者" ) return False sc1 = self.getscreen() def PopFun(): time.sleep(1) sc2 = self.getscreen() p = self.img_equal(sc1, sc2, at=START_UI["imgbox"]) if p < 0.76: return True else: return False if _id == 0: time.sleep(4) # 检测到题目id为0就重新验证 AutoCaptcha() state = self.lock_fun(PopFun, elseclick=START_UI["queren"], elsedelay=5, retry=8, is_raise=False) # 这里是获取toast,看是否输错密码 toast_message = self.d.toast.get_message() if toast_message is "密码错误": raise Exception("密码错误!") if self.d(text="Geetest").exists() or self.d( description="Geetest").exists(): if _time >= 5: print("重试次数太多啦,休息15s") time.sleep(15) _time = 0 AutoCaptcha() # 如果次数大于两次,则申诉题目 elif _time > captcha_senderror_times and captcha_senderror: print("—申诉题目:", _id) cs.send_error(_id) _time = +1 time.sleep(4) # 如果还有验证码就返回重试 AutoCaptcha() return state manual_captcha = captcha_skip if captcha_skip is False: for retry in range(3): if self.d(text="Geetest").exists() or self.d( description="Geetest").exists(): state = AutoCaptcha() time.sleep(5) if not state: manual_captcha = True break else: SkipAuth() flag = False break else: manual_captcha = True if manual_captcha: if self.d(text="Geetest").exists() or self.d( description="Geetest").exists(): self.log.write_log("error", message='%s账号出现了验证码,请在%d秒内手动输入验证码' % (self.account, captcha_wait_time)) if captcha_popup: TimeoutMsgBox( "!", f"{self.address}出现验证码\n账号:{self.account}", geo="200x80", timeout=captcha_wait_time) now_time = time.time() while time.time() - now_time < captcha_wait_time: self._move_check() time.sleep(1) if not (self.d(text="Geetest").exists() or self.d(description="Geetest").exists()): flag = False break time.sleep(1) if not (self.d(text="Geetest").exists() or self.d(description="Geetest").exists()): flag = False SkipAuth() if self.d( resourceId="com.bilibili.priconne:id/bsgamesdk_fl_realname_web" ).exists(timeout=0.1): return 1 # 说明要进行认证 if flag: return -1 else: return 0 # 正常
def do_login(self, ac, pwd): # 执行登陆逻辑 """ :param ac: :param pwd: :return: """ for retry in range(30): if not self.d( resourceId= "com.bilibili.priconne:id/bsgamesdk_edit_username_login" ).exists(): time.sleep(2) else: break else: raise Exception("进入登陆页面失败!") self.d( resourceId="com.bilibili.priconne:id/bsgamesdk_edit_username_login" ).click() self.d.clear_text() self.d.send_keys(str(ac)) self.d( resourceId="com.bilibili.priconne:id/bsgamesdk_edit_password_login" ).click() self.d.clear_text() self.d.send_keys(str(pwd)) self.d(resourceId="com.bilibili.priconne:id/bsgamesdk_buttonLogin" ).click() time.sleep(15) if debug: print("等待认证") while self.d(text="请滑动阅读协议内容").exists(): if debug: print("发现协议") self.d.touch.down(814, 367).sleep(1).up(814, 367) self.d(text="同意").click() time.sleep(6) flag = False if self.d(text="Geetest").exists(): flag = True self.phone_privacy() if captcha_skip is False: # 仅会识别两次,防止一直扣分 screen = self.getscreen() x, y = skip_caption(captcha_img=screen) print("验证码坐标识别:", x, ',', y) self.click(x, y, post_delay=1) self.click_btn(START_UI["queren"], retry=5) if self.d(text="Geetest").exists(): self.click(451, 442) time.sleep(3) while self.d(text="Geetest").exists(): screen = self.getscreen() x, y = skip_caption(captcha_img=screen) print("验证码n次坐标识别:", x, ',', y) self.click(x, y, post_delay=1) self.click_btn(START_UI["queren"], retry=5) if debug: print("等待认证") while self.d(text="请滑动阅读协议内容").exists(): if debug: print("发现协议") self.d.touch.down(814, 367).sleep(1).up(814, 367) self.d(text="同意").click() time.sleep(6) time.sleep(1) if not self.d(text="Geetest").exists(): flag = False else: self.log.write_log("error", message='%s账号出现了验证码,请在%d秒内手动输入验证码' % (self.account, captcha_wait_time)) if captcha_popup: TimeoutMsgBox("!", f"{self.address}出现验证码\n账号:{self.account}", geo="200x80", timeout=captcha_wait_time) now_time = time.time() while time.time() - now_time < captcha_wait_time: time.sleep(1) if not self.d(text="Geetest").exists(): flag = False break if flag: return -1 if debug: print("认证结束") if self.d(resourceId= "com.bilibili.priconne:id/bsgamesdk_edit_authentication_name" ).exists(timeout=0.1): return 1 # 说明要进行认证 else: return 0 # 正常
def do_login(self, ac, pwd): # 执行登陆逻辑 """ :param ac: :param pwd: :return: """ # 也许你已经注意到,这个整个登陆函数已经成了屎山了, # 每次只要出现登陆部分的BUG都要改半天 # 你永远不知道你程序当前运行在哪个函数里,auth?login_auth?login?do_login?init_home?lock_home? # 如果你想知道,建议在config中把disable_timeout_raise给开启, # 然后在程序运行时按Ctrl+C,如果你运气好,你会看到你程序卡在哪里。 # 我放弃了。 新增自动点击“下载”,自动下载新增数据功能, 2020-11-23 By TheAutumnOfRice # 结构梳理下为:auth -> login_auth(是否需要实名认证<->login<->do_login[验证码处理]) -> init_home(lock_home) for retry in range(300): self._move_check() self.click(945, 13) # 防止卡住 if self.d(resourceId="com.bilibili.priconne:id/tv_gsc_wel_change" ).exists(): self.d(resourceId="com.bilibili.priconne:id/tv_gsc_wel_change" ).click() time.sleep(0.8) continue if self.d(resourceId= "com.bilibili.priconne:id/tv_gsc_record_login_change" ).exists(): self.d(resourceId= "com.bilibili.priconne:id/tv_gsc_record_login_change" ).click() time.sleep(0.8) continue if self.d( resourceId="com.bilibili.priconne:id/iv_gsc_account_login" ).exists(): time.sleep(0.8) self.d( resourceId="com.bilibili.priconne:id/iv_gsc_account_login" ).click() continue if not self.d(resourceId="com.bilibili.priconne:id/et_gsc_account" ).exists(): time.sleep(0.2) else: break else: raise Exception("进入登陆页面失败!") self.d(resourceId="com.bilibili.priconne:id/et_gsc_account").click() self.d.clear_text() self.d.send_keys(str(ac)) self.d( resourceId="com.bilibili.priconne:id/et_gsc_account_pwd").click() self.d.clear_text() self.d.send_keys(str(pwd)) time.sleep(random.uniform(0.2, 1)) self.d(resourceId="com.bilibili.priconne:id/tv_gsc_account_login" ).click() # time.sleep(0.5) toast_message = self.d.toast.get_message() # print(toast_message) if toast_message == "密码错误": raise BadLoginException("密码错误!") elif "账号异常" in str(toast_message).split(" "): raise BadLoginException("账号异常!") while True: # 快速响应 # 很容易在这里卡住 # time.sleep(0.4) sc = self.getscreen() if self.is_exists(MAIN_BTN["xiazai"], screen=sc): self.click(MAIN_BTN["xiazai"]) if self.d(text="请滑动阅读协议内容").exists() or self.d( description="请滑动阅读协议内容").exists(): break elif self.is_exists(MAIN_BTN["liwu"], screen=sc): break elif self.d(text="Geetest").exists() or self.d( description="Geetest").exists(): break elif self.d( resourceId="com.bilibili.priconne:id/gsc_rl_realname_web" ).exists(): return 1 # 说明要进行认证 elif not self.d(resourceId="com.bilibili.priconne:id/tv_gsc_account_login").exists() and \ not self.d(resourceId="com.bilibili.priconne:id/gsc_rl_realname_web").exists(): break def SkipAuth(): for _ in range(2): # 有两个协议需要同意 if debug: print("等待认证") while self.d(text="请滑动阅读协议内容").exists() or self.d( description="请滑动阅读协议内容").exists(): if debug: print("发现协议") self._move_check() self.d.touch.down(810, 378).sleep(1).up(810, 378) if self.d(text="请滑动阅读协议内容").exists(): self.d(text="同意").click() if self.d(description="请滑动阅读协议内容").exists(): # 雷电三 self.d(description="同意").click() # time.sleep(6) if debug: print("结束认证") SkipAuth() flag = False if self.d(text="Geetest").exists() or self.d( description="Geetest").exists(): flag = True _time = 1 _id = 0 _pop = False # 初始化接码 cs = CaptionSkip() def AutoCaptcha(): nonlocal _time nonlocal _id nonlocal _pop # time.sleep(1) screen = self.getscreen() screen = screen[1:575, 157:793] # 原来的 456, 489 # 不要了,这是新的分辨率,需要包含游戏一部分截图 636,539 if self.d(textContains="请点击此处重试").exists(): print(f">>>{self.account}-请点击此处重试") # 点重试 # self.click(482, 315) self.d(text="请点击此处重试").click() elif self.d(textContains="异常").exists() or self.d( textContains="返回").exists(): print(f">>>{self.account}-网络异常,刷新验证码") self.click(476, 262) self.d(text="返回").click() elif self.d(textContains="请在下图依次").exists(): print(f">>>{self.account}-检测到图字结合题") print("当出现这玩意时,请仔细核对你的账号密码是否已被更改找回!") # 这是关闭验证码 self.click(667, 65, post_delay=3) # 结果出来为四个字的坐标 answer_result, _len, _id = cs.skip_caption( captcha_img=screen, question_type="X6004") for i in range(0, _len + 1): x = int(answer_result[i].split(',')[0]) + 157 y = int(answer_result[i].split(',')[1]) + 1 print(f">{self.account}-验证码第{i}坐标识别:", x, ',', y) self.click(x, y) if answer_result == [255, 439]: print("平台识别不出来,刷新") self.d(text="确认").click() _time = +1 time.sleep(captcha_sleep_times) elif self.d(textContains="请点击").exists(): print(f">>>{self.account}-检测到图形题") while True: # 不用at,直接全图找更保险.请自行处理验证失败图片抖动的耗时 if self.is_exists(START_UI["anying"]): break answer_result, _len, _id = cs.skip_caption( captcha_img=screen, question_type="X6001") # print(answer_result,' ', _len,' ', _id) x = int(answer_result[0]) + 157 y = int(answer_result[1]) + 1 print(f">{self.account}-验证码坐标识别:", x, ',', y) # print(type(x)) self.click(x, y) if answer_result == [255, 439]: print("平台识别不出来,刷新") self.d(text="确认").click() _time = +1 time.sleep(captcha_sleep_times) elif self.d(textContains="拖动滑块").exists(): print(f">>>{self.account}-检测到滑块题") answer_result, _len, _id = cs.skip_caption( captcha_img=screen, question_type="X8006") x = int(answer_result[0]) + 157 y = int(answer_result[1]) + 1 print(f">{self.account}-滑块坐标识别:", x, 386) # print(type(x)) # 从322,388 滑动到 x,y self.d.drag_to(322, 388, x, 386, 3.6) if answer_result == [255, 439]: print("平台识别不出来,刷新") self.d(text="确认").click() _time = +1 time.sleep(captcha_sleep_times) else: print( f"{self.account}-存在未知领域,无法识别到验证码(或许已经进入主页面了),如有问题请加群带图联系开发者" ) # return False def due_AutoCaptcha(): nonlocal _time nonlocal _id nonlocal _pop if _id == 0: # time.sleep(1) # 检测到题目id为0就重新验证 AutoCaptcha() # time.sleep(1) # sc2 = self.getscreen() # p = self.img_equal(sc1, sc2, at=START_UI["imgbox"]) # print(p) # if p <= 0.99: # nonlocal state # self.d(text="确认").click() # state = True # else: # state = False # 这里是验证码登录后 toast_message = self.d.toast.get_message() # print(toast_message) if self.d(resourceId= "com.bilibili.priconne:id/iv_gsc_account_login" ).exists(): # time.sleep(0.8) self.d( resourceId= "com.bilibili.priconne:id/iv_gsc_account_login").click( timeout=1) time.sleep(captcha_sleep_times) AutoCaptcha() if toast_message == "请检查网络,-662": # print("请检查网络,-662") if self.d(text="登录").exists(): self.d(text="登录").click(timeout=2) time.sleep(captcha_sleep_times) AutoCaptcha() # raise BadLoginException("请检查网络,-662") elif toast_message == "密码错误": raise BadLoginException("密码错误!") elif "账号异常" in str(toast_message).split(" "): raise BadLoginException("账号异常!") # 下面代码暂时不管用 if self.d(text="Geetest").exists() or self.d( description="Geetest").exists(): if _time >= 5: print("重试次数太多啦,休息15s") time.sleep(15) _time = 0 AutoCaptcha() # 如果次数大于两次,则申诉题目 elif _time > captcha_senderror_times and captcha_senderror: print("—申诉题目:", _id) cs.send_error(_id) _time = +1 print("验证码登陆验证重来!") # 如果还有验证码就返回重试 AutoCaptcha() manual_captcha = captcha_skip if captcha_skip is False: for retry in range(15): if self.d(text="Geetest").exists() or self.d(description="Geetest").exists() or \ self.d(resourceId="com.bilibili.priconne:id/iv_gs_title_back").exists(): AutoCaptcha() due_AutoCaptcha() state = True # 先这样,10s验证,state几乎已经不适用了 # time.sleep(5) if not state: manual_captcha = True break else: SkipAuth() flag = False break else: manual_captcha = True if manual_captcha: if self.d(text="Geetest").exists() or self.d( description="Geetest").exists(): self.log.write_log("error", message='%s账号出现了验证码,请在%d秒内手动输入验证码' % (self.account, captcha_wait_time)) if captcha_popup: TimeoutMsgBox( "!", f"{self.address}出现验证码\n账号:{self.account}", geo="200x80", timeout=captcha_wait_time) now_time = time.time() while time.time() - now_time < captcha_wait_time: self._move_check() time.sleep(1) if not (self.d(text="Geetest").exists() or self.d(description="Geetest").exists()): flag = False break time.sleep(1) if not (self.d(text="Geetest").exists() or self.d(description="Geetest").exists()): flag = False SkipAuth() if self.d(resourceId="com.bilibili.priconne:id/gsc_rl_realname_web" ).exists(timeout=0.1): return 1 # 说明要进行认证 if flag: return -1 else: return 0 # 正常
def do_login(self, ac, pwd): # 执行登陆逻辑 """ :param ac: :param pwd: :return: """ for retry in range(30): if not self.d( resourceId= "com.bilibili.priconne:id/bsgamesdk_edit_username_login" ).exists(): time.sleep(2) else: break else: raise Exception("进入登陆页面失败!") self.d( resourceId="com.bilibili.priconne:id/bsgamesdk_edit_username_login" ).click() self.d.clear_text() self.d.send_keys(str(ac)) self.d( resourceId="com.bilibili.priconne:id/bsgamesdk_edit_password_login" ).click() self.d.clear_text() self.d.send_keys(str(pwd)) self.d(resourceId="com.bilibili.priconne:id/bsgamesdk_buttonLogin" ).click() time.sleep(20) if debug: print("等待认证") while self.d(text="请滑动阅读协议内容").exists(): if debug: print("发现协议") self.d.touch.down(814, 367).sleep(1).up(814, 367) self.d(text="同意").click() time.sleep(10) flag = False if self.d(text="Geetest").exists(): flag = True self.phone_privacy() self.log.write_log("error", message='%s账号出现了验证码,请在%d秒内手动输入验证码' % (self.account, captcha_wait_time)) if captcha_popup: TimeoutMsgBox("!", f"{self.address}出现验证码\n账号:{self.account}", geo="200x80", timeout=captcha_wait_time) now_time = time.time() while time.time() - now_time < captcha_wait_time: time.sleep(1) if not self.d(text="Geetest").exists(): flag = False break if flag: return -1 if debug: print("认证结束") if self.d(resourceId= "com.bilibili.priconne:id/bsgamesdk_edit_authentication_name" ).exists(timeout=0.1): return 1 # 说明要进行认证 else: return 0 # 正常
def do_login(self, ac, pwd): # 执行登陆逻辑 """ :param ac: :param pwd: :return: """ # 也许你已经注意到,这个整个登陆函数已经成了屎山了, # 每次只要出现登陆部分的BUG都要改半天 # 你永远不知道你程序当前运行在哪个函数里,auth?login_auth?login?do_login?init_home?lock_home? # 如果你想知道,建议在config中把disable_timeout_raise给开启, # 然后在程序运行时按Ctrl+C,如果你运气好,你会看到你程序卡在哪里。 # 我放弃了。 新增自动点击“下载”,自动下载新增数据功能, 2020-11-23 By TheAutumnOfRice # 结构梳理下为:auth -> login_auth(是否需要实名认证<->login<->do_login[验证码处理]) -> init_home(lock_home) for retry in range(300): self._move_check() self.click(945, 13) # 防止卡住 if self.d(resourceId="com.bilibili.priconne:id/tv_gsc_other" ).exists(): self.d(resourceId="com.bilibili.priconne:id/tv_gsc_other" ).click() time.sleep(0.8) continue if self.d(resourceId="com.bilibili.priconne:id/tv_gsc_wel_change" ).exists(): self.d(resourceId="com.bilibili.priconne:id/tv_gsc_wel_change" ).click() time.sleep(0.8) continue if self.d(resourceId= "com.bilibili.priconne:id/tv_gsc_record_login_change" ).exists(): self.d(resourceId= "com.bilibili.priconne:id/tv_gsc_record_login_change" ).click() time.sleep(0.8) continue if self.d( resourceId="com.bilibili.priconne:id/iv_gsc_account_login" ).exists(): time.sleep(0.8) self.d( resourceId="com.bilibili.priconne:id/iv_gsc_account_login" ).click() continue if self.d(text="Geetest").exists() or self.d( description="Geetest").exists(): self.click(687, 72) # 防止卡验证码 continue if not self.d(resourceId="com.bilibili.priconne:id/et_gsc_account" ).exists(): time.sleep(0.2) else: break else: raise Exception("进入登陆页面失败!") self.d(resourceId="com.bilibili.priconne:id/et_gsc_account").click() self.d.clear_text() self.d.send_keys(str(ac)) self.d( resourceId="com.bilibili.priconne:id/et_gsc_account_pwd").click() self.d.clear_text() self.d.send_keys(str(pwd)) time.sleep(random.uniform(0.2, 1)) self.d(resourceId="com.bilibili.priconne:id/tv_gsc_account_login" ).click() # time.sleep(0.5) toast_message = self.d.toast.get_message() # print(toast_message) if toast_message == "密码错误": raise BadLoginException("密码错误!") elif toast_message == "系统检测到您的账号异常,请前往网页主站重新登录并进行验证": raise BadLoginException("账号异常!") # else: # print(f"toast_message:{toast_message}") while True: # 快速响应 # 很容易在这里卡住 # time.sleep(0.4) sc = self.getscreen() if self.is_exists(MAIN_BTN["xiazai"], screen=sc): self.click(MAIN_BTN["xiazai"]) if self.d(text="请滑动阅读协议内容").exists() or self.d( description="请滑动阅读协议内容").exists(): break elif self.is_exists(MAIN_BTN["liwu"], screen=sc): break elif self.d(text="Geetest").exists() or self.d( description="Geetest").exists(): break elif self.d( resourceId="com.bilibili.priconne:id/gsc_rl_realname_web" ).exists(): return 1 # 说明要进行认证 elif not self.d(resourceId="com.bilibili.priconne:id/tv_gsc_account_login").exists() and \ not self.d(resourceId="com.bilibili.priconne:id/gsc_rl_realname_web").exists(): break def SkipAuth(): for _ in range(2): # 有两个协议需要同意 if debug: self.log.write_log('debug', "等待认证") while self.d(text="请滑动阅读协议内容").exists() or self.d( description="请滑动阅读协议内容").exists(): if debug: self.log.write_log('debug', "发现协议") self._move_check() self.d.touch.down(808, 353).sleep(1).up(808, 353) if self.d(text="请滑动阅读协议内容").exists(): self.d(text="同意").click() if self.d(description="请滑动阅读协议内容").exists(): # 雷电三 self.d(description="同意").click() # time.sleep(6) if debug: self.log.write_log('debug', "结束认证") SkipAuth() flag = False if self.d(text="Geetest").exists() or self.d( description="Geetest").exists(): flag = True _time = 0 _id = -1 # -1代表没有答题 _pop = False # 初始化接码 cs = CaptionSkip(self.log) def AutoCaptcha(): nonlocal _time # 验证码答题次数 nonlocal _id nonlocal _pop # time.sleep(1) # 这里是判断验证码动画是否加载完毕和截图到达指定位置 # 不用at,直接全图找更保险.请自行处理验证失败图片抖动的耗时 screen = None # 这里堵塞了,等图像稳定 if self.wait_for_stable(similarity=1.0, threshold=0.1, delay=0.5, at=(348, 162, 621, 439)): # 原来的 456, 489 # 不要了,这是新的分辨率,需要包含游戏一部分截图 636,539 screen = self.getscreen()[1:575, 157:793] # 白屏处理 find_bw_img = screen[44:492, 94:543] w, b, _, _ = self.img_findgaoliang(find_bw_img) if b == 0: return False elif w > 200000 and b < 5000: return False elif not (self.d(text="Geetest").exists() or self.d(description="Geetest").exists()): return False # 再改就屎山了( if due_AutoCaptcha(toast=False) == -1: return False if self.d(textContains="请在下图依次").exists(): self.log.write_log('info', f">>>{self.account}-检测到图字结合题") self.log.write_log('warning', "当出现这玩意时,请仔细核对你的账号密码是否已被更改找回!") # 这是关闭验证码 self.click(674, 74, post_delay=3) # 结果出来为四个字的坐标 answer_result, _len, _id = cs.skip_caption( captcha_img=screen, question_type="X6004") for i in range(0, _len + 1): x = int(answer_result[i].split(',')[0]) + 157 y = int(answer_result[i].split(',')[1]) + 1 self.log.write_log( 'info', f">{self.account}-验证码第{i}坐标识别:{x},{y}") self.click(x, y) if answer_result == [255, 439]: self.click(687, 72) # self.d(text="登录").click(timeout=1) self.log.write_log('info', "平台识别不出来,刷新") else: pass # time.sleep(captcha_sleep_times) _time += 1 return True elif self.d(textContains="请点击").exists(): self.log.write_log('info', f">>>{self.account}-检测到图形题") answer_result, _len, _id = cs.skip_caption( captcha_img=screen, question_type="X6001") # print(answer_result,' ', _len,' ', _id) x = int(answer_result[0]) + 157 y = int(answer_result[1]) + 1 self.log.write_log('info', f">{self.account}-验证码坐标识别: {x},{y}") # print(type(x)) self.click(x, y) if answer_result == [255, 439]: self.click(687, 72) # self.d(text="登录").click(timeout=1) self.log.write_log('info', "平台识别不出来,刷新") else: pass # time.sleep(captcha_sleep_times) _time += 1 return True elif self.d(textContains="拖动滑块").exists(): self.log.write_log('info', f">>>{self.account}-检测到滑块题") answer_result, _len, _id = cs.skip_caption( captcha_img=screen, question_type="X8006") x = int(answer_result[0]) + 157 y = int(answer_result[1]) + 1 self.log.write_log('info', f">{self.account}-滑块坐标识别:{x}, 386") # print(type(x)) # 从322,388 滑动到 x,y self.d.drag_to(322, 388, x, 386, 3.6) if answer_result == [255, 439]: self.click(687, 72) # self.d(text="登录").click(timeout=1) self.log.write_log('info', "平台识别不出来,刷新") else: pass # time.sleep(captcha_sleep_times) _time += 1 return True else: self.log.write_log( 'info', f"{self.account}-存在未知领域,无法识别到验证码(或许已经进入主页面了),如有问题请加群带图联系开发者" ) return False def due_AutoCaptcha(toast=True, blocking=False): """ :param blocking: 堵塞等待结果处理 :param toast: 抓取toast :return -1:代表验证码已经被脚本刷新 """ # 处理验证码操作,已经不分前后了 nonlocal _time nonlocal _id nonlocal _pop if blocking: for_times = iter(int, 1) # print("死循环开启") else: for_times = range(0, 1) for _ in for_times: toast_message = "no message" # 答题过的id为str,优先队列执行 if type(_id) is str and \ (self.d(text="Geetest").exists() or self.d(description="Geetest").exists()): self.d(text="确认").click() _id = -1 return -1 # 不清楚验证码是否验证成功,会导致toast无法执行 if toast: # 这里是验证码登录后 toast_message = self.d.toast.get_message() # 耗时大户 # print(toast_message) if _id == 0: # time.sleep(1) # 检测到题目id为0就重新验证 # 防止卡验证码 if self.d(text="Geetest").exists() or self.d( description="Geetest").exists(): self.click(687, 72) _id = -1 return -1 elif self.d(textContains="请点击此处重试").exists(): self.log.write_log('info', f">>>{self.account}-请点击此处重试") # 点重试 # self.click(482, 315) self.d(text="请点击此处重试").click() return -1 elif self.d(textContains="异常").exists() or self.d( textContains="返回").exists(): self.log.write_log('info', f">>>{self.account}-网络异常,刷新验证码") self.click(476, 262) self.d(text="返回").click() return -1 # time.sleep(1) # sc2 = self.getscreen() # p = self.img_equal(sc1, sc2, at=START_UI["imgbox"]) # print(p) # if p <= 0.99: # nonlocal state # self.d(text="确认").click() # state = True # else: # state = False elif toast_message == "请检查网络,-662": self.log.write_log('info', "请检查网络,-662") # print("请检查网络,-662") if self.d(text="登录").exists(): self.d(text="登录").click(timeout=5) # time.sleep(captcha_sleep_times) return -1 # raise BadLoginException("请检查网络,-662") elif toast_message == "密码错误": raise BadLoginException("密码错误!") elif toast_message == "系统检测到您的账号异常,请前往网页主站重新登录并进行验证": raise BadLoginException("账号异常!") # 重生验证码 elif (_time >= 2 or _time == 0) and \ (self.d(text="Geetest").exists() or self.d(description="Geetest").exists()): # print(_time, "验证码重生") self.log.write_log('info', "验证码刷新") self.click(687, 72) self.d(text="登录").click(timeout=10) _time = 1 return -1 # 单独控件检测应该放在最后 elif self.d(resourceId= "com.bilibili.priconne:id/iv_gsc_account_login" ).exists(): # time.sleep(0.8) self.d(resourceId= "com.bilibili.priconne:id/iv_gsc_account_login" ).click(timeout=5) # time.sleep(captcha_sleep_times) return -1 elif self.d(text="登录").exists(): self.d(text="登录").click(timeout=5) return -1 # 下面代码暂时不管用 # if self.d(text="Geetest").exists() or self.d(description="Geetest").exists(): # if _time >= 5: # print("重试次数太多啦,休息15s") # time.sleep(15) # _time = 0 # AutoCaptcha() # # 如果次数大于两次,则申诉题目 # elif _time > captcha_senderror_times and captcha_senderror: # print("—申诉题目:", _id) # cs.send_error(_id) # _time = + 1 # print("验证码登陆验证重来!") # # 如果还有验证码就返回重试 # AutoCaptcha() manual_captcha = captcha_skip if captcha_skip is False: exist_geetest = False # state = True # 先这样,10s验证,state几乎已经不适用了 # 请确保来这之前已经有账户和密码输入! if self.d(text="Geetest").exists() or self.d( description="Geetest").exists(): exist_geetest = True while exist_geetest: if self.d(className='android.widget.RelativeLayout' ).exists(): try: # print(self.account, "在过验证码") if AutoCaptcha(): due_AutoCaptcha(blocking=True) except Exception as e: self.log.write_log('error', f"自动过验证码发生报错:{e}") continue # # time.sleep(5) # if not state: # manual_captcha = True # break else: time.sleep(1) if not self.d(className='android.widget.RelativeLayout' ).exists(): self.log.write_log('info', f"{self.account}已经过验证码") SkipAuth() flag = False break elif due_AutoCaptcha() == -1: continue else: manual_captcha = True if manual_captcha: if self.d(text="Geetest").exists() or self.d( description="Geetest").exists(): self.log.write_log("error", message='%s账号出现了验证码,请在%d秒内手动输入验证码' % (self.account, captcha_wait_time)) if captcha_popup: TimeoutMsgBox( "!", f"{self.address}出现验证码\n账号:{self.account}", geo="200x80", timeout=captcha_wait_time) now_time = time.time() while time.time() - now_time < captcha_wait_time: self._move_check() time.sleep(1) if not (self.d(text="Geetest").exists() or self.d(description="Geetest").exists()): flag = False break time.sleep(1) if not (self.d(text="Geetest").exists() or self.d(description="Geetest").exists()): flag = False SkipAuth() if self.d(resourceId="com.bilibili.priconne:id/gsc_rl_realname_web" ).exists(timeout=0.1): return 1 # 说明要进行认证 if flag: return -1 else: return 0 # 正常