user_auth_repository.dart
5.07 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
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;
}
}
///
/// chargeCodes : bxe_vip
/// duration: durationType=1-天数|=2-月数|=3-yyyyMMdd|=4-学期数
/// durationType : 1.天|2.月|3.特定过期日期|4.学期|5.永久
/// totalFee: 经过计算后的实收价格,单位分
/// useCoin: 1.使用,0.不使用
///
Future<dynamic> createOrder(String userId, String tbxStuId, String chargeCodes, int duration, int durationType, int totalFee,
bool renew, String phone, String stuId, String ext, int useCoin, String deviceType) async {
try {
Response resp = await _appService.post(
'/api/v1/comm/user/buyvip',
{
"userId": userId,
"tbxStuId": tbxStuId,
"chargeCodes": chargeCodes,
"duration": duration,
"durationType": durationType,
"totalFee": totalFee,
"renew": renew,
"phone": phone,
"stuId": stuId,
"ext": ext,
"useCoin": useCoin,
"deviceType": deviceType
},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
// 检查ios的订单是否已经订阅
Future<dynamic> orderCheck(String userId,String receipt,String orderid, String platform,int isSandbox ) async {
try {
debugPrint('收据长度: ${receipt.length}');
debugPrint('收据前100字符: ${receipt.substring(0, receipt.length > 100 ? 100 : receipt.length)}');
Response resp = await _appService.post(
'/api/v1/comm/user/ordercheck',
{
"userId": userId,
"receipt": receipt,
"orderid":orderid,
"platform": platform,
"isSandbox":isSandbox,
},
);
return resp.statusCode == HttpStatus.ok ? resp.data : null;
} on DioException {
return null;
}
}
}