skywood/lib/global/client/event_client.dart

68 lines
2.1 KiB
Dart

import 'package:skywood/global/request/api_const.dart';
import 'package:skywood/global/request/app_request.dart';
import 'package:skywood/global/tool/sky_log.dart';
import 'package:skywood/utils/tools/token_manage.dart';
class EventClient {
static Future eventCreateHis({
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 AppRequest.post(ApiString.eventCreateHistory, data: params).then((value) {
SkyLog.print(value.data, tag: "eventCreateHis");
});
}
static Future eventEnterApp() {
return AppRequest.post(ApiString.eventUserEnterApp).then((value) {});
}
static Future<bool> eventOnline({String? oldToken}) {
String token = TokenManager().get();
if (token == '') return Future<bool>.value(false);
final body = <String, dynamic>{};
if (oldToken != null) body['token'] = oldToken;
return AppRequest.post(ApiString.eventUserOnline, data: body).then((value) {
return value.isSuccess;
});
}
static Future<bool> eventOLeaveApp({String? oldToken}) {
String token = TokenManager().get();
if (token == '') return Future<bool>.value(false);
final body = <String, dynamic>{};
if (oldToken != null) body['token'] = oldToken;
return AppRequest.post(ApiString.eventUserLeaveApp, data: body).then((value) {
return value.isSuccess;
});
}
// 上报播放时长
static Future eventPlaySeconds({
required int shortPlayId,
required int videoId,
required int seconds,
}) {
return AppRequest.post(ApiString.eventPlaySeconds, data: {
"short_play_id": shortPlayId,
"video_id": videoId,
"play_seconds": seconds,
}).then((value) {});
}
// 上报观看时长
static Future eventWatchTime({
required int shortPlayId,
required int seconds,
}) {
return AppRequest.post(ApiString.eventWatchTime, data: {
"short_play_id": shortPlayId,
// 时间戳的毫秒数
"request_id": DateTime.now().millisecondsSinceEpoch,
"duration": seconds,
}).then((value) {});
}
}