我需要在我的Android应用程序代码中实现验证码,但不知道如何着手。
请问有人可以帮我吗?
可以看看SimpleCaptcha或JCaptcha。
JCaptcha
可以肯定。我不知道 SimpleCaptcha
,但它应该也可以。 - Amokrane Chentir我很不要脸地自荐一下,但我讨厌其他所有的选择,特别是它们都是基于网络的。现在,我确定我的解决方案需要大量的工作等,并且可能没有使用其他外部解决方案那么安全,但至少它容易使用并具有一些选项。
dependencies {
compile 'com.google.android.gms:play-services-safetynet:15.0.1'
}
Use API(example from google documentation)
public void onClick(View v) {
SafetyNet.getClient(this).verifyWithRecaptcha(YOUR_API_SITE_KEY)
.addOnSuccessListener((Executor) this,
new OnSuccessListener<SafetyNetApi.RecaptchaTokenResponse>() {
@Override
public void onSuccess(SafetyNetApi.RecaptchaTokenResponse response) {
// Indicates communication with reCAPTCHA service was
// successful.
String userResponseToken = response.getTokenResult();
if (!userResponseToken.isEmpty()) {
// Validate the user response token using the
// reCAPTCHA siteverify API.
}
}
})
.addOnFailureListener((Executor) this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
if (e instanceof ApiException) {
// An error occurred when communicating with the
// reCAPTCHA service. Refer to the status code to
// handle the error appropriately.
ApiException apiException = (ApiException) e;
int statusCode = apiException.getStatusCode();
Log.d(TAG, "Error: " + CommonStatusCodes
.getStatusCodeString(statusCode));
} else {
// A different, unknown type of error occurred.
Log.d(TAG, "Error: " + e.getMessage());
}
}
});
}