103 lines
3.1 KiB
Dart
103 lines
3.1 KiB
Dart
|
|
import 'package:novyronst/common/api/api_request.dart';
|
|
import 'package:novyronst/common/api/api_string.dart';
|
|
import 'package:novyronst/common/help/help_log.dart';
|
|
import 'package:novyronst/common/help/help_token.dart';
|
|
import 'package:novyronst/common/model/novyronst_user.dart';
|
|
import 'package:novyronst/common/model/register_model.dart';
|
|
|
|
class UserRequest {
|
|
|
|
static Future login() {
|
|
final body = <String, dynamic>{
|
|
"avator": '',
|
|
"email": '123456@qq.com',
|
|
"family_name": 'test1',
|
|
"platform": 'android',
|
|
"third_id": '32434',
|
|
};
|
|
return ApiRequest.post(ApiStringUser.login, data: body).then((value) {
|
|
HelpLog.print(value.data, tag: 'loginnnn');
|
|
});
|
|
}
|
|
|
|
static Future<RegisterModel?> register() {
|
|
return ApiRequest.post(ApiStringUser.register).then((value) {
|
|
if (value.isSuccess) {
|
|
return RegisterModel.fromJson(value.data['data']);
|
|
}
|
|
return null;
|
|
});
|
|
}
|
|
|
|
static Future<NovyronstUser?> getUserInfo() {
|
|
return ApiRequest.get(ApiStringUser.userInfo).then((value) {
|
|
if (value.isSuccess) {
|
|
HelpLog.print(value.data, tag: 'getUserInfo');
|
|
return NovyronstUser.fromJson(value.data['data']);
|
|
}
|
|
return null;
|
|
});
|
|
}
|
|
|
|
static Future eventCreateHistory({
|
|
required String shortPlayId,
|
|
required String videoId
|
|
}) {
|
|
// {"short_play_id": shortPlayId, "video_id": videoId}
|
|
Map<String, dynamic> params = {"short_play_id": shortPlayId, "video_id": videoId};
|
|
return ApiRequest.post(ApiStringUser.eventCreateHistory, data: params).then((value) {
|
|
HelpLog.print(value.data, tag: "eventCreateHis");
|
|
});
|
|
}
|
|
|
|
static Future eventEnterApp() {
|
|
return ApiRequest.post(ApiStringUser.eventUserEnterApp).then((value) {});
|
|
}
|
|
|
|
static Future<bool> eventOnline({String? oldToken}) {
|
|
String token = HelpToken().get();
|
|
if (token == '') return Future<bool>.value(false);
|
|
final body = <String, dynamic>{};
|
|
if (oldToken != null) body['token'] = oldToken;
|
|
return ApiRequest.post(ApiStringUser.eventUserOnline, data: body).then((value) {
|
|
return value.isSuccess;
|
|
});
|
|
}
|
|
|
|
static Future<bool> eventOLeaveApp({String? oldToken}) {
|
|
String token = HelpToken().get();
|
|
if (token == '') return Future<bool>.value(false);
|
|
final body = <String, dynamic>{};
|
|
if (oldToken != null) body['token'] = oldToken;
|
|
return ApiRequest.post(ApiStringUser.eventUserLeaveApp, data: body).then((value) {
|
|
return value.isSuccess;
|
|
});
|
|
}
|
|
|
|
// 上报播放时长
|
|
static Future eventPlaySeconds({
|
|
required int shortPlayId,
|
|
required int videoId,
|
|
required int seconds,
|
|
}) {
|
|
return ApiRequest.post(ApiStringUser.eventPlaySeconds, data: {
|
|
"short_play_id": shortPlayId,
|
|
"video_id": videoId,
|
|
"play_seconds": seconds,
|
|
}).then((value) {});
|
|
}
|
|
|
|
// 上报观看时长
|
|
static Future eventWatchTime({
|
|
required int shortPlayId,
|
|
required int seconds,
|
|
}) {
|
|
return ApiRequest.post(ApiStringUser.eventWatchTime, data: {
|
|
"short_play_id": shortPlayId,
|
|
// 时间戳的毫秒数
|
|
"request_id": DateTime.now().millisecondsSinceEpoch,
|
|
"duration": seconds,
|
|
}).then((value) {});
|
|
}
|
|
} |