我已经成功实现了 Google SafetyNet API,甚至得到了成功的响应。问题是JWSResult
fromAttestationResponse
是一个散列字符串,而我的期望是得到一个 JSON 作为响应。
请问我需要先从哪里找问题?
这attest()
是调用的代码:
fun callSafetyNetAttentationApi(context: Activity, callback: SafetyNetCallback) {
if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS) {
val nonce: ByteArray? = getRequestNonce("Safety Net Sample: " + System.currentTimeMillis())
val client = SafetyNet.getClient(context)
nonce?.let {
val task: Task<AttestationResponse> = client.attest(it, BuildConfig.SAFETY_NET_KEY)
task.addOnSuccessListener { response -> safetyNetSuccess(response, callback) }
.addOnFailureListener { callback.isDeviceTrusted(false) }
} ?: kotlin.run {
callback.isDeviceTrusted(false)
}
} else {
MaterialDialog.Builder(context)
.title("The app cannot be used")
.content("Please update Google Play Services and try again.")
.cancelable(false)
.positiveText("Dismiss")
.onPositive { dialog, which -> context.finish() }
.show()
}
}