android xamarin 中的 reCaptcha [英] reCaptcha in android xamarin

查看:107
本文介绍了android xamarin 中的 reCaptcha的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Xamarin 安卓应用中实现验证码.我掌握了这个 integrate googlesAndroid 中的 reCaptcha 验证.但它是一个原生的android项目.我还发现了 this,但我是无法使其工作.我收到 无法检查兼容性 警报.API SafetyNetClass.SafetyNetApi.AttestAsync 返回错误.不知道为什么.

I would like to implement captcha in Xamarin android app. I got hold of this integrate googles reCaptcha validation in Android. But its a native android project. I also found this, but I am unable to make it work. I am getting Failed to Check Compatibility alert. The API SafetyNetClass.SafetyNetApi.AttestAsync is returning an error. Not sure why.

有没有其他方法可以进行验证码验证.任何帮助将不胜感激.

Is there any other way to go about captcha validation. Any help would be appreciated.

推荐答案

为了使用 SafetyNetApi 进行 reCaptcha 验证,您需要:

In order to use the SafetyNetApi to do reCaptcha validation you need to:

  • 将您的 minSdkVersion 设置为 14 或更高
  • 确保在您的 SDK 工具中包含 Google Repository
  • 安装 Xamarin.GooglePlayServices.SafetyNet
  • reCAPTCHA Android 注册站点中签署您的应用程序包名称并获取您的站点密钥和密钥
  • Set your minSdkVersion to 14 or higher
  • Make sure you include Google Repository in your SDK tools
  • Install Xamarin.GooglePlayServices.SafetyNet package
  • Sign your app package name in reCAPTCHA Android signup site and get your Site key and Secret key

在此之后您启动验证码验证:

After this you launch the verification of the captcha:

try
{
    var response = await SafetyNetClass.GetClient(this.context).VerifyWithRecaptchaAsync("YOUR_API_SITE_KEY");
    if (!string.IsNullOrEmpty(response.TokenResult))
    {
        // Validate the user response token using the
        // reCAPTCHA siteverify API.
    }
}
catch(Exception ex)
{
    // Handle exception
    throw ex;
}

获取token结果不为空后,需要使用reCAPTCHA siteverify API进行验证.这里是您需要使用 Secret key 的地方.

After you get the token result not null, you need to verify it using the reCAPTCHA siteverify API. Here is where you need to use the Secret key.

在与 reCaptcha 服务通信时注意错误处理.您可以通过以下链接查看更多相关信息.

Pay attention to error handling when communicating with the reCaptcha service. You can check more about this following the links below.

更多信息:

  • https://developer.android.com/training/safetynet/recaptcha#validate-response
  • https://developers.google.com/recaptcha/docs/verify
  • http://android-er.blogspot.com/2017/06/example-using-safetynet-recaptcha-api.html (careful here because some of the methods used here are obsolete)

这篇关于android xamarin 中的 reCaptcha的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆