diff --git a/lib/http/api.dart b/lib/http/api.dart index 6e10da62..f9bbb913 100644 --- a/lib/http/api.dart +++ b/lib/http/api.dart @@ -8,7 +8,8 @@ class Api { // APP端不感兴趣、取消不感兴趣 static const String feedDislike = '${HttpString.appBaseUrl}/x/feed/dislike'; - static const String feedDislikeCancel = '${HttpString.appBaseUrl}/x/feed/dislike/cancel'; + static const String feedDislikeCancel = + '${HttpString.appBaseUrl}/x/feed/dislike/cancel'; // 热门视频 static const String hotList = '/x/web-interface/popular'; @@ -35,8 +36,10 @@ class Api { /// like num 操作方式 必要 1:点赞 2:取消赞 // csrf str CSRF Token(位于cookie) 必要 // https://api.bilibili.com/x/web-interface/archive/like - static const String likeVideo = '/x/web-interface/archive/like'; + // static const String likeVideo = '/x/web-interface/archive/like'; + // 改用app端点赞接口 + static const String likeVideo = '${HttpString.appBaseUrl}/x/v2/view/like'; //判断视频是否被点赞(双端)Get // access_key str APP登录Token APP方式必要 /// aid num 稿件avid 必要(可选) avid与bvid任选一个 @@ -50,7 +53,8 @@ class Api { /// access_key str APP登录Token 必要 /// aid num 稿件avid 必要 /// - static const String dislikeVideo = '${HttpString.appBaseUrl}/x/v2/view/dislike'; + static const String dislikeVideo = + '${HttpString.appBaseUrl}/x/v2/view/dislike'; // 投币视频(web端)POST /// aid num 稿件avid 必要(可选) avid与bvid任选一个 @@ -59,7 +63,10 @@ class Api { /// select_like num 是否附加点赞 非必要 0:不点赞 1:同时点赞 默认为0 // csrf str CSRF Token(位于cookie) 必要 // https://api.bilibili.com/x/web-interface/coin/add - static const String coinVideo = '/x/web-interface/coin/add'; + // static const String coinVideo = '/x/web-interface/coin/add'; + + // 改用app端投币接口 + static const String coinVideo = '${HttpString.appBaseUrl}/x/v2/view/coin/add'; // 判断视频是否被投币(双端)GET // access_key str APP登录Token APP方式必要 @@ -383,13 +390,16 @@ class Api { //https://api.bilibili.com/x/msgfeed/like?platform=web&build=0&mobi_app=web 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 - static const String msgSysUserNotify = '${HttpString.messageBaseUrl}/x/sys-msg/query_user_notify'; + static const String msgSysUserNotify = + '${HttpString.messageBaseUrl}/x/sys-msg/query_user_notify'; //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'; + 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 - static const String msgSysUpdateCursor = '${HttpString.messageBaseUrl}/x/sys-msg/update_cursor'; + static const String msgSysUpdateCursor = + '${HttpString.messageBaseUrl}/x/sys-msg/update_cursor'; /// 私聊 /// 'https://api.vc.bilibili.com/session_svr/v1/session_svr/get_sessions? diff --git a/lib/http/video.dart b/lib/http/video.dart index 9ac839a7..a1a0dfcc 100644 --- a/lib/http/video.dart +++ b/lib/http/video.dart @@ -256,7 +256,7 @@ class VideoHttp { // }; return { 'status': false, - 'data': null, + 'data': result.data, 'code': result.code, 'msg': result.message, // 'msg': errMap[result.code] ?? '请求异常', @@ -307,12 +307,16 @@ class VideoHttp { var res = await Request().post( Api.coinVideo, queryParameters: { - 'bvid': bvid, + 'aid': IdUtils.bv2av(bvid), + // 'bvid': bvid, 'multiply': multiply, 'select_like': 0, - 'csrf': await Request.getCsrf(), + 'access_key': GStorage.localCache + .get(LocalCacheKey.accessKey, defaultValue: {})['value'], + // 'csrf': await Request.getCsrf(), }, ); + print(res); if (res.data['code'] == 0) { return {'status': true, 'data': res.data['data']}; } else { @@ -351,10 +355,16 @@ class VideoHttp { var res = await Request().post( Api.likeVideo, queryParameters: { - 'bvid': bvid, - 'like': type ? 1 : 2, - 'csrf': await Request.getCsrf(), - }, + 'aid': IdUtils.bv2av(bvid), + 'like': type ? 0 : 1, + 'access_key': GStorage.localCache + .get(LocalCacheKey.accessKey, defaultValue: {})['value'], + } + // queryParameters: { + // 'bvid': bvid, + // 'like': type ? 1 : 2, + // 'csrf': await Request.getCsrf(), + // }, ); if (res.data['code'] == 0) { return {'status': true, 'data': res.data['data']}; diff --git a/lib/pages/bangumi/introduction/controller.dart b/lib/pages/bangumi/introduction/controller.dart index ba403f15..7b32feb3 100644 --- a/lib/pages/bangumi/introduction/controller.dart +++ b/lib/pages/bangumi/introduction/controller.dart @@ -136,7 +136,7 @@ class BangumiIntroController extends GetxController { Future actionLikeVideo() async { var result = await VideoHttp.likeVideo(bvid: bvid, type: !hasLike.value); if (result['status']) { - SmartDialog.showToast(!hasLike.value ? '点赞成功' : '取消赞'); + SmartDialog.showToast(!hasLike.value ? result['data']['toast'] : '取消赞'); hasLike.value = !hasLike.value; bangumiDetail.value.stat!['likes'] = bangumiDetail.value.stat!['likes'] + (!hasLike.value ? 1 : -1); diff --git a/lib/pages/video/detail/introduction/controller.dart b/lib/pages/video/detail/introduction/controller.dart index 53d71082..509ca2e3 100644 --- a/lib/pages/video/detail/introduction/controller.dart +++ b/lib/pages/video/detail/introduction/controller.dart @@ -57,7 +57,6 @@ class VideoIntroController extends GetxController { List delMediaIdsNew = []; // 关注状态 默认未关注 RxMap followStatus = {}.obs; - int _tempThemeValue = -1; RxInt lastPlayCid = 0.obs; var userInfo; @@ -123,7 +122,8 @@ class VideoIntroController extends GetxController { // 获取到粉丝数再返回 await queryUserStat(); } else { - SmartDialog.showToast(result['msg']); + SmartDialog.showToast( + "${result['code']} ${result['msg']} ${result['data']}"); } if (userLogin) { // 获取点赞状态 @@ -175,43 +175,26 @@ class VideoIntroController extends GetxController { } // 一键三连 - Future actionOneThree(BuildContext context) async { + Future actionOneThree() async { + feedBack(); if (userInfo == null) { SmartDialog.showToast('账号未登录'); return; } if (hasLike.value && hasCoin.value && hasFav.value) { // 已点赞、投币、收藏 - SmartDialog.showToast('🙏 UP已经收到了~'); + SmartDialog.showToast('已三连'); return false; } - await showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: const Text('提示'), - content: const Text('一键三连 给UP送温暖'), - actions: [ - TextButton(onPressed: () => Get.back(), child: const Text('点错了')), - TextButton( - onPressed: () async { - Get.back(); - var result = await VideoHttp.oneThree(bvid: bvid); - if (result['status']) { - hasLike.value = result["data"]["like"]; - hasCoin.value = result["data"]["coin"]; - hasFav.value = result["data"]["fav"]; - SmartDialog.showToast('三连成功 🎉'); - } else { - SmartDialog.showToast(result['msg']); - } - }, - child: const Text('确认'), - ) - ], - ); - }, - ); + var result = await VideoHttp.oneThree(bvid: bvid); + if (result['status']) { + hasLike.value = result["data"]["like"]; + hasCoin.value = result["data"]["coin"]; + hasFav.value = result["data"]["fav"]; + SmartDialog.showToast('三连成功'); + } else { + SmartDialog.showToast(result['msg']); + } } // (取消)点赞 @@ -224,7 +207,7 @@ class VideoIntroController extends GetxController { if (result['status']) { // hasLike.value = result["data"] == 1 ? true : false; if (!hasLike.value) { - SmartDialog.showToast('点赞成功'); + SmartDialog.showToast(result['data']['toast']); hasLike.value = true; hasDislike.value = false; videoDetail.value.stat!.like = videoDetail.value.stat!.like! + 1; @@ -268,54 +251,42 @@ class VideoIntroController extends GetxController { SmartDialog.showToast('账号未登录'); return; } + void coinVideo(int coin) async { + var res = await VideoHttp.coinVideo(bvid: bvid, multiply: coin); + if (res['status']) { + print(res); + SmartDialog.showToast('投币成功'); + hasCoin.value = true; + videoDetail.value.stat!.coin = videoDetail.value.stat!.coin! + coin; + } else { + SmartDialog.showToast(res['msg']); + } + } + showDialog( context: Get.context!, builder: (context) { return AlertDialog( title: const Text('选择投币个数'), contentPadding: const EdgeInsets.fromLTRB(0, 12, 0, 12), - content: StatefulBuilder(builder: (context, StateSetter setState) { - return Column( - mainAxisSize: MainAxisSize.min, - children: [ - RadioListTile( - value: 1, - title: const Text('1枚'), - groupValue: _tempThemeValue, - onChanged: (value) { - _tempThemeValue = value!; - Get.appUpdate(); - }, - ), - RadioListTile( - value: 2, - title: const Text('2枚'), - groupValue: _tempThemeValue, - onChanged: (value) { - _tempThemeValue = value!; - Get.appUpdate(); - }, - ), - ], - ); - }), actions: [ - TextButton(onPressed: () => Get.back(), child: const Text('取消')), + TextButton( + onPressed: () => Get.back(), + child: Text('取消', + style: TextStyle( + color: Theme.of(context).colorScheme.outline))), TextButton( onPressed: () async { - var res = await VideoHttp.coinVideo( - bvid: bvid, multiply: _tempThemeValue); - if (res['status']) { - SmartDialog.showToast('投币成功'); - hasCoin.value = true; - videoDetail.value.stat!.coin = - videoDetail.value.stat!.coin! + _tempThemeValue; - } else { - SmartDialog.showToast(res['msg']); - } + coinVideo(1); Get.back(); }, - child: const Text('确定')) + child: const Text('投 1 枚')), + TextButton( + onPressed: () async { + coinVideo(1); + Get.back(); + }, + child: const Text('投 2 枚')) ], ); }); @@ -444,6 +415,10 @@ class VideoIntroController extends GetxController { // 关注/取关up Future actionRelationMod(BuildContext context) async { + if (userInfo == null) { + SmartDialog.showToast('账号未登录'); + return; + } feedBack(); int mid = videoDetail.value.owner!.mid!; MemberController _ = Get.put(MemberController(mid: mid),