opt: http
This commit is contained in:
@ -15,6 +15,4 @@ class Constants {
|
||||
// 59b43e04ad6965f34319062b478f83dd TV端
|
||||
static const String appSec = '59b43e04ad6965f34319062b478f83dd';
|
||||
static const String thirdSign = '04224646d1fea004e79606d3b038c84a';
|
||||
static const String thirdApi =
|
||||
'https://www.mcbbs.net/template/mcbbs/image/special_photo_bg.png';
|
||||
}
|
||||
|
||||
@ -21,7 +21,6 @@ class HtmlHttp {
|
||||
}
|
||||
try {
|
||||
Document rootTree = parse(response.data);
|
||||
// log(response.data.body.toString());
|
||||
Element body = rootTree.body!;
|
||||
Element appDom = body.querySelector('#app')!;
|
||||
Element authorHeader = appDom.querySelector('.fixed-author-header')!;
|
||||
@ -52,7 +51,6 @@ class HtmlHttp {
|
||||
.className
|
||||
.split(' ')[1]
|
||||
.split('-')[2];
|
||||
// List imgList = opusDetail.querySelectorAll('bili-album__preview__picture__img');
|
||||
return {
|
||||
'status': true,
|
||||
'avatar': avatar,
|
||||
@ -76,20 +74,10 @@ class HtmlHttp {
|
||||
Element body = rootTree.body!;
|
||||
Element appDom = body.querySelector('#app')!;
|
||||
Element authorHeader = appDom.querySelector('.up-left')!;
|
||||
// 头像
|
||||
// String avatar =
|
||||
// authorHeader.querySelector('.bili-avatar-img')!.attributes['data-src']!;
|
||||
// print(avatar);
|
||||
// avatar = 'https:${avatar.split('@')[0]}';
|
||||
String uname = authorHeader.querySelector('.up-name')!.text.trim();
|
||||
// 动态详情
|
||||
Element opusDetail = appDom.querySelector('.article-content')!;
|
||||
// 发布时间
|
||||
// String updateTime =
|
||||
// opusDetail.querySelector('.opus-module-author__pub__text')!.text;
|
||||
// print(updateTime);
|
||||
|
||||
//
|
||||
String opusContent =
|
||||
opusDetail.querySelector('#read-article-holder')!.innerHtml;
|
||||
RegExp digitRegExp = RegExp(r'\d+');
|
||||
|
||||
@ -8,7 +8,6 @@ import 'package:cookie_jar/cookie_jar.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:dio/io.dart';
|
||||
import 'package:dio_cookie_manager/dio_cookie_manager.dart';
|
||||
// import 'package:dio_http2_adapter/dio_http2_adapter.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:pilipala/utils/id_utils.dart';
|
||||
import '../utils/storage.dart';
|
||||
@ -171,15 +170,6 @@ class Request {
|
||||
|
||||
dio = Dio(options);
|
||||
|
||||
/// fix 第三方登录 302重定向 跟iOS代理问题冲突
|
||||
// ..httpClientAdapter = Http2Adapter(
|
||||
// ConnectionManager(
|
||||
// idleTimeout: const Duration(milliseconds: 10000),
|
||||
// onClientCreate: (_, ClientSetting config) =>
|
||||
// config.onBadCertificate = (_) => true,
|
||||
// ),
|
||||
// );
|
||||
|
||||
/// 设置代理
|
||||
if (enableSystemProxy) {
|
||||
dio.httpClientAdapter = IOHttpClientAdapter(
|
||||
@ -247,11 +237,26 @@ class Request {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* get请求
|
||||
*/
|
||||
getWithoutCookie(url, {data}) {
|
||||
return get(
|
||||
url,
|
||||
data: data,
|
||||
options: Options(
|
||||
headers: {
|
||||
'cookie': 'buvid3= ; b_nut= ; sid= ',
|
||||
'user-agent': headerUa(type: 'pc'),
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* post请求
|
||||
*/
|
||||
post(url, {data, queryParameters, options, cancelToken, extra}) async {
|
||||
// print('post-data: $data');
|
||||
Response response;
|
||||
try {
|
||||
response = await dio.post(
|
||||
@ -262,7 +267,6 @@ class Request {
|
||||
options ?? Options(contentType: Headers.formUrlEncodedContentType),
|
||||
cancelToken: cancelToken,
|
||||
);
|
||||
// print('post success: ${response.data}');
|
||||
return response;
|
||||
} on DioException catch (e) {
|
||||
Response errResponse = Response(
|
||||
@ -318,7 +322,7 @@ class Request {
|
||||
}
|
||||
} else {
|
||||
headerUa =
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.2 Safari/605.1.15';
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36';
|
||||
}
|
||||
return headerUa;
|
||||
}
|
||||
|
||||
@ -3,8 +3,6 @@
|
||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import '../utils/storage.dart';
|
||||
|
||||
class ApiInterceptor extends Interceptor {
|
||||
@override
|
||||
@ -19,21 +17,7 @@ class ApiInterceptor extends Interceptor {
|
||||
@override
|
||||
void onResponse(Response response, ResponseInterceptorHandler handler) {
|
||||
try {
|
||||
if (response.statusCode == 302) {
|
||||
final List<String> locations = response.headers['location']!;
|
||||
if (locations.isNotEmpty) {
|
||||
if (locations.first.startsWith('https://www.mcbbs.net')) {
|
||||
final Uri uri = Uri.parse(locations.first);
|
||||
final String? accessKey = uri.queryParameters['access_key'];
|
||||
final String? mid = uri.queryParameters['mid'];
|
||||
try {
|
||||
Box localCache = GStrorage.localCache;
|
||||
localCache.put(LocalCacheKey.accessKey,
|
||||
<String, String?>{'mid': mid, 'value': accessKey});
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 在响应之后处理数据
|
||||
} catch (err) {
|
||||
print('ApiInterceptor: $err');
|
||||
}
|
||||
|
||||
@ -1,10 +1,6 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:html/parser.dart';
|
||||
import 'package:pilipala/models/video/later.dart';
|
||||
import '../common/constants.dart';
|
||||
import '../models/model_hot_video_item.dart';
|
||||
import '../models/user/fav_detail.dart';
|
||||
import '../models/user/fav_folder.dart';
|
||||
@ -218,25 +214,6 @@ class UserHttp {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取用户凭证 失效
|
||||
static Future thirdLogin() async {
|
||||
var res = await Request().get(
|
||||
'https://passport.bilibili.com/login/app/third',
|
||||
data: {
|
||||
'appkey': Constants.appKey,
|
||||
'api': Constants.thirdApi,
|
||||
'sign': Constants.thirdSign,
|
||||
},
|
||||
);
|
||||
try {
|
||||
if (res.data['code'] == 0 && res.data['data']['has_login'] == 1) {
|
||||
Request().get(res.data['data']['confirm_uri']);
|
||||
}
|
||||
} catch (err) {
|
||||
SmartDialog.showNotify(msg: '获取用户凭证: $err', notifyType: NotifyType.error);
|
||||
}
|
||||
}
|
||||
|
||||
// 清空稍后再看
|
||||
static Future toViewClear() async {
|
||||
var res = await Request().post(
|
||||
@ -283,30 +260,6 @@ class UserHttp {
|
||||
return {'status': false, 'msg': res.data['message']};
|
||||
}
|
||||
}
|
||||
// // 相互关系查询
|
||||
// static Future relationSearch(int mid) async {
|
||||
// Map params = await WbiSign().makSign({
|
||||
// 'mid': mid,
|
||||
// 'token': '',
|
||||
// 'platform': 'web',
|
||||
// 'web_location': 1550101,
|
||||
// });
|
||||
// var res = await Request().get(
|
||||
// Api.relationSearch,
|
||||
// data: {
|
||||
// 'mid': mid,
|
||||
// 'w_rid': params['w_rid'],
|
||||
// 'wts': params['wts'],
|
||||
// },
|
||||
// );
|
||||
// if (res.data['code'] == 0) {
|
||||
// // relation 主动状态
|
||||
// // 被动状态
|
||||
// return {'status': true, 'data': res.data['data']};
|
||||
// } else {
|
||||
// return {'status': false, 'msg': res.data['message']};
|
||||
// }
|
||||
// }
|
||||
|
||||
// 搜索历史记录
|
||||
static Future searchHistory(
|
||||
@ -436,31 +389,6 @@ class UserHttp {
|
||||
}
|
||||
}
|
||||
|
||||
// 稍后再看播放全部
|
||||
// static Future toViewPlayAll({required int oid, required String bvid}) async {
|
||||
// var res = await Request().get(
|
||||
// Api.watchLaterHtml,
|
||||
// data: {
|
||||
// 'oid': oid,
|
||||
// 'bvid': bvid,
|
||||
// },
|
||||
// );
|
||||
// String scriptContent =
|
||||
// extractScriptContents(parse(res.data).body!.outerHtml)[0];
|
||||
// int startIndex = scriptContent.indexOf('{');
|
||||
// int endIndex = scriptContent.lastIndexOf('};');
|
||||
// String jsonContent = scriptContent.substring(startIndex, endIndex + 1);
|
||||
// // 解析JSON字符串为Map
|
||||
// Map<String, dynamic> jsonData = json.decode(jsonContent);
|
||||
// // 输出解析后的数据
|
||||
// return {
|
||||
// 'status': true,
|
||||
// 'data': jsonData['resourceList']
|
||||
// .map((e) => MediaVideoItemModel.fromJson(e))
|
||||
// .toList()
|
||||
// };
|
||||
// }
|
||||
|
||||
static List<String> extractScriptContents(String htmlContent) {
|
||||
RegExp scriptRegExp = RegExp(r'<script>([\s\S]*?)<\/script>');
|
||||
Iterable<Match> matches = scriptRegExp.allMatches(htmlContent);
|
||||
|
||||
Reference in New Issue
Block a user