parent
							
								
									4c83e00bf8
								
							
						
					
					
						commit
						e94a01bc69
					
				@ -0,0 +1,69 @@ | 
				
			|||||||
 | 
					package io.legado.app.help | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import io.legado.app.utils.startActivity | 
				
			||||||
 | 
					import io.legado.app.constant.AppLog | 
				
			||||||
 | 
					import io.legado.app.exception.NoStackTraceException | 
				
			||||||
 | 
					import io.legado.app.data.entities.BaseSource | 
				
			||||||
 | 
					import io.legado.app.ui.browser.WebViewActivity | 
				
			||||||
 | 
					import io.legado.app.ui.association.VerificationCodeActivity | 
				
			||||||
 | 
					import splitties.init.appCtx | 
				
			||||||
 | 
					import kotlinx.coroutines.runBlocking | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					object SourceVerificationHelp { | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**  | 
				
			||||||
 | 
					     * 获取书源验证结果 | 
				
			||||||
 | 
					     * 图片验证码 防爬 滑动验证码 点击字符 等等 | 
				
			||||||
 | 
					     */ | 
				
			||||||
 | 
					    fun getVerificationResult(source: BaseSource?, url: String, title: String, useBrowser: Boolean): String { | 
				
			||||||
 | 
					        source ?: throw NoStackTraceException("getVerificationResult parameter source cannot be null") | 
				
			||||||
 | 
					        return runBlocking { | 
				
			||||||
 | 
					            val key = "${source?.getKey() ?: ""}_verificationResult" | 
				
			||||||
 | 
					            CacheManager.delete(key) | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (!useBrowser) { | 
				
			||||||
 | 
					                appCtx.startActivity<VerificationCodeActivity> { | 
				
			||||||
 | 
					                    putExtra("imageUrl", url) | 
				
			||||||
 | 
					                    putExtra("sourceOrigin", source?.getKey()) | 
				
			||||||
 | 
					                } | 
				
			||||||
 | 
					            } else { | 
				
			||||||
 | 
					                startBrowser(source, url, title, true) | 
				
			||||||
 | 
					            } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var waitUserInput: Boolean = false | 
				
			||||||
 | 
					            while(CacheManager.get(key) == null) { | 
				
			||||||
 | 
					                if (!waitUserInput) { | 
				
			||||||
 | 
					                    AppLog.putDebug("等待返回验证结果...") | 
				
			||||||
 | 
					                    waitUserInput = true | 
				
			||||||
 | 
					                } | 
				
			||||||
 | 
					            } | 
				
			||||||
 | 
					            CacheManager.get(key)!!.let { | 
				
			||||||
 | 
					                if (it.isBlank()) { | 
				
			||||||
 | 
					                    throw NoStackTraceException("验证结果为空") | 
				
			||||||
 | 
					                } else { | 
				
			||||||
 | 
					                   it | 
				
			||||||
 | 
					                } | 
				
			||||||
 | 
					            } | 
				
			||||||
 | 
					       } | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** | 
				
			||||||
 | 
					     * 启动内置浏览器 | 
				
			||||||
 | 
					      @param saveResult 保存网页源代码到数据库 | 
				
			||||||
 | 
					     */ | 
				
			||||||
 | 
					    fun startBrowser(source: BaseSource?, url: String, title: String, saveResult: Boolean? = false) { | 
				
			||||||
 | 
					        source ?: throw NoStackTraceException("startBrowser parameter source cannot be null") | 
				
			||||||
 | 
					        appCtx.startActivity<WebViewActivity> { | 
				
			||||||
 | 
					            putExtra("title", title) | 
				
			||||||
 | 
					            putExtra("url", url) | 
				
			||||||
 | 
					            putExtra("sourceOrigin", source?.getKey()) | 
				
			||||||
 | 
					            putExtra("sourceVerificationEnable", saveResult) | 
				
			||||||
 | 
					            IntentData.put(url, source?.getHeaderMap(true)) | 
				
			||||||
 | 
					        } | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private fun checkActivityStatus(): Boolean { | 
				
			||||||
 | 
					        return true | 
				
			||||||
 | 
					    } | 
				
			||||||
 | 
					} | 
				
			||||||
					Loading…
					
					
				
		Reference in new issue