time_based.service.dart 728 B

12345678910111213141516171819202122232425262728293031
  1. import 'package:dio/dio.dart';
  2. import 'package:maxkey_flutter/utils.dart';
  3. class TimeBasedService {
  4. final Dio _dio;
  5. TimeBasedService(this._dio);
  6. Future<bool> verify({required String totpCode}) async {
  7. try {
  8. LOGGER.i("TimeBasedService.verify(): ");
  9. LOGGER.i("GET: /config/verify?otp=$totpCode");
  10. final res = await _dio.get(
  11. "/config/verify",
  12. queryParameters: {"otp": totpCode},
  13. );
  14. if (res.data["code"] != 0) {
  15. LOGGER.w("验证失败:${res.data["message"]}");
  16. return false;
  17. }
  18. LOGGER.i("验证成功");
  19. return true;
  20. } catch (err) {
  21. LOGGER.e("TimeBasedService.verify(): ");
  22. LOGGER.e(err);
  23. }
  24. return false;
  25. }
  26. }