行为验证 Android SDK提供给集成Android原生客户端开发的开发者使用, SDK不依赖任何第三方库。
环境需求
条目 |
|
开发目标 |
API 14+ |
开发环境 |
android studio |
demo依赖 |
okgo |
####资源下载
####配置
#####1.获取JAR包
通过git命令获取:
1 2 3 4
| //Step 1. Add the JitPack repository to your build file maven { url 'https://www.jitpack.io' } //Step 2. Add the dependency implementation 'com.github.VAPTCHA:VAPTCHA-android:1.0.0',{ exclude module: "okio" }
|
手动下载JAR包:
Github:vaptcha_android_libary
####2.studio导入
####模式分类
模式 |
type |
描述 |
嵌入式 |
embed |
自定义验证视图 在xml中直接引入 |
点击式 |
popup |
自定义按钮 在xml中直接引 |
隐藏式 |
invisible |
定义了java方法 在用户需要的地方直接调用 |
####manifest中加入加入权限: |
|
|
1 2 3 4
| //网络权限 <uses-permission android:name="android.permission.INTERNET"/> //获取当前网络状态 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
####代码示例
#####1. 嵌入式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| //在xml中直接引用并配置 <com.vaptcha.VaptchaView android:id="@+id/vaptchaView" android:layout_width="wrap_content" android:layout_height="wrap_content" app:vaptcha_scene="01" app:vaptcha_type="embed" app:vaptcha_vid="5af01666a485d42f244c7d0d" /> //初始化 并设置监听 VaptchaView vaptchaView = findViewById(R.id.vaptchaView); vaptchaView.setVaptchaListener(new vaptchaListener() { @Override public void onError() { // 验证失败 } @Override public void onExection() { // 验证异常 } @Override public void onSuccess(String token) { // 验证成功 拿到token tv_login.setEnabled(true); } }); //验证重置 vaptchaView.vaptchaReset();
|
参数说明
参数名 |
描述 |
|
vaptcha_type |
embed(嵌入式) |
必填 |
vaptcha_vid |
vaptcha获取到的vid |
必填 |
vaptcha_scene |
描述 |
必填 |
vaptcha_isOutAge |
true进入宕机模式 |
选填 |
vaptcha_outage_url |
宕机模式的服务器地址 |
选填 |
vaptcha_lang |
语言(简体中文 zh-Hans)(繁体中文 zh-Hant)(英文 en) |
选填 |
效果图
![嵌入式 效果图](https://upload-images.jianshu.io/upload_images/5439590-9161289dac3b1b02.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
#####2点击式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| <com.vaptcha.VaptchaView android:id="@+id/vaptchaButton" android:layout_width="match_parent" android:layout_height="wrap_content" app:vaptcha_color="#cccccc" app:vaptcha_scene="01" app:vaptcha_type="popup" app:vaptcha_vid="5af01666a485d42f244c7d0d" /> //初始化 并设置监听 vaptchaButton=mView.findViewById(R.id.vaptchaButton); vaptchaButton.setVaptchaListener(new vaptchaListener() { @Override public void onError() { // 验证失败 } @Override public void onExection() { // 验证异常 } @Override public void onSuccess(String token) { // 验证成功 拿到token } }); //验证重置 vaptchaButton.vaptchaReset();
|
参数说明
参数名 |
描述 |
|
vaptcha_type |
popup(点击式) |
必填 |
vaptcha_vid |
vaptcha获取到的vid |
必填 |
vaptcha_scene |
描述 |
必填 |
vaptcha_isOutAge |
true进入宕机模式 |
选填 |
vaptcha_outage_url |
宕机模式的服务器地址 |
选填 |
vaptcha_color |
按钮颜色 |
选填 |
vaptcha_lang |
语言(简体中文 zh-Hans)(繁体中文 zh-Hant)(英文 en) |
选填 |
效果图 |
|
|
![点击式 效果图](https://upload-images.jianshu.io/upload_images/5439590-7cfce4e493b722e4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) |
|
|
####3隐藏式 |
|
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| //初始化VaptchaView 并传入配置参数 VaptchaView hide_view =new VaptchaView(getContext(), "invisible", "5af01666a485d42f244c7d0d", "01"); //调起验证界面 hide_view.show(); //添加验证监听 hide_view.setVaptchaListener( new vaptchaListener() { @Override public void onError() { //验证错误 } @Override public void onExection() { //验证异常 } @Override public void onSuccess(String token) { //验证成功 } };);
|
参数说明
参数名 |
描述 |
|
Context |
上下文 |
必填 |
vaptcha_type |
invisible |
必填 |
vaptcha_vid |
vaptcha获取到的vid |
必填 |
vaptcha_scene |
描述 |
必填 |
vaptcha_isOutAge |
true进入宕机模式 |
选填 |
vaptcha_outage_url |
宕机模式的服务器地址 |
选填 |
vaptcha_lang |
语言(简体中文 zh-Hans)(繁体中文 zh-Hant)(英文 en) |
选填 |
效果图 |
|
|
![隐藏式 效果图](https://upload-images.jianshu.io/upload_images/5439590-64c7b605de715aca.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) |
|
|
以上为VAPTCHA SDK提供的三种验证方式,具体更多参数设置详见 Demo。