From a0f92df5b558cfb002c9c8142282bd4eae2835d6 Mon Sep 17 00:00:00 2001
From: My-Responsitories <107370289+My-Responsitories@users.noreply.github.com>
Date: Wed, 21 Feb 2024 13:16:38 +0800
Subject: [PATCH] fix dynamic risk challenge
---
lib/http/api.dart | 6 ++++++
lib/http/init.dart | 42 ++++++++++++++++++++++++++++++++++++------
lib/http/member.dart | 8 +++++++-
lib/utils/utils.dart | 15 ++++++++++++++-
4 files changed, 63 insertions(+), 8 deletions(-)
diff --git a/lib/http/api.dart b/lib/http/api.dart
index 4b6bbeb8..2e758439 100644
--- a/lib/http/api.dart
+++ b/lib/http/api.dart
@@ -477,4 +477,10 @@ class Api {
/// 获取未读动态数
static const getUnreadDynamic = '/x/web-interface/dynamic/entrance';
+
+ /// 用户动态主页
+ static const dynamicSpmPrefix = 'https://space.bilibili.com/1/dynamic';
+
+ /// 激活buvid3
+ static const activateBuvidApi = '/x/internal/gaia-gateway/ExClimbWuzhi';
}
diff --git a/lib/http/init.dart b/lib/http/init.dart
index dcc9f402..a0b36369 100644
--- a/lib/http/init.dart
+++ b/lib/http/init.dart
@@ -1,7 +1,9 @@
// ignore_for_file: avoid_print
import 'dart:async';
+import 'dart:convert';
import 'dart:developer';
import 'dart:io';
+import 'dart:math' show Random;
import 'package:cookie_jar/cookie_jar.dart';
import 'package:dio/dio.dart';
import 'package:dio/io.dart';
@@ -11,6 +13,7 @@ import 'package:hive/hive.dart';
import 'package:pilipala/utils/id_utils.dart';
import '../utils/storage.dart';
import '../utils/utils.dart';
+import 'api.dart';
import 'constants.dart';
import 'interceptor.dart';
@@ -24,6 +27,7 @@ class Request {
late bool enableSystemProxy;
late String systemProxyHost;
late String systemProxyPort;
+ static final RegExp spmPrefixExp = RegExp(r'');
/// 设置cookie
static setCookie() async {
@@ -51,13 +55,12 @@ class Request {
}
setOptionsHeaders(userInfo, userInfo != null && userInfo.mid != null);
- if (cookie.isEmpty) {
- try {
- await Request().get(HttpString.baseUrl);
- } catch (e) {
- log("setCookie, ${e.toString()}");
- }
+ try {
+ await buvidActivate();
+ } catch (e) {
+ log("setCookie, ${e.toString()}");
}
+
final String cookieString = cookie
.map((Cookie cookie) => '${cookie.name}=${cookie.value}')
.join('; ');
@@ -87,6 +90,33 @@ class Request {
dio.options.headers['referer'] = 'https://www.bilibili.com/';
}
+ static Future buvidActivate() async {
+ var html = await Request().get(Api.dynamicSpmPrefix);
+ String spmPrefix = spmPrefixExp.firstMatch(html.data)!.group(1)!;
+ Random rand = Random();
+ String rand_png_end = base64.encode(
+ List.generate(32, (_) => rand.nextInt(256)) +
+ List.filled(4, 0) +
+ [73, 69, 78, 68] +
+ List.generate(4, (_) => rand.nextInt(256))
+ );
+
+ String jsonData = json.encode({
+ '3064': 1,
+ '39c8': '${spmPrefix}.fp.risk',
+ '3c43': {
+ 'adca': 'Linux',
+ 'bfe9': rand_png_end.substring(rand_png_end.length - 50),
+ },
+ });
+
+ await Request().post(
+ Api.activateBuvidApi,
+ data: {'payload': jsonData},
+ options: Options(contentType: 'application/json')
+ );
+ }
+
/*
* config it and create
*/
diff --git a/lib/http/member.dart b/lib/http/member.dart
index 82d2992b..1af0f9a4 100644
--- a/lib/http/member.dart
+++ b/lib/http/member.dart
@@ -79,6 +79,8 @@ class MemberHttp {
String order = 'pubdate',
bool orderAvoided = true,
}) async {
+ String dmImgStr = Utils.base64EncodeRandomString(16, 64);
+ String dmCoverImgStr = Utils.base64EncodeRandomString(32, 128);
Map params = await WbiSign().makSign({
'mid': mid,
'ps': ps,
@@ -88,7 +90,11 @@ class MemberHttp {
'order': order,
'platform': 'web',
'web_location': 1550101,
- 'order_avoided': orderAvoided
+ 'order_avoided': orderAvoided,
+ 'dm_img_list': '[]',
+ 'dm_img_str': dmImgStr.substring(0, dmImgStr.length - 2),
+ 'dm_cover_img_str': dmCoverImgStr.substring(0, dmCoverImgStr.length - 2),
+ 'dm_img_inter': '{"ds":[],"wh":[0,0,0],"of":[0,0,0]}',
});
var res = await Request().get(
Api.memberArchive,
diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart
index d68ac51b..09d8c97f 100644
--- a/lib/utils/utils.dart
+++ b/lib/utils/utils.dart
@@ -16,6 +16,8 @@ import '../http/index.dart';
import '../models/github/latest.dart';
class Utils {
+ static final Random random = Random();
+
static Future getCookiePath() async {
final Directory tempDir = await getApplicationSupportDirectory();
final String tempPath = "${tempDir.path}/.plpl/";
@@ -180,7 +182,7 @@ class Utils {
}
static String makeHeroTag(v) {
- return v.toString() + Random().nextInt(9999).toString();
+ return v.toString() + random.nextInt(9999).toString();
}
static int duration(String duration) {
@@ -340,4 +342,15 @@ class Utils {
return md5String;
}
+
+ static List generateRandomBytes(int minLength, int maxLength) {
+ return List.generate(
+ random.nextInt(maxLength-minLength+1), (_) => random.nextInt(0x60) + 0x20
+ );
+ }
+
+ static String base64EncodeRandomString(int minLength, int maxLength) {
+ List randomBytes = generateRandomBytes(minLength, maxLength);
+ return base64.encode(randomBytes);
+ }
}