現(xiàn)在極驗不支持flutter版本哀峻,創(chuàng)建了一個插件呈枉,將原聲的極驗可以可以用在flutter上面,支持自定義驗證堪侯,支持iOS嚎尤、Android雙端。
效果如下:
源碼地址
https://github.com/Joker-388/flutter-geetest
集成
dependencies:
flutter_geetest:
git: https://github.com/Joker-388/flutter-geetest.git
接口
/// 極驗sdk版本
static Future<String> skdVersion() async {
final String version = await _channel.invokeMethod('getPlatformVersion');
return version;
}
/// 啟動極驗 <br></br>
/// String [api1]: api1,SDK代處理的第一次驗證接口 <br></br>
/// String [api2]: api2,SDK代處理的第二次驗證接口 <br></br>
/// String [gt]: gt伍宦,自行處理api1獲取的參數(shù) <br></br>
/// String [challenge]: challenge芽死,自行處理api1獲取的參數(shù) <br></br>
/// String [success]: success,自行處理api1獲取的參數(shù) <br></br>
/// <br></br>
/// {"msg":"xxxx", data:{"xxx":"xxx"}};
static Future<Map<String, dynamic>> launchGeetest({String api1 = "", String api2 = "", String gt = "", String challenge = "", int success = -1}) async {
var result = await _channel.invokeMethod('launchGeetest', {
'api1': api1,
'api2': api2,
'gt': gt,
'challenge': challenge,
'success': success,
});
return json.decode(result);
}
獲取極驗sdk版本
var version = await FlutterGeetest.skdVersion();
print("Geetest version $version");
使用極驗?zāi)J驗證
/// api1+api2
void _launchGeetest3() {
FlutterGeetest.launchGeetest(
api1: 'https://www.geetest.com/demo/gt/register-slide',
api2: 'https://www.geetest.com/demo/gt/validate-slide',
).then((data) {
print('Flutter_GeetestPlugin: data====>$data');
if (data["data"] == null) {
String errormsg = data["msg"];
_showSnackbarMsg('$errormsg');
return;
}
var result = data["data"];
_showSnackbarMsg('$result');
});
}
自定義 注冊步驟次洼,使用默認二次驗證
/// api1結(jié)果參數(shù)+api2
void _launchGeetest4() {
api1().then((data){
FlutterGeetest.launchGeetest(
gt: data['gt'],
challenge: data['challenge'],
success: data['success'],
api2: 'https://www.geetest.com/demo/gt/validate-slide',
).then((data) {
print('Flutter_GeetestPlugin: data====>$data');
if (data["data"] == null) {
String errormsg = data["msg"];
_showSnackbarMsg('$errormsg');
return;
}
var result = data["data"];
_showSnackbarMsg('$result');
});
});
}
自定義 二次驗證关贵,使用默認注冊步驟
/// 僅api1 , 返回結(jié)果自行進行二次接口校驗
void _launchGeetest1() {
FlutterGeetest.launchGeetest(
api1: 'https://www.geetest.com/demo/gt/register-slide',
).then((data) {
print('Flutter_GeetestPlugin: data====>$data');
if (data["data"] == null) {
String errormsg = data["msg"];
_showSnackbarMsg('$errormsg');
return;
}
api2(data["data"]).then((data){
print("api2: $data");
_showSnackbarMsg('$data');
});
});
}
自定義 注冊 和 二次驗證
/// 僅api1結(jié)果參數(shù)(gt,challenge,success),參數(shù)來自于自行接口獲取
void _launchGeetest2() {
api1().then((data){
print("!!!!! $data");
FlutterGeetest.launchGeetest(
gt: data['gt'],
challenge: data['challenge'],
success: data['success'],
).then((data) {
print('Flutter_GeetestPlugin: data====>$data');
if (data["data"] == null) {
String errormsg = data["msg"];
_showSnackbarMsg('$errormsg');
return;
}
api2(data["data"]).then((data){
print("api2: $data");
_showSnackbarMsg('$data');
});
});
});
}