AndroidアプリのコードにCaptchaを実装する必要がありますが、その方法がわかりません。
誰かがここで私を助けてくれますか?
SimpleCaptchaまたはJCaptchaを見てください。
恥知らずな自己宣伝ですが、私は他のすべての選択肢を嫌いでした。具体的には、それらはすべてネットワークベースであるということです。さて、私のものにはたくさんの作業などが必要であり、別の外部ソリューションを使用するほど安全ではないかもしれませんが、少なくとも使いやすく、いくつかのオプションがあります。
現在、GoogleはこのためのSafetyNetreCAPTCHAライブラリを提供しています。詳細については、こちら
をご覧ください。
以下は、reCaptchaを実装するための手順です。
dependencies { compile 'com.google.android.gms:play-services-safetynet:15.0.1' }
APIを使用する(Googleドキュメントの例)
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());
}
}
});
}