Skip to content

Commit f91880f

Browse files
committed
Update
1 parent 31e3070 commit f91880f

File tree

7 files changed

+56
-13
lines changed

7 files changed

+56
-13
lines changed

app/src/main/assets/captcha.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@
3737
product: 'bind'
3838
}, function(captcha) {
3939
captcha.onReady(function(){
40-
postMessage("challenge_change");
4140
captcha.showCaptcha();
4241
}).onSuccess(function(){
4342
var result = captcha.getValidate();
44-
postToken(result);
43+
postToken(JSON.stringify(result));
4544
}).onClose(function () {
4645
postMessage("gt_close");
4746
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package one.mixin.android.ui.landing
2+
3+
import com.google.gson.Gson
4+
import com.google.gson.JsonObject
5+
import com.google.gson.JsonSyntaxException
6+
import com.google.gson.annotations.SerializedName
7+
import one.mixin.android.util.GsonHelper
8+
9+
data class GTCaptcha4Result(
10+
@SerializedName("lot_number")
11+
val lotNumber: String?,
12+
@SerializedName("captcha_output")
13+
val captchaOutput: String?,
14+
@SerializedName("pass_token")
15+
val passToken: String?,
16+
@SerializedName("gen_time")
17+
val genTime: String?,
18+
)
19+
20+
object GTCaptcha4Utils {
21+
fun parseGTCaptchaResponse(json: String): GTCaptcha4Result? {
22+
return try {
23+
return GsonHelper.customGson.fromJson(json, GTCaptcha4Result::class.java)
24+
} catch (e: JsonSyntaxException) {
25+
e.printStackTrace()
26+
null
27+
}
28+
}
29+
}
30+

app/src/main/java/one/mixin/android/ui/landing/MobileFragment.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,11 @@ class MobileFragment: BaseFragment(R.layout.fragment_mobile) {
256256
} else if (captchaResponse.first.isH()) {
257257
verificationRequest.hCaptchaResponse = captchaResponse.second
258258
} else {
259-
// Todo
259+
val t = GTCaptcha4Utils.parseGTCaptchaResponse(captchaResponse.second)
260+
verificationRequest.lotNumber = t?.lotNumber
261+
verificationRequest.captchaOutput = t?.captchaOutput
262+
verificationRequest.passToken = t?.passToken
263+
verificationRequest.genTime = t?.genTime
260264
}
261265
}
262266
binding.continueBn.displayedChild = 1

app/src/main/java/one/mixin/android/ui/landing/MobileViewModel.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ internal constructor(
9898
}
9999

100100
suspend fun anonymousRequest(publicKeyHex: String, messageHex: String, signatureHex: String, hCaptchaResponse: String? = null, gRecaptchaResponse: String? = null, gtRecaptchaResponse: String? = null): MixinResponse<VerificationResponse> {
101-
// val gt = gtRecaptchaResponse?.let { GTCaptcha4Utils.parseGTCaptchaResponse(it) }
101+
val gt = gtRecaptchaResponse?.let { GTCaptcha4Utils.parseGTCaptchaResponse(it) }
102102
val r = accountRepository.verification(
103103
VerificationRequest(
104104
purpose = VerificationPurpose.ANONYMOUS_SESSION.name,
@@ -107,10 +107,10 @@ internal constructor(
107107
masterSignatureHex = signatureHex,
108108
hCaptchaResponse = hCaptchaResponse,
109109
gRecaptchaResponse = gRecaptchaResponse,
110-
// lotNumber = gt?.lotNumber,
111-
// captchaOutput = gt?.captchaOutput,
112-
// passToken = gt?.passToken,
113-
// genTime = gt?.genTime,
110+
lotNumber = gt?.lotNumber,
111+
captchaOutput = gt?.captchaOutput,
112+
passToken = gt?.passToken,
113+
genTime = gt?.genTime,
114114
)
115115
)
116116
return r

app/src/main/java/one/mixin/android/ui/landing/VerificationFragment.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,11 @@ class VerificationFragment : PinCodeFragment(R.layout.fragment_verification) {
319319
} else if (captchaResponse.first.isH()) {
320320
verificationRequest.hCaptchaResponse = captchaResponse.second
321321
} else {
322-
//Todo
322+
val t = GTCaptcha4Utils.parseGTCaptchaResponse(captchaResponse.second)
323+
verificationRequest.lotNumber = t?.lotNumber
324+
verificationRequest.captchaOutput = t?.captchaOutput
325+
verificationRequest.passToken = t?.passToken
326+
verificationRequest.genTime = t?.genTime
323327
}
324328
}
325329
viewModel.verification(verificationRequest)

app/src/main/java/one/mixin/android/ui/setting/delete/DeleteAccountFragment.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import one.mixin.android.ui.common.BaseFragment
2727
import one.mixin.android.ui.common.VerifyBottomSheetDialogFragment
2828
import one.mixin.android.ui.common.VerifyFragment
2929
import one.mixin.android.ui.home.MainActivity
30+
import one.mixin.android.ui.landing.GTCaptcha4Utils
3031
import one.mixin.android.ui.landing.MobileFragment.Companion.FROM_DELETE_ACCOUNT
3132
import one.mixin.android.ui.landing.VerificationFragment
3233
import one.mixin.android.ui.setting.LogoutPinBottomSheetDialogFragment
@@ -188,6 +189,11 @@ class DeleteAccountFragment : BaseFragment(R.layout.fragment_delete_account) {
188189
} else if (captchaResponse.first.isH()) {
189190
verificationRequest.hCaptchaResponse = captchaResponse.second
190191
} else if (captchaResponse.first.isGT()) {
192+
val t = GTCaptcha4Utils.parseGTCaptchaResponse(captchaResponse.second)
193+
verificationRequest.lotNumber = t?.lotNumber
194+
verificationRequest.captchaOutput = t?.captchaOutput
195+
verificationRequest.passToken = t?.passToken
196+
verificationRequest.genTime = t?.genTime
191197
}
192198
}
193199
binding.deleteCover.isVisible = true

app/src/main/java/one/mixin/android/widget/CaptchaView.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class CaptchaView(private val context: Context, private val callback: Callback)
166166

167167
webView.clearCache(true)
168168
webView.loadDataWithBaseURL(Constants.API.DOMAIN, html, "text/html", "UTF-8", null)
169-
// runOnUiThread(stopWebViewRunnable, WEB_VIEW_TIME_OUT)
169+
runOnUiThread(stopWebViewRunnable, WEB_VIEW_TIME_OUT)
170170
}
171171
}
172172

@@ -181,9 +181,9 @@ class CaptchaView(private val context: Context, private val callback: Callback)
181181
fun postMessage(
182182
@Suppress("UNUSED_PARAMETER") value: String,
183183
) {
184-
Timber.e("postMessage: $value")
185-
// cancelRunOnUiThread(stopWebViewRunnable)
186-
// runOnUiThread(stopWebViewRunnable)
184+
if (value.isBlank()) return
185+
cancelRunOnUiThread(stopWebViewRunnable)
186+
runOnUiThread(stopWebViewRunnable)
187187
}
188188

189189
@Suppress("unused")

0 commit comments

Comments
 (0)