user_auth_repository.dart 1.88 KB
import 'dart:io';

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

class UserAuthRepository {
  late final ApiService _appService;

  UserAuthRepository() {
    _appService = getIt<ApiService>(instanceName: 'appApiService');
  }

  ///
  /// {
  ///   "code": 0,
  ///   "error": "操作成功"
  /// }
  ///
  Future<dynamic> updateUser(String userid, String name, String nickName, String avatar) async {
    Response resp = await _appService.post(
      '/api/v1/comm/user/update',
      {
        "userid": userid,
        "name": name,
        "nickName": nickName,
        "avatar": avatar,
      },
    );
    return resp.statusCode == HttpStatus.ok ? resp.data : null;
  }

  Future<dynamic> appleLogin(String userid, String authorizationCode, String identityToken) async {
    Response resp = await _appService.post(
      '/api/v1/comm/user/applelogin',
      {
        "user": userid,
        "authorizationCode": authorizationCode,
        "identityToken": identityToken,
      },
    );
    return resp.statusCode == HttpStatus.ok ? resp.data : null;
  }

  ///
  /// {
  ///   "code":  1,
  ///   "data":"bxe userid" // 存在会返回
  ///   "error": "",
  /// }
  Future<dynamic> exchangeId(String userid) async {
    Response resp = await _appService.post(
      '/api/v1/comm/user/exchangeid',
      {
        "userId": userid,
        "type": "apple",
      },
    );
    return resp.statusCode == HttpStatus.ok ? resp.data : null;
  }

  ///
  /// {
  ///   "error": "",
  ///   "code":  0,
  /// }
  Future<dynamic> newBinding(String userid, String bxeUserId) async {
    Response resp = await _appService.post(
      '/api/v1/comm/user/newbinding',
      {
        "userId": userid,
        "bxeUserId": userid,
        "type": "apple",
      },
    );
    return resp.statusCode == HttpStatus.ok ? resp.data : null;
  }
}