Add universal captcha solver

This commit is contained in:
NerdNumber9
2019-04-18 20:38:04 -04:00
parent 852c1a423d
commit ec4af65c36
5 changed files with 147 additions and 75 deletions

View File

@ -14,7 +14,8 @@ import java.nio.charset.Charset
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
class AutoSolvingWebViewClient(activity: SolveCaptchaActivity,
source: CaptchaCompletionVerifier,
injectScript: String?)
injectScript: String?,
private val headers: Map<String, String>)
: BasicWebViewClient(activity, source, injectScript) {
override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? {
@ -31,6 +32,24 @@ class AutoSolvingWebViewClient(activity: SolveCaptchaActivity,
doc.toString().byteInputStream(Charset.forName("UTF-8")).buffered()
)
}
if(headers.isNotEmpty()) {
val response = activity.httpClient.newCall(request.toOkHttpRequest()
.newBuilder()
.apply {
headers.forEach { (n, v) -> addHeader(n, v) }
}
.build())
.execute()
return WebResourceResponse(
response.body()?.contentType()?.let { "${it.type()}/${it.subtype()}" },
response.body()?.contentType()?.charset()?.toString(),
response.code(),
response.message(),
response.headers().toMultimap().mapValues { it.value.joinToString(",") },
response.body()?.byteStream()
)
}
return super.shouldInterceptRequest(view, request)
}
}