update msg api (#375)

This commit is contained in:
My-Responsitories
2025-03-03 09:23:19 +00:00
committed by GitHub
parent 432c5133e6
commit d5a244ce7f
7 changed files with 57 additions and 133 deletions

View File

@@ -468,12 +468,9 @@ class Api {
static const String msgFeedAt = '/x/msgfeed/at'; static const String msgFeedAt = '/x/msgfeed/at';
//https://api.bilibili.com/x/msgfeed/like?platform=web&build=0&mobi_app=web //https://api.bilibili.com/x/msgfeed/like?platform=web&build=0&mobi_app=web
static const String msgFeedLike = '/x/msgfeed/like'; static const String msgFeedLike = '/x/msgfeed/like';
//https://message.bilibili.com/x/sys-msg/query_user_notify?csrf=xxxx&csrf=xxxx&page_size=20&build=0&mobi_app=web //https://message.bilibili.com/x/sys-msg/query_notify_list?page_size=20&cursor=xxx
static const String msgSysUserNotify = static const String msgSysNotify =
'${HttpString.messageBaseUrl}/x/sys-msg/query_user_notify'; '${HttpString.messageBaseUrl}/x/sys-msg/query_notify_list';
//https://message.bilibili.com/x/sys-msg/query_unified_notify?csrf=xxxx&csrf=xxxx&page_size=10&build=0&mobi_app=web
static const String msgSysUnifiedNotify =
'${HttpString.messageBaseUrl}/x/sys-msg/query_unified_notify';
// 系统信息光标更新(已读标记) // 系统信息光标更新(已读标记)
//https://message.bilibili.com/x/sys-msg/update_cursor?csrf=xxxx&csrf=xxxx&cursor=1705288500000000000&has_up=0&build=0&mobi_app=web //https://message.bilibili.com/x/sys-msg/update_cursor?csrf=xxxx&csrf=xxxx&cursor=1705288500000000000&has_up=0&build=0&mobi_app=web

View File

@@ -9,37 +9,4 @@ class HttpString {
static const String dynamicShareBaseUrl = 'https://t.bilibili.com'; static const String dynamicShareBaseUrl = 'https://t.bilibili.com';
static const String spaceBaseUrl = 'https://space.bilibili.com'; static const String spaceBaseUrl = 'https://space.bilibili.com';
static const String sponsorBlockBaseUrl = 'https://www.bsbsb.top'; static const String sponsorBlockBaseUrl = 'https://www.bsbsb.top';
static const List<int> validateStatusCodes = [
302,
304,
307,
400,
401,
403,
404,
405,
409,
412,
500,
503,
504,
509,
616,
617,
625,
626,
628,
629,
632,
643,
650,
652,
658,
662,
688,
689,
701,
799,
8888
];
} }

View File

@@ -16,6 +16,9 @@ class MsgHttp {
var res = await Request().get(Api.msgFeedReply, queryParameters: { var res = await Request().get(Api.msgFeedReply, queryParameters: {
'id': cursor == -1 ? null : cursor, 'id': cursor == -1 ? null : cursor,
'reply_time': cursorTime == -1 ? null : cursorTime, 'reply_time': cursorTime == -1 ? null : cursorTime,
'platform': 'android',
'mobi_app': 'android',
'build': '8350200',
}); });
if (res.data['code'] == 0) { if (res.data['code'] == 0) {
return { return {
@@ -35,6 +38,9 @@ class MsgHttp {
var res = await Request().get(Api.msgFeedAt, queryParameters: { var res = await Request().get(Api.msgFeedAt, queryParameters: {
'id': cursor == -1 ? null : cursor, 'id': cursor == -1 ? null : cursor,
'at_time': cursorTime == -1 ? null : cursorTime, 'at_time': cursorTime == -1 ? null : cursorTime,
'platform': 'android',
'mobi_app': 'android',
'build': '8350200',
}); });
if (res.data['code'] == 0) { if (res.data['code'] == 0) {
return { return {
@@ -54,6 +60,9 @@ class MsgHttp {
var res = await Request().get(Api.msgFeedLike, queryParameters: { var res = await Request().get(Api.msgFeedLike, queryParameters: {
'id': cursor == -1 ? null : cursor, 'id': cursor == -1 ? null : cursor,
'like_time': cursorTime == -1 ? null : cursorTime, 'like_time': cursorTime == -1 ? null : cursorTime,
'platform': 'android',
'mobi_app': 'android',
'build': '8350200',
}); });
if (res.data['code'] == 0) { if (res.data['code'] == 0) {
return { return {
@@ -69,31 +78,10 @@ class MsgHttp {
} }
} }
static Future msgFeedSysUserNotify() async { static Future msgFeedNotify({int cursor = -1, int pageSize = 20}) async {
String csrf = await Request.getCsrf(); var res = await Request().get(Api.msgSysNotify, queryParameters: {
var res = await Request().get(Api.msgSysUserNotify, queryParameters: { 'cursor': cursor == -1 ? null : cursor,
'csrf': csrf, 'page_size': pageSize,
'page_size': 20,
});
if (res.data['code'] == 0) {
return {
'status': true,
'data': res.data['data'],
};
} else {
return {
'status': false,
'date': [],
'msg': res.data['message'],
};
}
}
static Future msgFeedSysUnifiedNotify() async {
String csrf = await Request.getCsrf();
var res = await Request().get(Api.msgSysUnifiedNotify, queryParameters: {
'csrf': csrf,
'page_size': 10,
}); });
if (res.data['code'] == 0) { if (res.data['code'] == 0) {
return { return {

View File

@@ -1,27 +1,3 @@
class MsgFeedSysMsg {
List<SystemNotifyList>? systemNotifyList;
MsgFeedSysMsg({this.systemNotifyList});
MsgFeedSysMsg.fromJson(Map<String, dynamic> json) {
if (json['system_notify_list'] != null) {
systemNotifyList = <SystemNotifyList>[];
json['system_notify_list'].forEach((v) {
systemNotifyList!.add(SystemNotifyList.fromJson(v));
});
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
if (systemNotifyList != null) {
data['system_notify_list'] =
systemNotifyList!.map((v) => v.toJson()).toList();
}
return data;
}
}
class SystemNotifyList { class SystemNotifyList {
int? id; int? id;
int? cursor; int? cursor;

View File

@@ -5,38 +5,33 @@ import 'package:PiliPlus/http/msg.dart';
import '../../../models/msg/msgfeed_sys_msg.dart'; import '../../../models/msg/msgfeed_sys_msg.dart';
class SysMsgController extends GetxController { class SysMsgController extends GetxController {
static const pageSize = 20;
RxList<SystemNotifyList> msgFeedSysMsgList = <SystemNotifyList>[].obs; RxList<SystemNotifyList> msgFeedSysMsgList = <SystemNotifyList>[].obs;
bool isLoading = false; bool isLoading = false;
int cursor = -1; int cursor = -1;
int cursorTime = -1;
bool isEnd = false; bool isEnd = false;
Future queryMsgFeedSysMsg() async { Future queryMsgFeedSysMsg() async {
if (isLoading) return; if (isLoading) return;
isLoading = true; isLoading = true;
var resUserNotify = await MsgHttp.msgFeedSysUserNotify(); final res = await MsgHttp.msgFeedNotify(cursor: cursor, pageSize: pageSize);
var resUnifiedNotify = await MsgHttp.msgFeedSysUnifiedNotify();
isLoading = false; isLoading = false;
List<SystemNotifyList> systemNotifyList = []; if (res['status']) {
if (resUserNotify['status']) { final data = (res['data'] as List)
MsgFeedSysMsg data = MsgFeedSysMsg.fromJson(resUserNotify['data']); .map((i) => SystemNotifyList.fromJson(i))
if (data.systemNotifyList != null) { .toList();
systemNotifyList.addAll(data.systemNotifyList!); isEnd = data.length + 1 < pageSize; // data.length会比pageSize小1
} if (data.isNotEmpty) {
} if (cursor == -1) {
if (resUnifiedNotify['status']) { msgFeedSysMsgList.assignAll(data);
MsgFeedSysMsg data = MsgFeedSysMsg.fromJson(resUnifiedNotify['data']);
if (data.systemNotifyList != null) {
systemNotifyList.addAll(data.systemNotifyList!);
}
}
if (systemNotifyList.isNotEmpty) {
systemNotifyList.sort((a, b) => b.cursor!.compareTo(a.cursor!));
msgFeedSysMsgList.assignAll(systemNotifyList);
msgSysUpdateCursor(msgFeedSysMsgList.first.cursor!);
} else { } else {
SmartDialog.showToast( msgFeedSysMsgList.addAll(data);
"UserNotify: ${resUserNotify['msg']} UnifiedNotify: ${resUnifiedNotify['msg']}"); }
cursor = data.last.cursor ?? -1;
msgSysUpdateCursor(msgFeedSysMsgList.first.cursor!);
}
} else {
SmartDialog.showToast(res['msg']);
} }
} }
@@ -58,7 +53,6 @@ class SysMsgController extends GetxController {
Future onRefresh() async { Future onRefresh() async {
cursor = -1; cursor = -1;
cursorTime = -1;
queryMsgFeedSysMsg(); queryMsgFeedSysMsg();
} }

View File

@@ -16,6 +16,7 @@ import 'utils.dart';
class PiliScheme { class PiliScheme {
static late AppLinks appLinks; static late AppLinks appLinks;
static StreamSubscription? listener; static StreamSubscription? listener;
static final uriDigitRegExp = RegExp(r'/(\d+)');
static Future<void> init() async { static Future<void> init() async {
// Register our protocol only on Windows platform // Register our protocol only on Windows platform
@@ -67,19 +68,19 @@ class PiliScheme {
return true; return true;
case 'pgc': case 'pgc':
// bilibili://pgc/season/ep/123456?h5_awaken_params=random // bilibili://pgc/season/ep/123456?h5_awaken_params=random
String? id = RegExp(r'/(\d+)').firstMatch(path)?.group(1); String? id = uriDigitRegExp.firstMatch(path)?.group(1);
if (id != null) { if (id != null) {
bool isEp = path.contains('/ep/'); bool isEp = path.contains('/ep/');
Utils.viewBangumi( Utils.viewBangumi(
seasonId: isEp ? null : id, seasonId: isEp ? null : id,
epId: isEp ? id : null, epId: isEp ? id : null,
); progress: uri.queryParameters['start_progress']);
return true; return true;
} }
return false; return false;
case 'space': case 'space':
// bilibili://space/12345678?frommodule=XX&h5awaken=random // bilibili://space/12345678?frommodule=XX&h5awaken=random
String? mid = RegExp(r'/(\d+)').firstMatch(path)?.group(1); String? mid = uriDigitRegExp.firstMatch(path)?.group(1);
if (mid != null) { if (mid != null) {
Utils.toDupNamed('/member?mid=$mid', off: off); Utils.toDupNamed('/member?mid=$mid', off: off);
return true; return true;
@@ -92,7 +93,7 @@ class PiliScheme {
if (queryParameters['comment_root_id'] != null) { if (queryParameters['comment_root_id'] != null) {
// to check // to check
// to video reply // to video reply
String? oid = RegExp(r'/(\d+)').firstMatch(path)?.group(1); String? oid = uriDigitRegExp.firstMatch(path)?.group(1);
int? rpid = int.tryParse(queryParameters['comment_root_id']!); int? rpid = int.tryParse(queryParameters['comment_root_id']!);
if (oid != null && rpid != null) { if (oid != null && rpid != null) {
Get.to( Get.to(
@@ -132,7 +133,7 @@ class PiliScheme {
// to video // to video
// bilibili://video/12345678?page=0&h5awaken=random // bilibili://video/12345678?page=0&h5awaken=random
String? aid = RegExp(r'/(\d+)').firstMatch(path)?.group(1); String? aid = uriDigitRegExp.firstMatch(path)?.group(1);
String? bvid = RegExp(r'/(BV[a-z\d]{10})', caseSensitive: false) String? bvid = RegExp(r'/(BV[a-z\d]{10})', caseSensitive: false)
.firstMatch(path) .firstMatch(path)
?.group(1); ?.group(1);
@@ -163,7 +164,7 @@ class PiliScheme {
return false; return false;
case 'live': case 'live':
// bilibili://live/12345678?extra_jump_from=1&from=1&is_room_feed=1&h5awaken=random // bilibili://live/12345678?extra_jump_from=1&from=1&is_room_feed=1&h5awaken=random
String? roomId = RegExp(r'/(\d+)').firstMatch(path)?.group(1); String? roomId = uriDigitRegExp.firstMatch(path)?.group(1);
if (roomId != null) { if (roomId != null) {
Utils.toDupNamed('/liveRoom?roomid=$roomId', off: off); Utils.toDupNamed('/liveRoom?roomid=$roomId', off: off);
return true; return true;
@@ -172,7 +173,7 @@ class PiliScheme {
case 'bangumi': case 'bangumi':
// bilibili://bangumi/season/12345678?h5_awaken_params=random // bilibili://bangumi/season/12345678?h5_awaken_params=random
if (path.startsWith('/season')) { if (path.startsWith('/season')) {
String? seasonId = RegExp(r'/(\d+)').firstMatch(path)?.group(1); String? seasonId = uriDigitRegExp.firstMatch(path)?.group(1);
if (seasonId != null) { if (seasonId != null) {
Utils.viewBangumi(seasonId: seasonId, epId: null); Utils.viewBangumi(seasonId: seasonId, epId: null);
return true; return true;
@@ -195,7 +196,7 @@ class PiliScheme {
return true; return true;
case 'article': case 'article':
// bilibili://article/40679479?jump_opus=1&jump_opus_type=1&opus_type=article&h5awaken=random // bilibili://article/40679479?jump_opus=1&jump_opus_type=1&opus_type=article&h5awaken=random
String? id = RegExp(r'/(\d+)').firstMatch(path)?.group(1); String? id = uriDigitRegExp.firstMatch(path)?.group(1);
if (id != null) { if (id != null) {
Utils.toDupNamed( Utils.toDupNamed(
'/htmlRender', '/htmlRender',
@@ -256,7 +257,7 @@ class PiliScheme {
final queryParameters = uri.queryParameters; final queryParameters = uri.queryParameters;
final commentRootId = queryParameters['comment_root_id']; final commentRootId = queryParameters['comment_root_id'];
if (commentRootId != null) { if (commentRootId != null) {
String? oid = RegExp(r'/(\d+)').firstMatch(path)?.group(1); String? oid = uriDigitRegExp.firstMatch(path)?.group(1);
int? rpid = int.tryParse(commentRootId); int? rpid = int.tryParse(commentRootId);
if (oid != null && rpid != null) { if (oid != null && rpid != null) {
Get.to( Get.to(
@@ -296,7 +297,7 @@ class PiliScheme {
} }
return false; return false;
case 'album': case 'album':
String? rid = RegExp(r'/(\d+)').firstMatch(path)?.group(1); String? rid = uriDigitRegExp.firstMatch(path)?.group(1);
if (rid != null) { if (rid != null) {
SmartDialog.showLoading(); SmartDialog.showLoading();
dynamic res = await DynamicsHttp.dynamicDetail(rid: rid, type: 2); dynamic res = await DynamicsHttp.dynamicDetail(rid: rid, type: 2);
@@ -402,7 +403,7 @@ class PiliScheme {
} }
if (host.contains('live.bilibili.com')) { if (host.contains('live.bilibili.com')) {
String? roomId = RegExp(r'/(\d+)').firstMatch(path)?.group(1); String? roomId = uriDigitRegExp.firstMatch(path)?.group(1);
if (roomId != null) { if (roomId != null) {
Utils.toDupNamed('/liveRoom?roomid=$roomId', off: off); Utils.toDupNamed('/liveRoom?roomid=$roomId', off: off);
return true; return true;
@@ -412,7 +413,7 @@ class PiliScheme {
} }
if (host.contains('space.bilibili.com')) { if (host.contains('space.bilibili.com')) {
String? mid = RegExp(r'/(\d+)').firstMatch(path)?.group(1); String? mid = uriDigitRegExp.firstMatch(path)?.group(1);
if (mid != null) { if (mid != null) {
Utils.toDupNamed('/member?mid=$mid', off: off); Utils.toDupNamed('/member?mid=$mid', off: off);
return true; return true;
@@ -448,6 +449,7 @@ class PiliScheme {
launchURL(); launchURL();
return false; return false;
case 'bangumi': case 'bangumi':
// www.bilibili.com/bangumi/play/ep{eid}?start_progress={offset}&thumb_up_dm_id={dmid}
debugPrint('番剧'); debugPrint('番剧');
String? id = RegExp(r'(ss|ep)\d+').firstMatch(path)?.group(0); String? id = RegExp(r'(ss|ep)\d+').firstMatch(path)?.group(0);
if (id != null) { if (id != null) {
@@ -456,7 +458,7 @@ class PiliScheme {
Utils.viewBangumi( Utils.viewBangumi(
seasonId: isSeason ? id : null, seasonId: isSeason ? id : null,
epId: isSeason ? null : id, epId: isSeason ? null : id,
); progress: uri.queryParameters['start_progress']);
return true; return true;
} }
launchURL(); launchURL();
@@ -498,7 +500,7 @@ class PiliScheme {
return false; return false;
case 'space': case 'space':
debugPrint('个人空间'); debugPrint('个人空间');
String? mid = RegExp(r'/(\d+)').firstMatch(path)?.group(1); String? mid = uriDigitRegExp.firstMatch(path)?.group(1);
if (mid != null) { if (mid != null) {
Utils.toDupNamed( Utils.toDupNamed(
'/member?mid=$mid', '/member?mid=$mid',
@@ -524,7 +526,7 @@ class PiliScheme {
} }
static Future<bool> _onPushDynDetail(path, off) async { static Future<bool> _onPushDynDetail(path, off) async {
String? id = RegExp(r'/(\d+)').firstMatch(path)?.group(1); String? id = uriDigitRegExp.firstMatch(path)?.group(1);
if (id != null) { if (id != null) {
SmartDialog.showLoading(); SmartDialog.showLoading();
dynamic res = await DynamicsHttp.dynamicDetail(id: id); dynamic res = await DynamicsHttp.dynamicDetail(id: id);

View File

@@ -899,10 +899,8 @@ class Utils {
return '${randomTraceId.toString()}:${randomTraceId.toString().substring(16, 32)}:0:0'; return '${randomTraceId.toString()}:${randomTraceId.toString().substring(16, 32)}:0:0';
} }
static void viewBangumi({ static void viewBangumi(
dynamic seasonId, {dynamic seasonId, dynamic epId, dynamic progress}) async {
dynamic epId,
}) async {
try { try {
SmartDialog.showLoading(msg: '资源获取中'); SmartDialog.showLoading(msg: '资源获取中');
var result = await SearchHttp.bangumiInfo(seasonId: seasonId, epId: epId); var result = await SearchHttp.bangumiInfo(seasonId: seasonId, epId: epId);
@@ -934,6 +932,7 @@ class Utils {
'pic': item.cover, 'pic': item.cover,
'heroTag': Utils.makeHeroTag(item.cid), 'heroTag': Utils.makeHeroTag(item.cid),
'videoType': SearchType.video, 'videoType': SearchType.video,
if (progress != null) 'progress': int.tryParse(progress)
}, },
preventDuplicates: false, preventDuplicates: false,
); );
@@ -963,6 +962,7 @@ class Utils {
'heroTag': Utils.makeHeroTag(episode.cid), 'heroTag': Utils.makeHeroTag(episode.cid),
'videoType': SearchType.media_bangumi, 'videoType': SearchType.media_bangumi,
'bangumiItem': data, 'bangumiItem': data,
if (progress != null) 'progress': int.tryParse(progress)
}, },
preventDuplicates: false, preventDuplicates: false,
); );