time_based.service.dart 634 B

1234567891011121314151617181920212223242526272829
  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("GET: /config/verify?otp=$totpCode");
  9. final res = await _dio.get(
  10. "/config/verify",
  11. queryParameters: {"otp": totpCode},
  12. );
  13. if (res.data["code"] != 0) {
  14. LOGGER.w("验证失败:${res.data["message"]}");
  15. return false;
  16. }
  17. LOGGER.i("验证成功");
  18. return true;
  19. } catch (err) {
  20. LOGGER.e(err);
  21. }
  22. return false;
  23. }
  24. }