mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-01 00:28:18 +08:00
remove duplicate code (#312)
* remove duplicate code * Update login.dart
This commit is contained in:
committed by
GitHub
parent
192cd60a4f
commit
9e242fb902
@@ -31,7 +31,7 @@ class GrpcRepo {
|
|||||||
static const _phone = 'phone';
|
static const _phone = 'phone';
|
||||||
|
|
||||||
static final _eId = _isLogin ? Utils.genAuroraEid(_mid!) : '';
|
static final _eId = _isLogin ? Utils.genAuroraEid(_mid!) : '';
|
||||||
static final _buvid = LoginUtils.buvid();
|
static final _buvid = LoginUtils.buvid;
|
||||||
static final _traceId = Utils.genTraceId();
|
static final _traceId = Utils.genTraceId();
|
||||||
static final _sessionId = Utils.generateRandomString(8);
|
static final _sessionId = Utils.generateRandomString(8);
|
||||||
|
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ import '../utils/utils.dart';
|
|||||||
import 'index.dart';
|
import 'index.dart';
|
||||||
|
|
||||||
class LoginHttp {
|
class LoginHttp {
|
||||||
static String deviceId = LoginUtils.genDeviceId();
|
static final String deviceId = LoginUtils.genDeviceId();
|
||||||
static String buvid = LoginUtils.buvid();
|
static final String buvid = LoginUtils.buvid;
|
||||||
static String host = 'passport.bilibili.com';
|
static const String host = 'passport.bilibili.com';
|
||||||
static Map<String, String> headers = {
|
static final Map<String, String> headers = {
|
||||||
'Host': host,
|
'Host': host,
|
||||||
'buvid': buvid,
|
'buvid': buvid,
|
||||||
'env': 'prod',
|
'env': 'prod',
|
||||||
@@ -224,7 +224,7 @@ class LoginHttp {
|
|||||||
'device_platform': 'Android14vivo',
|
'device_platform': 'Android14vivo',
|
||||||
'disable_rcmd': '0',
|
'disable_rcmd': '0',
|
||||||
'dt': Uri.encodeComponent(Encrypter(RSA(publicKey: publicKey))
|
'dt': Uri.encodeComponent(Encrypter(RSA(publicKey: publicKey))
|
||||||
.encrypt(LoginUtils.generateRandomString(16))
|
.encrypt(Utils.generateRandomString(16))
|
||||||
.base64),
|
.base64),
|
||||||
'from_pv': 'main.homepage.avatar-nologin.all.click',
|
'from_pv': 'main.homepage.avatar-nologin.all.click',
|
||||||
'from_url': Uri.encodeComponent('bilibili://pegasus/promo'),
|
'from_url': Uri.encodeComponent('bilibili://pegasus/promo'),
|
||||||
@@ -304,7 +304,7 @@ class LoginHttp {
|
|||||||
// 'device_tourist_id': '',
|
// 'device_tourist_id': '',
|
||||||
'disable_rcmd': '0',
|
'disable_rcmd': '0',
|
||||||
'dt': Uri.encodeComponent(Encrypter(RSA(publicKey: publicKey))
|
'dt': Uri.encodeComponent(Encrypter(RSA(publicKey: publicKey))
|
||||||
.encrypt(LoginUtils.generateRandomString(16))
|
.encrypt(Utils.generateRandomString(16))
|
||||||
.base64),
|
.base64),
|
||||||
'from_pv': 'main.my-information.my-login.0.click',
|
'from_pv': 'main.my-information.my-login.0.click',
|
||||||
'from_url': Uri.encodeComponent('bilibili://user_center/mine'),
|
'from_url': Uri.encodeComponent('bilibili://user_center/mine'),
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'package:PiliPlus/http/constants.dart';
|
|||||||
import 'package:PiliPlus/pages/dynamics/view.dart' show ReplyOption;
|
import 'package:PiliPlus/pages/dynamics/view.dart' show ReplyOption;
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
import '../models/msg/account.dart';
|
import '../models/msg/account.dart';
|
||||||
import '../models/msg/session.dart';
|
import '../models/msg/session.dart';
|
||||||
@@ -583,36 +584,37 @@ class MsgHttp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static String getDevId() {
|
static String getDevId() {
|
||||||
final List<String> b = [
|
return Uuid().v4();
|
||||||
'0',
|
// final List<String> b = [
|
||||||
'1',
|
// '0',
|
||||||
'2',
|
// '1',
|
||||||
'3',
|
// '2',
|
||||||
'4',
|
// '3',
|
||||||
'5',
|
// '4',
|
||||||
'6',
|
// '5',
|
||||||
'7',
|
// '6',
|
||||||
'8',
|
// '7',
|
||||||
'9',
|
// '8',
|
||||||
'A',
|
// '9',
|
||||||
'B',
|
// 'A',
|
||||||
'C',
|
// 'B',
|
||||||
'D',
|
// 'C',
|
||||||
'E',
|
// 'D',
|
||||||
'F'
|
// 'E',
|
||||||
];
|
// 'F'
|
||||||
final List<String> s = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".split('');
|
// ];
|
||||||
for (int i = 0; i < s.length; i++) {
|
// final List<String> s = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".split('');
|
||||||
if ('-' == s[i] || '4' == s[i]) {
|
// for (int i = 0; i < s.length; i++) {
|
||||||
continue;
|
// if ('-' == s[i] || '4' == s[i]) {
|
||||||
}
|
// continue;
|
||||||
final int randomInt = Random().nextInt(16);
|
// }
|
||||||
if ('x' == s[i]) {
|
// final int randomInt = Random().nextInt(16);
|
||||||
s[i] = b[randomInt];
|
// if ('x' == s[i]) {
|
||||||
} else {
|
// s[i] = b[randomInt];
|
||||||
s[i] = b[3 & randomInt | 8];
|
// } else {
|
||||||
}
|
// s[i] = b[3 & randomInt | 8];
|
||||||
}
|
// }
|
||||||
return s.join();
|
// }
|
||||||
|
// return s.join();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
@@ -14,14 +13,12 @@ import 'package:PiliPlus/pages/dynamics/tab/controller.dart';
|
|||||||
import 'package:PiliPlus/pages/live/controller.dart';
|
import 'package:PiliPlus/pages/live/controller.dart';
|
||||||
import 'package:PiliPlus/pages/main/controller.dart';
|
import 'package:PiliPlus/pages/main/controller.dart';
|
||||||
import 'package:PiliPlus/utils/storage.dart';
|
import 'package:PiliPlus/utils/storage.dart';
|
||||||
import 'package:crypto/crypto.dart';
|
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:PiliPlus/pages/dynamics/index.dart';
|
import 'package:PiliPlus/pages/dynamics/index.dart';
|
||||||
import 'package:PiliPlus/pages/home/index.dart';
|
import 'package:PiliPlus/pages/home/index.dart';
|
||||||
import 'package:PiliPlus/pages/media/index.dart';
|
import 'package:PiliPlus/pages/media/index.dart';
|
||||||
import 'package:PiliPlus/pages/mine/index.dart';
|
import 'package:PiliPlus/pages/mine/index.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
|
||||||
import 'package:webview_cookie_manager/webview_cookie_manager.dart';
|
import 'package:webview_cookie_manager/webview_cookie_manager.dart';
|
||||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart' as web;
|
import 'package:flutter_inappwebview/flutter_inappwebview.dart' as web;
|
||||||
import 'package:PiliPlus/pages/dynamics/controller.dart';
|
import 'package:PiliPlus/pages/dynamics/controller.dart';
|
||||||
@@ -31,14 +28,16 @@ import 'package:PiliPlus/pages/mine/controller.dart';
|
|||||||
import 'package:PiliPlus/http/user.dart';
|
import 'package:PiliPlus/http/user.dart';
|
||||||
|
|
||||||
class LoginUtils {
|
class LoginUtils {
|
||||||
static Future onLogin(Map<String, dynamic> token_info, cookie_info) async {
|
static final random = Random();
|
||||||
|
|
||||||
|
static Future onLogin(Map<String, dynamic> tokenInfo, jsonCookieInfo) async {
|
||||||
try {
|
try {
|
||||||
GStorage.localCache.put(LocalCacheKey.accessKey, {
|
GStorage.localCache.put(LocalCacheKey.accessKey, {
|
||||||
'mid': token_info['mid'],
|
'mid': tokenInfo['mid'],
|
||||||
'value': token_info['access_token'] ?? token_info['value'],
|
'value': tokenInfo['access_token'] ?? tokenInfo['value'],
|
||||||
'refresh': token_info['refresh_token'] ?? token_info['refresh']
|
'refresh': tokenInfo['refresh_token'] ?? tokenInfo['refresh']
|
||||||
});
|
});
|
||||||
List<dynamic> cookieInfo = cookie_info['cookies'];
|
List<dynamic> cookieInfo = jsonCookieInfo['cookies'];
|
||||||
List<Cookie> cookies = [];
|
List<Cookie> cookies = [];
|
||||||
String cookieStrings = cookieInfo.map((cookie) {
|
String cookieStrings = cookieInfo.map((cookie) {
|
||||||
String cstr =
|
String cstr =
|
||||||
@@ -198,31 +197,25 @@ class LoginUtils {
|
|||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
static String buvid() {
|
|
||||||
var mac = <String>[];
|
|
||||||
var random = Random();
|
|
||||||
|
|
||||||
for (var i = 0; i < 6; i++) {
|
|
||||||
var min = 0;
|
|
||||||
var max = 0xff;
|
|
||||||
var num = (random.nextInt(max - min + 1) + min).toRadixString(16);
|
|
||||||
mac.add(num);
|
|
||||||
}
|
|
||||||
|
|
||||||
var md5Str = md5.convert(utf8.encode(mac.join(':'))).toString();
|
|
||||||
var md5Arr = md5Str.split('');
|
|
||||||
return 'XY${md5Arr[2]}${md5Arr[12]}${md5Arr[22]}$md5Str';
|
|
||||||
}
|
|
||||||
|
|
||||||
static String getUUID() {
|
|
||||||
return const Uuid().v4().replaceAll('-', '');
|
|
||||||
}
|
|
||||||
|
|
||||||
static String generateBuvid() {
|
static String generateBuvid() {
|
||||||
String uuid = getUUID() + getUUID();
|
var md5Str =
|
||||||
return 'XY${uuid.substring(0, 35).toUpperCase()}';
|
Iterable.generate(32, (_) => random.nextInt(16).toRadixString(16))
|
||||||
|
.join()
|
||||||
|
.toUpperCase();
|
||||||
|
return 'XY${md5Str[2]}${md5Str[12]}${md5Str[22]}$md5Str';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static final buvid = generateBuvid();
|
||||||
|
|
||||||
|
// static String getUUID() {
|
||||||
|
// return const Uuid().v4().replaceAll('-', '');
|
||||||
|
// }
|
||||||
|
|
||||||
|
// static String generateBuvid() {
|
||||||
|
// String uuid = getUUID() + getUUID();
|
||||||
|
// return 'XY${uuid.substring(0, 35).toUpperCase()}';
|
||||||
|
// }
|
||||||
|
|
||||||
static String genDeviceId() {
|
static String genDeviceId() {
|
||||||
// https://github.com/bilive/bilive_client/blob/2873de0532c54832f5464a4c57325ad9af8b8698/bilive/lib/app_client.ts#L62
|
// https://github.com/bilive/bilive_client/blob/2873de0532c54832f5464a4c57325ad9af8b8698/bilive/lib/app_client.ts#L62
|
||||||
final String yyyyMMddHHmmss = DateTime.now()
|
final String yyyyMMddHHmmss = DateTime.now()
|
||||||
@@ -230,7 +223,6 @@ class LoginUtils {
|
|||||||
.replaceAll(RegExp(r'[-:TZ]'), '')
|
.replaceAll(RegExp(r'[-:TZ]'), '')
|
||||||
.substring(0, 14);
|
.substring(0, 14);
|
||||||
|
|
||||||
final Random random = Random(); // Random.secure();
|
|
||||||
final String randomHex32 =
|
final String randomHex32 =
|
||||||
List.generate(32, (index) => random.nextInt(16).toRadixString(16))
|
List.generate(32, (index) => random.nextInt(16).toRadixString(16))
|
||||||
.join();
|
.join();
|
||||||
@@ -251,12 +243,4 @@ class LoginUtils {
|
|||||||
|
|
||||||
return deviceID + check;
|
return deviceID + check;
|
||||||
}
|
}
|
||||||
|
|
||||||
static String generateRandomString(int length) {
|
|
||||||
const chars =
|
|
||||||
'123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
|
||||||
final Random random = Random(); // Random.secure();
|
|
||||||
return List.generate(length, (index) => chars[random.nextInt(chars.length)])
|
|
||||||
.join();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -765,7 +765,6 @@ class Utils {
|
|||||||
|
|
||||||
static String generateRandomString(int length) {
|
static String generateRandomString(int length) {
|
||||||
const characters = '0123456789abcdefghijklmnopqrstuvwxyz';
|
const characters = '0123456789abcdefghijklmnopqrstuvwxyz';
|
||||||
Random random = Random();
|
|
||||||
|
|
||||||
return String.fromCharCodes(Iterable.generate(length,
|
return String.fromCharCodes(Iterable.generate(length,
|
||||||
(_) => characters.codeUnitAt(random.nextInt(characters.length))));
|
(_) => characters.codeUnitAt(random.nextInt(characters.length))));
|
||||||
@@ -777,66 +776,43 @@ class Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 1. Convert UID to a byte array.
|
// 1. Convert UID to a byte array.
|
||||||
List<int> midByte = utf8.encode(uid.toString());
|
var midByte = utf8.encode(uid.toString());
|
||||||
List<int> resultByte = List<int>.filled(midByte.length, 0);
|
|
||||||
|
|
||||||
// 2. XOR each byte with the corresponding byte from the key.
|
// 2. XOR each byte with the corresponding byte from the key.
|
||||||
const key = 'ad1va46a7lza';
|
const key = 'ad1va46a7lza';
|
||||||
for (int i = 0; i < midByte.length; i++) {
|
for (int i = 0; i < midByte.length; i++) {
|
||||||
resultByte[i] = midByte[i] ^ key.codeUnitAt(i % key.length);
|
midByte[i] ^= key.codeUnitAt(i % key.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Perform Base64 encoding without padding.
|
// 3. Perform Base64 encoding without padding.
|
||||||
String base64Encoded =
|
String base64Encoded =
|
||||||
base64.encode(resultByte).replaceAll('=', ''); // Remove padding
|
base64.encode(midByte).replaceAll('=', ''); // Remove padding
|
||||||
|
|
||||||
// Return the resulting x-bili-aurora-eid.
|
// Return the resulting x-bili-aurora-eid.
|
||||||
return base64Encoded;
|
return base64Encoded;
|
||||||
}
|
}
|
||||||
|
|
||||||
static String genRandomString(int length) {
|
// static String genRandomString(int length) {
|
||||||
const characters = '0123456789abcdefghijklmnopqrstuvwxyz';
|
// const characters = '0123456789abcdefghijklmnopqrstuvwxyz';
|
||||||
Random random = Random();
|
// Random random = Random();
|
||||||
return List.generate(
|
// return List.generate(
|
||||||
length, (index) => characters[random.nextInt(characters.length)])
|
// length, (index) => characters[random.nextInt(characters.length)])
|
||||||
.join();
|
// .join();
|
||||||
}
|
// }
|
||||||
|
|
||||||
static String genTraceId() {
|
static String genTraceId() {
|
||||||
// 1. Generate a 32-character random string (random_id).
|
String randomId = generateRandomString(32);
|
||||||
String randomId = genRandomString(32);
|
|
||||||
|
|
||||||
// 2. Take the first 24 characters of random_id as random_trace_id.
|
|
||||||
StringBuffer randomTraceId = StringBuffer(randomId.substring(0, 24));
|
StringBuffer randomTraceId = StringBuffer(randomId.substring(0, 24));
|
||||||
|
|
||||||
// 3. Initialize an array b_arr with a length of 3, initial values are 0.
|
|
||||||
List<int> bArr = List.filled(3, 0);
|
|
||||||
|
|
||||||
// Get the current timestamp.
|
|
||||||
int ts = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
|
||||||
|
|
||||||
// Using a loop to traverse b_arr from high to low.
|
|
||||||
for (int i = 2; i >= 0; i--) {
|
for (int i = 2; i >= 0; i--) {
|
||||||
ts >>= 8; // Right shift ts by 8 bits.
|
|
||||||
bArr[i] = (ts ~/ 128) % 2 == 0
|
|
||||||
? (ts % 256)
|
|
||||||
: (ts % 256) - 256; // Assign value based on condition.
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. Convert each element in b_arr to a two-digit hexadecimal string and append to random_trace_id.
|
|
||||||
for (int value in bArr) {
|
|
||||||
randomTraceId
|
randomTraceId
|
||||||
.write(value.toRadixString(16).padLeft(2, '0')); // Convert to hex.
|
.write(random.nextInt(256).toRadixString(16).padLeft(2, '0'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. Append the 31st and 32nd characters of random_id to random_trace_id.
|
|
||||||
randomTraceId.write(randomId.substring(30, 32));
|
randomTraceId.write(randomId.substring(30, 32));
|
||||||
|
|
||||||
// 6. Finally, concatenate as '{random_trace_id}:{random_trace_id[16..32]}:0:0'.
|
return '${randomTraceId.toString()}:${randomTraceId.toString().substring(16, 32)}:0:0';
|
||||||
String randomTraceIdFinal =
|
|
||||||
'${randomTraceId.toString()}:${randomTraceId.toString().substring(16, 32)}:0:0';
|
|
||||||
|
|
||||||
return randomTraceIdFinal;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void viewBangumi({
|
static void viewBangumi({
|
||||||
|
|||||||
Reference in New Issue
Block a user