wechat_auth_repository.dart 1.27 KB
import 'dart:io';

import 'package:appframe/config/locator.dart';
import 'package:appframe/services/api_service.dart';
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';

class WechatAuthRepository {
  late final ApiService _apiService;

  WechatAuthRepository() {
    _apiService = getIt<ApiService>(instanceName: 'bxeApiService');
  }

  Future<dynamic> codeToSk(String code) async {
    try {
      Response resp = await _apiService.post(
        '/login/applet/wkbxe/codeToSkByApp?version=1.0.0',
        {
          "appCode": "bxeapp",
          "params": {"code": code},
        },
      );

      debugPrint('登录结果: $resp');

      return resp.statusCode == HttpStatus.ok ? resp.data : null;
    } on DioException catch (e) {
      debugPrint('codeToSk网络异常: $e');
      return null;
    }
  }

  Future<dynamic> getTicket() async {
    try {
      Response resp = await _apiService.post(
        '/login/applet/wkbxe/getTicketByApp?version=1.0.0',
        {
          "appCode": "bxeapp",
          "params": {},
        },
      );

      debugPrint('获取ticket: $resp');

      return resp.statusCode == HttpStatus.ok ? resp.data : null;
    } on DioException catch (e) {
      debugPrint('getTicket网络异常: $e');
      return null;
    }
  }
}