Skip to content

Commit

Permalink
验证码破解
Browse files Browse the repository at this point in the history
  • Loading branch information
youyi-sizuru committed Oct 18, 2022
1 parent 8e172e2 commit 7936707
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import com.lifefighter.overlord.net.MihoyoSignRequest
import com.lifefighter.utils.*
import com.lifefighter.widget.adapter.DataBindingAdapter
import com.lifefighter.widget.adapter.ViewItemBinder
import kotlinx.coroutines.delay
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import java.util.concurrent.TimeUnit
import java.util.regex.Pattern

/**
* @author xzp
Expand Down Expand Up @@ -107,10 +109,7 @@ class MihoyoSignConfigActivity : BaseActivity<ActivityMihoyoSignConfigBinding>()
!it.todaySigned
}.forEach { account ->
try {
mihoyoInterface.signGenshin(
cookie = account.cookie,
request = MihoyoSignRequest(region = account.region, uid = account.uid)
)
signGenshin(mihoyoInterface, account)
toast("恭喜${account.nickname}签到成功")
} catch (e: MihoyoException) {
when (e.code) {
Expand Down Expand Up @@ -164,6 +163,44 @@ class MihoyoSignConfigActivity : BaseActivity<ActivityMihoyoSignConfigBinding>()
}
}

suspend fun signGenshin(mihoyoInterface: MihoyoInterface, account: MihoyoAccount) {
var retryTimes = 3
//验证码请求头
val codeMap = hashMapOf<String, String>()
while (retryTimes >= 0) {
retryTimes--
val result = mihoyoInterface.signGenshin(
cookie = account.cookie,
request = MihoyoSignRequest(region = account.region, uid = account.uid),
headerMap = codeMap
)
if (result.riskCode == 375) {
// 触发了验证码
result.challenge?.let {
codeMap["x-rpc-challenge"] = it
}
val validate = mihoyoInterface.getSignCode(
gt = result.gt,
challenge = result.challenge
).let {
val pattern = Pattern.compile("^.+\"validate\": \"(.+?)\".+$")
val matcher = pattern.matcher(it)
if(matcher.matches()){
matcher.group(1)
}else {
null
}
} ?: break
codeMap["x-rpc-validate"] = validate
codeMap["x-rpc-seccode"] = "$validate|jordan"
delay(3000)
} else {
return
}
}
throw MihoyoException(code = -1000, "验证码无法破解")
}

class MihoyoAccountItemModel(val account: MihoyoAccount) {
val name = "${account.nickname}(${account.regionName})"
val todaySigned = account.todaySigned
Expand All @@ -184,10 +221,7 @@ class SignWork(
!it.todaySigned
}.forEach {
try {
mihoyoInterface.signGenshin(
cookie = it.cookie,
request = MihoyoSignRequest(region = it.region, uid = it.uid)
)
signGenshin(mihoyoInterface, it)
notifySignResult(it, true)
updateAccountInfo(it)
} catch (e: MihoyoException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ package com.lifefighter.overlord.model
* @author xzp
* @created on 2021/3/9.
*/
class MihoyoData<T>(val retcode: Int? = null, val message: String? = null, val data: T? = null)
class MihoyoData<T>(
val retcode: Int? = null,
val status: String? = null,
val message: String? = null,
val data: T? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ import retrofit2.Converter
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.converter.scalars.ScalarsConverterFactory
import retrofit2.http.GET
import java.lang.reflect.Type
import java.math.BigInteger
import java.nio.ByteBuffer
import java.security.MessageDigest
import java.util.*
import java.util.concurrent.TimeUnit
import kotlin.random.Random

/**
* @author xzp
Expand All @@ -42,8 +44,9 @@ object AppInterfaceModule {
level = HttpLoggingInterceptor.Level.BODY
})
.build()
).addConverterFactory(MihoyoDataConverterFactory()).addConverterFactory(
GsonConverterFactory.create(JsonUtils.gson)
).addConverterFactory(MihoyoDataConverterFactory())
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create(JsonUtils.gson)
).baseUrl("https://api-takumi.mihoyo.com").build()
}
single {
Expand All @@ -65,11 +68,17 @@ object AppInterfaceModule {
class MihoyoRequestInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val oldRequest = chain.request()
if(oldRequest.url().host().contains("mihoyo").not()){
return chain.proceed(oldRequest)
}
val cookie = oldRequest.header("Cookie").orEmpty()
val requestBuilder = oldRequest.newBuilder()
requestBuilder.addHeader(
"User-Agent",
"Mozilla/5.0 (Linux; Android 10; MIX 2 Build/QKQ1.190825.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/83.0.4103.101 Mobile Safari/537.36 miHoYoBBS/2.35.2"
"Mozilla/5.0 (Linux; Android 10; MIX 2 Build/QKQ1.190825.002; wv) " +
"AppleWebKit/537.36 (KHTML, like Gecko)" +
" Version/4.0 Chrome/83.0.${Random.nextInt(1, 100)}.${Random.nextInt(100, 1000)}" +
" Mobile Safari/537.36 miHoYoBBS/2.35.${Random.nextInt(1, 10)}"
)
requestBuilder.addHeader(
"Referer",
Expand Down Expand Up @@ -120,8 +129,14 @@ class MihoyoDataConverterFactory : Converter.Factory() {
type: Type,
annotations: Array<Annotation>,
retrofit: Retrofit
): Converter<ResponseBody, *> {
return MihoyoDataConverter<Any>(type)
): Converter<ResponseBody, *>? {
return if(annotations.none {
it is GET && it.value.contains("geetest")
}) {
MihoyoDataConverter<Any>(type)
}else {
null
}
}
}

Expand All @@ -133,7 +148,7 @@ class MihoyoDataConverter<T>(private val type: Type) : Converter<ResponseBody, T
it.charStream(),
JsonUtils.newParameterizedType(MihoyoData::class.java, type)
) ?: throw JsonIOException("json result is null")
if (data.retcode != 0) {
if ((data.retcode == 0 || data.status == "success").not()) {
throw MihoyoException(data.retcode ?: -1, data.message.orEmpty())
}
data.data
Expand Down
23 changes: 20 additions & 3 deletions app/src/main/java/com/lifefighter/overlord/net/MihoyoInterface.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@ interface MihoyoInterface {
@POST("event/bbs_sign_reward/sign")
suspend fun signGenshin(
@Header("Cookie") cookie: String,
@Body request: MihoyoSignRequest
): Any
@Body request: MihoyoSignRequest,
@HeaderMap headerMap: Map<String, String>? = null
): MihoyoSignResult

@GET("https://api.geetest.com/ajax.php?&lang=zh-cn&pt=3&client_type=web_mobile&callback=geetest_1663984420850")
suspend fun getSignCode(
@Query("gt") gt: String?,
@Query("challenge") challenge: String?
): String
}

class MihoyoRoleListData(val list: List<MihoyoRole>? = null)
Expand Down Expand Up @@ -65,4 +71,15 @@ class MihoyoSignRequest(
@SerializedName("act_id") val actId: String = "e202009291139501",
val region: String,
val uid: String
)
)

class MihoyoSignResult(
val code: String? = null,
@SerializedName("risk_code")
val riskCode: Int? = null,
val gt: String? = null,
val challenge: String? = null
)


class MihoyoValidateResult(val validate: String? = null)

0 comments on commit 7936707

Please sign in to comment.