适用于 Flutter 的阿里云人机验证插件
支持滑动验证、智能验证(智能验证暂不支持刮刮卡等形式)。
将此添加到包的 pubspec.yaml 文件中:
dependencies:
flutter_aliyun_captcha: ^1.0.5
您可以从命令行安装软件包:
$ flutter packages get
导入 flutter_aliyun_captcha
import 'package:flutter_aliyun_captcha/flutter_aliyun_captcha.dart';
AliyunCaptchaButton
会根据其上层小部件的尺寸自适应,务必在上层小部件设置宽度和高度。
Container(
width: double.infinity,
height: 48,
margin: EdgeInsets.only(
top: 10,
bottom: 10,
left: 16,
right: 16,
),
child: AliyunCaptchaButton(
controller: _captchaController,
type: AliyunCaptchaType.slide, // 重要:请设置正确的类型
option: AliyunCaptchaOption(
appKey: '<appKey>',
scene: 'scene',
language: 'cn',
// 更多参数请参见:https://help.aliyun.com/document_detail/193141.html
),
customStyle: '''
.nc_scale {
background: #eeeeee !important;
/* 默认背景色 */
}
.nc_scale div.nc_bg {
background: #4696ec !important;
/* 滑过时的背景色 */
}
.nc_scale .scale_text2 {
color: #fff !important;
/* 滑过时的字体颜色 */
}
.errloading {
border: #ff0000 1px solid !important;
color: #ef9f06 !important;
}
''',
onSuccess: (dynamic data) {
// {"sig": "...", "token": "..."}
_addLog('onSuccess', data);
},
onFailure: (String failCode) {
_addLog('onFailure', 'failCode: $failCode');
},
onError: (String errorCode) {
_addLog('onError', 'errorCode: $errorCode');
},
),
)
AliyunCaptchaButton(
controller: _captchaController,
type: AliyunCaptchaType.smart, // 重要:请设置正确的类型
option: AliyunCaptchaOption(
appKey: '<appKey>',
scene: 'scene',
language: 'cn',
// 更多参数请参见:https://help.aliyun.com/document_detail/193144.html
),
onSuccess: (dynamic data) {
// {"sig": "...", "token": "..."}
_addLog('onSuccess', data);
},
onFailure: (String failCode) {
_addLog('onFailure', 'failCode: $failCode');
},
onError: (String errorCode) {
_addLog('onError', 'errorCode: $errorCode');
},
),
)
String sdkVersion = await AliyunCaptcha.sdkVersion;
MIT License
Copyright (c) 2021 LiJianying <lijy91@foxmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.