Skip to content

Commit

Permalink
重写登陆逻辑、新增视频异常验证
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Nov 10, 2024
1 parent 9a7dab5 commit 2277d73
Show file tree
Hide file tree
Showing 13 changed files with 299 additions and 533 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

340 changes: 0 additions & 340 deletions .idea/other.xml

This file was deleted.

32 changes: 6 additions & 26 deletions app/src/main/java/github/zerorooot/nap511/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class MainActivity : ComponentActivity() {
R.drawable.baseline_cloud_24 to "我的文件",
R.drawable.baseline_cloud_download_24 to "离线下载",
R.drawable.baseline_cloud_done_24 to "离线列表",
// R.drawable.baseline_add_moderator_24 to "验证账号",
// R.drawable.baseline_add_moderator_24 to "验证video账号",
R.drawable.baseline_web_24 to "网页版",
R.drawable.ic_baseline_delete_24 to "回收站",
R.drawable.baseline_settings_24 to "高级设置",
Expand Down Expand Up @@ -260,6 +260,9 @@ class MainActivity : ComponentActivity() {
"https://captchaapi.115.com/?ac=security_code&type=web&cb=Close911_" + System.currentTimeMillis()
CaptchaWebViewScreen()
}
"验证video账号" -> {
CaptchaVideoWebViewScreen()
}

"退出应用" -> ExitApp()
"captchaWebView" -> CaptchaWebViewScreen()
Expand Down Expand Up @@ -289,8 +292,8 @@ class MainActivity : ComponentActivity() {
if (it != "") {
val replace = it.replace(" ", "").replace("[\r\n]".toRegex(), "");
thread {
val checkLogin = checkLogin(replace)
val message = if (checkLogin == "") {
val checkLogin = App().checkLogin(replace)
val message = if (checkLogin == "0") {
"登录失败~,请重试"
} else {
DataStoreUtil.putData(ConfigUtil.cookie, replace)
Expand Down Expand Up @@ -333,29 +336,6 @@ class MainActivity : ComponentActivity() {
"刷新文件" -> fileViewModel.refresh()
}
}

private fun checkLogin(cookie: String): String {
val url =
"https://passportapi.115.com/app/1.0/web/1.0/check/sso?_${System.currentTimeMillis() / 1000}"
val okHttpClient = OkHttpClient()
val request: Request = Request.Builder().url(url).addHeader("cookie", cookie)
.addHeader("Content-Type", "application/json; Charset=UTF-8").addHeader(
"User-Agent",
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36 115Browser/23.9.3.6"
).get().build()
val body = okHttpClient.newCall(request).execute().body
val uid = run {
val string = body.string()
try {
Gson().fromJson(
string, LoginBean::class.java
).data.user_id
} catch (e: Exception) {
""
}
}
return uid
}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package github.zerorooot.nap511.screen

import android.annotation.SuppressLint
import android.net.UrlQuerySanitizer
import android.webkit.CookieManager
import android.webkit.URLUtil
import android.webkit.WebResourceResponse
import android.webkit.WebSettings
import android.webkit.WebView
Expand All @@ -27,6 +29,7 @@ import com.acsbendi.requestinspectorwebview.RequestInspectorWebViewClient
import com.acsbendi.requestinspectorwebview.WebViewRequest
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import github.zerorooot.nap511.MainActivity
import github.zerorooot.nap511.R
import github.zerorooot.nap511.activity.OfflineTaskWorker
import github.zerorooot.nap511.bean.LoginBean
Expand All @@ -37,6 +40,9 @@ import github.zerorooot.nap511.util.DataStoreUtil
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
import java.io.InputStreamReader
import java.io.StringBufferInputStream
import kotlin.concurrent.thread


@SuppressLint("SetJavaScriptEnabled")
Expand Down Expand Up @@ -158,42 +164,34 @@ fun loginWebViewClient(webView: WebView): WebViewClient {
view: WebView,
webViewRequest: WebViewRequest
): WebResourceResponse? {
val loginUrlVip = "https://passportapi.115.com/app/1.0/web/1.0/login/vip"
if (loginUrlVip == webViewRequest.url) {
val httpClient = OkHttpClient()
val a = Request.Builder()
.url(loginUrlVip)
.method("POST", webViewRequest.body.toRequestBody())
val headerMap = mapOf(
"sec-ch-ua-platform" to "\"Linux\"",
"sec-ch-ua" to "\"Not A(Brand\";v=\"99\", \"Google Chrome\";v=\"121\", \"Chromium\";v=\"121\"",
"sec-ch-ua-mobile" to "?0",
"user-agent" to "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
)
webViewRequest.headers.forEach { (t, u) -> a.addHeader(t, u) }
headerMap.forEach { (t, u) ->
a.removeHeader(t)
a.addHeader(t, u)
}
val response = httpClient.newCall(a.build()).execute()
val body = response.body.string()
val loginBean = Gson().fromJson(body, LoginBean::class.java)
val text = if (loginBean.state == 0) {
//error
loginBean.message
} else {
val cookie = loginBean.data.cookie.toString()
DataStoreUtil.putData(ConfigUtil.cookie, cookie)
DataStoreUtil.putData(ConfigUtil.uid, loginBean.data.user_id)
App.cookie = cookie
App.gesturesEnabled = true
"登陆成功~,请重启应用!"
val url = webViewRequest.url
if (url.startsWith("https://webapi.115.com/label/list")) {
var message = "登录失败~,请重试"
var cookie = webViewRequest.headers["cookie"]
if (cookie == null) {
App.instance.toast(message)
return super.shouldInterceptRequest(view, webViewRequest)
}
App.instance.toast(text)
//USERSESSIONID=xx; UID=xx; CID=xx; SEID=xx; PHPSESSID=xx; acw_tc=xx; UID=xx; CID=xx; SEID=xx
val regex = Regex("(UID=\\w+; CID=\\w+; SEID=\\w+)")
val matches = regex.findAll(cookie).map { it.value }.toList()
// thread {
// val c1 = App().checkLogin(matches[0].replace(" ", ""))
// val c2 = App().checkLogin(matches[1].replace(" ", ""))
// println()
// }
message = "登陆成功,请重启应用!"

cookie = matches[1].replace(" ", "")
val uid = UrlQuerySanitizer(url).getValue("user_id")
DataStoreUtil.putData(ConfigUtil.cookie, cookie)
DataStoreUtil.putData(ConfigUtil.uid, uid)
App.cookie = cookie
App.gesturesEnabled = true
App.instance.toast(message)
}
return null
return super.shouldInterceptRequest(view, webViewRequest)
}

}

}
Expand All @@ -204,6 +202,7 @@ fun CaptchaWebViewScreen() {
App.cookie.split(";").forEach { a ->
cookieManager.setCookie("https://captchaapi.115.com", a)
cookieManager.setCookie("https://webapi.115.com", a)
cookieManager.setCookie("https://webapi.115.com/user/captcha", a)
}
cookieManager.flush()
BaseWebViewScreen(
Expand All @@ -217,6 +216,24 @@ fun CaptchaWebViewScreen() {

}

@Composable
fun CaptchaVideoWebViewScreen() {
val cookieManager = CookieManager.getInstance()
App.cookie.split(";").forEach { a ->
cookieManager.setCookie("https://v.anxia.com/captchaapi/", a)
cookieManager.setCookie("https://v.anxia.com/webapi/user/captcha", a)
}
cookieManager.flush()
BaseWebViewScreen(
titleText = "验证码",
topAppBarActionButtonOnClick = {
App.instance.openDrawerState()
},
webViewClient = { captchaWebViewClient(it) },
loadUrl = "https://v.anxia.com/captchaapi/?ac=security_code&client=web&type=web&ctype=web&cb=Close911_" + System.currentTimeMillis()
)

}

fun captchaWebViewClient(webView: WebView): WebViewClient {
return object : RequestInspectorWebViewClient(webView) {
Expand All @@ -232,7 +249,7 @@ fun captchaWebViewClient(webView: WebView): WebViewClient {
webViewRequest.headers.forEach { (t, u) -> a.addHeader(t, u) }
//移除web添加的cookie
a.removeHeader("cookie")
a.addHeader("cookie",App.cookie)
a.addHeader("cookie", App.cookie)

val response = httpClient.newCall(a.build()).execute()
val string = response.body.string()
Expand All @@ -242,7 +259,11 @@ fun captchaWebViewClient(webView: WebView): WebViewClient {
App.instance.toast("验证账号成功~,重新添加链接中.......")
}
}
return null

if (webViewRequest.url.startsWith("https://v.anxia.com/webapi/user/captcha")) {
return super.shouldInterceptRequest(view, webViewRequest)
}
return super.shouldInterceptRequest(view, webViewRequest)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import github.zerorooot.nap511.screenitem.RecycleCellItem
import github.zerorooot.nap511.util.App
import github.zerorooot.nap511.util.ConfigUtil
import github.zerorooot.nap511.util.DataStoreUtil
import github.zerorooot.nap511.viewmodel.RecycleViewModel

@OptIn(ExperimentalMaterialApi::class, ExperimentalFoundationApi::class)
@Composable
fun RecycleScreen(recycleViewModel: RecycleViewModel) {
recycleViewModel.getRecycleFileList()
var deleteIndex by remember {
mutableStateOf(-1)
mutableIntStateOf(-1)
}
val refreshing by recycleViewModel.isRefreshing.collectAsState()
val recycleFileList = recycleViewModel.recycleFileList
Expand All @@ -48,6 +50,8 @@ fun RecycleScreen(recycleViewModel: RecycleViewModel) {

RecyclePasswordDialog(recycleViewModel) {
if (it != "") {
DataStoreUtil.putData(ConfigUtil.password, it)

if (deleteIndex == -1) {
recycleViewModel.deleteAll()
} else {
Expand Down
26 changes: 26 additions & 0 deletions app/src/main/java/github/zerorooot/nap511/util/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ import androidx.compose.material3.DrawerState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import com.google.gson.Gson
import github.zerorooot.nap511.bean.LoginBean
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.Request

class App : Application() {
companion object {
Expand Down Expand Up @@ -54,6 +58,28 @@ class App : Application() {
}

}
fun checkLogin(cookie: String): String {
val url =
"https://passportapi.115.com/app/1.0/web/1.0/check/sso?_${System.currentTimeMillis() / 1000}"
val okHttpClient = OkHttpClient()
val request: Request = Request.Builder().url(url).addHeader("cookie", cookie)
.addHeader("Content-Type", "application/json; Charset=UTF-8").addHeader(
"User-Agent",
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36 115Browser/23.9.3.6"
).get().build()
val body = okHttpClient.newCall(request).execute().body
val uid = run {
val string = body.string()
try {
Gson().fromJson(
string, LoginBean::class.java
).data.user_id
} catch (e: Exception) {
"0"
}
}
return uid
}

fun closeDrawerState() {
if (isScopeInitialized()) {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '8.1.4' apply false
id 'com.android.application' version '8.3.2' apply false
id 'com.android.library' version '8.1.4' apply false
id 'org.jetbrains.kotlin.android' version '1.9.0' apply false
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 4 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Sat Jan 21 12:59:30 CST 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 2277d73

Please sign in to comment.