From 394f642d5cba76321d2f0fe59856c52cd5f73af6 Mon Sep 17 00:00:00 2001 From: orz12 Date: Sat, 17 Aug 2024 09:15:22 +0800 Subject: [PATCH] =?UTF-8?q?mod:=20=E7=BB=A7=E7=BB=AD=E8=A1=A5=E5=85=85?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E9=A3=8E=E6=8E=A7=E5=88=86=E6=94=AF=EF=BC=88?= =?UTF-8?q?=E5=B0=9A=E6=9C=AA=E5=AE=8C=E6=88=90=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/http/api.dart | 8 +++ lib/http/login.dart | 28 ++++++++++ lib/pages/login/controller.dart | 99 +++++++++++++++++++++++++-------- 3 files changed, 112 insertions(+), 23 deletions(-) diff --git a/lib/http/api.dart b/lib/http/api.dart index b01869f3..ff524e2f 100644 --- a/lib/http/api.dart +++ b/lib/http/api.dart @@ -522,6 +522,14 @@ class Api { static const String safeCenterSmsCode = '${HttpString.passBaseUrl}/x/safecenter/common/sms/send'; + /// type str loginTelCheck + /// code int 验证码内容 + /// tmp_code str 验证标记代码 来自数据处理中的解析出的参数tmp_token + /// request_id str 验证请求标记 来自数据处理中的解析出的参数requestId + /// captcha_key str 验证秘钥 来自申请验证码的captcha_key(data->captcha_key) + static const String safeCenterSmsVerify = + '${HttpString.passBaseUrl}/x/safecenter/login/tel/verify'; + /// 密码加密密钥 /// disable_rcmd /// local_id diff --git a/lib/http/login.dart b/lib/http/login.dart index 6266ba60..c2d4d3cf 100644 --- a/lib/http/login.dart +++ b/lib/http/login.dart @@ -415,4 +415,32 @@ class LoginHttp { }; } } + + static Future safeCenterSmsVerify( + {String? type, + required String code, + required String tmpCode, + required String requestId, + required String source, + required String captchaKey}) async { + var res = await Request().post(Api.safeCenterSmsVerify, data: { + 'type': type ?? 'loginTelCheck', + 'code': code, + 'tmp_code': tmpCode, + 'request_id': requestId, + 'source': source, + 'captcha_key': captchaKey, + }); + print(res); + if (res.data['code'] == 0) { + return {'status': true, 'data': res.data['data']}; + } else { + return { + 'status': false, + 'code': res.data['code'], + 'msg': res.data['message'], + 'data': res.data['data'] + }; + } + } } diff --git a/lib/pages/login/controller.dart b/lib/pages/login/controller.dart index 6f6fdf67..517c547d 100644 --- a/lib/pages/login/controller.dart +++ b/lib/pages/login/controller.dart @@ -316,32 +316,85 @@ class LoginPageController extends GetxController return; } Map accountInfo = { - "telVerify": safeCenterRes['data']['account_info']!['tel_verify']!, - "hide_tel": safeCenterRes['data']['account_info']!["hide_tel"]!, + "telVerify": safeCenterRes['data']['account_info']!['tel_verify'], + "bindTel": safeCenterRes['data']['account_info']!["bind_tel"], + "mailVerify": safeCenterRes['data']['account_info']!['mailVerify'], + "bindMail": safeCenterRes['data']['account_info']!["bind_mail"], }; - SmartDialog.showNotify( - msg: "将给你的手机号:${accountInfo['hide_tel']}发送短信验证码", - notifyType: NotifyType.alert, - alignment: Alignment.topCenter); + TextEditingController _textFieldController = TextEditingController(); + String captchaKey = ''; + Get.dialog(AlertDialog( + title: const Text("本次登录需要验证您的手机号"), + content: Column( + children:[ + Text(accountInfo['bindTel'] ?? '未能获取手机号'), + TextField( + controller: _textFieldController, + decoration: const InputDecoration(hintText: "请输入短信验证码"), + ),]), - var preCaptureRes = await LoginHttp.preCapture(); - if (!preCaptureRes['status']) { - SmartDialog.showToast("获取验证码失败,请尝试其它登录方式\n" - "(${preCaptureRes['code']}) ${preCaptureRes['msg']}"); - return; - } - String geeGt = preCaptureRes['data']['gee_gt']!; - String geeChallenge = preCaptureRes['data']['gee_challenge']; - captchaData.token = preCaptureRes['data']['recaptcha_token']!; + actions: [ + TextButton( + child: const Text("发送验证码 "), + onPressed: () async { + var preCaptureRes = await LoginHttp.preCapture(); + if (!preCaptureRes['status']) { + SmartDialog.showToast("获取验证码失败,请尝试其它登录方式\n" + "(${preCaptureRes['code']}) ${preCaptureRes['msg']}"); + return; + } + String geeGt = preCaptureRes['data']['gee_gt']!; + String geeChallenge = preCaptureRes['data']['gee_challenge']; + captchaData.token = preCaptureRes['data']['recaptcha_token']!; + + getCaptcha(geeGt, geeChallenge, () async { + var safeCenterSendSmsCodeRes = await LoginHttp.safeCenterSmsCode( + tmpCode: currentUri.queryParameters['tmp_token']!, + geeChallenge: geeChallenge, + geeSeccode: captchaData.seccode!, + geeValidate: captchaData.validate!, + recaptchaToken: captchaData.token!); + if (!safeCenterSendSmsCodeRes['status']) { + SmartDialog.showToast("发送短信验证码失败,请尝试其它登录方式\n" + "(${safeCenterSendSmsCodeRes['code']}) ${safeCenterSendSmsCodeRes['msg']}"); + return; + } + SmartDialog.showToast("短信验证码已发送,请查收"); + captchaKey = safeCenterSendSmsCodeRes['data']['captcha_key']; + }); + }, + ), + TextButton( + onPressed: Get.back, + child: const Text(" 取消"), + ), + TextButton( + onPressed: () async { + String? code = _textFieldController.text; + if (code.isEmpty) { + SmartDialog.showToast("请输入短信验证码"); + return; + } + var safeCenterSmsVerifyRes = await LoginHttp.safeCenterSmsVerify( + code: code, + tmpCode: currentUri.queryParameters['tmp_token']!, + requestId: currentUri.queryParameters['request_id']!, + source: currentUri.queryParameters['source']!, + captchaKey: captchaKey, + ); + if (!safeCenterSmsVerifyRes['status']) { + SmartDialog.showToast("验证短信验证码失败,请尝试其它登录方式\n" + "(${safeCenterSmsVerifyRes['code']}) ${safeCenterSmsVerifyRes['msg']}"); + return; + } + SmartDialog.showToast("验证成功,正在登录"); + // loginByPassword(); + }, + child: const Text("确认"), + ), + ], + )); - getCaptcha(geeGt, geeChallenge, () { - LoginHttp.safeCenterSmsCode( - tmpCode: currentUri.queryParameters['tmp_token']!, - geeChallenge: geeChallenge, - geeSeccode: captchaData.seccode!, - geeValidate: captchaData.validate!, - recaptchaToken: captchaData.token!); - }); return; }