user_auth_repository.dart
3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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 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 {
try {
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;
} on DioException {
return null;
}
}
Future<dynamic> appleLogin(String userid, String authorizationCode, String identityToken) async {
try {
Response resp = await _appService.post(
'/api/v1/comm/user/applelogin',
{
"user": userid,
"authorizationCode": authorizationCode,
"identityToken": identityToken,
},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
///
/// {
/// "code": 1,
/// "data":"bxe userid" // 存在会返回
/// "error": "",
/// }
Future<dynamic> exchangeId(String userid) async {
try {
Response resp = await _appService.post(
'/api/v1/comm/user/exchangeid',
{
"userId": userid,
"type": "apple",
},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
///
/// {
/// "error": "",
/// "code": 0,
/// }
Future<dynamic> newBinding(String userid, String bxeUserId, String type) async {
try {
Response resp = await _appService.post(
'/api/v1/comm/user/newbinding',
{
"userId": userid,
"bxeUserId": bxeUserId,
"type": type,
},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
///
/// 查询绑定信息
///
/// 返回示例 {"cdoe":0,"data":{"appleId":"001161.5105e0b7b7b7429fabda11c8d28af432.0846","phone":"","unionId":"oCyks03FGEe1RfBMtKfZlMeLR31o"}}
///
Future<dynamic> binded(String userId) async {
try {
Response resp = await _appService.post(
'/api/v1/comm/user/binded',
{"userId": userId},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
Future<dynamic> unbind(String? userId, String? phone) async {
try {
final body = <String, dynamic>{};
if (userId != null && userId.isNotEmpty) {
body['userId'] = userId;
} else if (phone != null && phone.isNotEmpty) {
body['phone'] = phone;
}
Response resp = await _appService.post(
'/api/v1/comm/user/unbind',
body,
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException catch (e) {
debugPrint('unbind error: $e');
return null;
}
}
}