Skip to content

Commit

Permalink
optimize: use ck
Browse files Browse the repository at this point in the history
  • Loading branch information
snowtafir committed Oct 31, 2024
1 parent 34aa146 commit db28a6c
Show file tree
Hide file tree
Showing 8 changed files with 688 additions and 325 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# 2.0.5
* 优化ck
* 新增 User-Agent 配置项
* 优化获取动态数据
* 新增获取B站up数据的随机延迟配置项
Expand Down
29 changes: 14 additions & 15 deletions apps/bilibili.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
readSyncCookie,
saveLocalBiliCk,
saveLoginCookie,
readTempCk
saveTempCk
} from '@/models/bilibili/bilibili.mian.models';

declare const logger: any;
Expand Down Expand Up @@ -278,12 +278,6 @@ export default class YukiBili extends Plugin {

let biliLoginCk = await pollLoginQRCode(this.e, token);

//let _uuid = readSavedCookieItems(biliLoginCk, ['_uuid'])

//const buvid_fp = await get_buvid_fp(_uuid);

//biliLoginCk = buvid_fp + biliLoginCk;

if (lodash.trim(biliLoginCk).length != 0) {
await saveLoginCookie(this.e, biliLoginCk);
this.e.reply(`get bilibili LoginCk:成功!`);
Expand Down Expand Up @@ -373,14 +367,10 @@ export default class YukiBili extends Plugin {
//筛选ck
localBiliCookie = await readSavedCookieItems(
localBiliCookie,
['buvid3', 'buvid4', '_uuid', 'SESSDATA', 'DedeUserID', 'DedeUserID__ckMd5', 'bili_jct', 'b_nut', 'b_lsid'],
['buvid3', 'buvid4', '_uuid', 'SESSDATA', 'DedeUserID', 'DedeUserID__ckMd5', 'bili_jct', 'b_nut', 'b_lsid', 'buvid_fp', 'sid'],
false
);

//const buvid_fp = await get_buvid_fp(param._uuid)

//localBiliCookie = buvid_fp + localBiliCookie; //添加buvid_fp值

await saveLocalBiliCk(localBiliCookie);

logger.mark(`${this.e.logFnc} 保存B站cookie成功 [UID:${param.DedeUserID}]`);
Expand Down Expand Up @@ -445,9 +435,18 @@ export default class YukiBili extends Plugin {
/** 删除并刷新redis缓存的临时B站ck */
async reflashTempCk() {
try {
await getNewTempCk();
let newTempCk = await readTempCk();
if (newTempCk !== null && newTempCk !== undefined && newTempCk.length !== 0 && newTempCk !== '') {
const newTempCk = await getNewTempCk();
if (newTempCk) {
await saveTempCk(newTempCk);
const result = await postGateway(newTempCk);

const data = await result.data; // 解析校验结果

if (data?.code !== 0) {
logger?.error(`优纪插件:tempCK,Gateway校验失败:${JSON.stringify(data)}`);
} else if (data?.code === 0) {
logger?.mark(`优纪插件:tempCK,Gateway校验成功:${JSON.stringify(data)}`);
}
this.e.reply(
`~yuki-plugin:\n临时b站ck刷新成功~❤~\n接下来如果获取动态失败,请重启bot(手动或发送指令 #重启)刷新状态~\n如果重启续仍不可用,请考虑 #优纪添加b站登录 吧~`
);
Expand Down
279 changes: 279 additions & 0 deletions models/bilibili/bilibili.main.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class BiliApi {
// 将静态常量赋值给实例属性
get BILIBIL_API() {
return {
//获取服务器端RTC时间戳
biliServerTimeStamp: 'https://api.live.bilibili.com/xlive/open-interface/v1/rtc/getTimestamp',
//获取动态资源列表 wbi/无wbi parama = { host_mid: uid, timezone_offset: -480, platform: 'web', features: 'itemOpusStyle,listOnlyfans,opusBigCover,onlyfansVote', web_location: "333.999", ...getDmImg(), "x-bili-device-req-json": { "platform": "web", "device": "pc" }, "x-bili-web-req-json": { "spm_id": "333.999" }, w_rid, wts }
biliDynamicInfoList: `https://api.bilibili.com/x/polymer/web-dynamic/v1/feed/space`,

Expand Down Expand Up @@ -131,6 +133,283 @@ class BiliApi {
'User-Agent': this.USER_AGENT
};
}

/**返回GatWay payload */
async BILIBILI_BROWSER_DATA(_uuid: string) {
return {
'3064': 1, // ptype, mobile => 2, others => 1
'5062': `${Date.now()}`, // timestamp
'03bf': 'https://www.bilibili.com/', // url accessed
'39c8': '333.999.fp.risk',
'34f1': '', // target_url, default empty now
'd402': '', // screenx, default empty
'654a': '', // screeny, default empty
'6e7c': '878x1066', // browser_resolution, window.innerWidth || document.body && document.body.clientWidth + "x" + window.innerHeight || document.body && document.body.clientHeight
'3c43': {
// 3c43 => msg
'2673': 0, // hasLiedResolution, window.screen.width < window.screen.availWidth || window.screen.height < window.screen.availHeight
'5766': 24, // colorDepth, window.screen.colorDepth
'6527': 0, // addBehavior, !!window.HTMLElement.prototype.addBehavior, html5 api
'7003': 1, // indexedDb, !!window.indexedDB, html5 api
'807e': 1, // cookieEnabled, navigator.cookieEnabled
'b8ce': this.USER_AGENT, // ua "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0",
'641c': 0, // webdriver, navigator.webdriver, like Selenium
'07a4': 'zh-CN', // language
'1c57': 'not available', // deviceMemory in GB, navigator.deviceMemory
'0bd0': 16, // hardwareConcurrency, navigator.hardwareConcurrency
'748e': [1920, 1200], // window.screen.width window.screen.height
'd61f': [1920, 1152], // window.screen.availWidth window.screen.availHeight
'fc9d': -480, // timezoneOffset, (new Date).getTimezoneOffset()
'6aa9': 'Asia/Shanghai', //Intl.DateTimeFormat().resolvedOptions().timeZone, // timezone, (new window.Intl.DateTimeFormat).resolvedOptions().timeZone
'75b8': 1, // sessionStorage, window.sessionStorage, html5 api
'3b21': 1, // localStorage, window.localStorage, html5 api
'8a1c': 0, // openDatabase, window.openDatabase, html5 api
'd52f': 'not available', // cpuClass, navigator.cpuClass
'adca': this.USER_AGENT.includes('Windows') ? 'Win32' : 'Linux', // platform, navigator.platform
'80c9': [
[
'PDF Viewer',
'Portable Document Format',
[
['application/pdf', 'pdf'],
['text/pdf', 'pdf']
]
],
[
'Chrome PDF Viewer',
'Portable Document Format',
[
['application/pdf', 'pdf'],
['text/pdf', 'pdf']
]
],
[
'Chromium PDF Viewer',
'Portable Document Format',
[
['application/pdf', 'pdf'],
['text/pdf', 'pdf']
]
],
[
'Microsoft Edge PDF Viewer',
'Portable Document Format',
[
['application/pdf', 'pdf'],
['text/pdf', 'pdf']
]
],
[
'WebKit built-in PDF',
'Portable Document Format',
[
['application/pdf', 'pdf'],
['text/pdf', 'pdf']
]
]
], // plugins
'13ab': 'f3YAAAAASUVORK5CYII=', // canvas fingerprint
'bfe9': 'kABYpRAGAVYzWJooB9Bf4P+UortSvxRY0AAAAASUVORK5CYII=', // webgl_str
'a3c1': [
'extensions:ANGLE_instanced_arrays;EXT_blend_minmax;EXT_color_buffer_half_float;EXT_float_blend;EXT_frag_depth;EXT_shader_texture_lod;EXT_sRGB;EXT_texture_compression_bptc;EXT_texture_compression_rgtc;EXT_texture_filter_anisotropic;OES_element_index_uint;OES_fbo_render_mipmap;OES_standard_derivatives;OES_texture_float;OES_texture_float_linear;OES_texture_half_float;OES_texture_half_float_linear;OES_vertex_array_object;WEBGL_color_buffer_float;WEBGL_compressed_texture_s3tc;WEBGL_compressed_texture_s3tc_srgb;WEBGL_debug_renderer_info;WEBGL_debug_shaders;WEBGL_depth_texture;WEBGL_draw_buffers;WEBGL_lose_context;WEBGL_provoking_vertex',
'webgl aliased line width range:[1, 1]',
'webgl aliased point size range:[1, 1024]',
'webgl alpha bits:8',
'webgl antialiasing:yes',
'webgl blue bits:8',
'webgl depth bits:24',
'webgl green bits:8',
'webgl max anisotropy:16',
'webgl max combined texture image units:32',
'webgl max cube map texture size:16384',
'webgl max fragment uniform vectors:1024',
'webgl max render buffer size:16384',
'webgl max texture image units:16',
'webgl max texture size:16384',
'webgl max varying vectors:30',
'webgl max vertex attribs:16',
'webgl max vertex texture image units:16',
'webgl max vertex uniform vectors:4096',
'webgl max viewport dims:[32767, 32767]',
'webgl red bits:8',
'webgl renderer:ANGLE (Intel, Intel(R) HD Graphics Direct3D11 vs_5_0 ps_5_0), or similar',
'webgl shading language version:WebGL GLSL ES 1.0',
'webgl stencil bits:0',
'webgl vendor:Mozilla',
'webgl version:WebGL 1.0',
'webgl unmasked vendor:Google Inc. (Intel)',
'webgl unmasked renderer:ANGLE (Intel, Intel(R) HD Graphics Direct3D11 vs_5_0 ps_5_0), or similar',
'webgl vertex shader high float precision:23',
'webgl vertex shader high float precision rangeMin:127',
'webgl vertex shader high float precision rangeMax:127',
'webgl vertex shader medium float precision:23',
'webgl vertex shader medium float precision rangeMin:127',
'webgl vertex shader medium float precision rangeMax:127',
'webgl vertex shader low float precision:23',
'webgl vertex shader low float precision rangeMin:127',
'webgl vertex shader low float precision rangeMax:127',
'webgl fragment shader high float precision:23',
'webgl fragment shader high float precision rangeMin:127',
'webgl fragment shader high float precision rangeMax:127',
'webgl fragment shader medium float precision:23',
'webgl fragment shader medium float precision rangeMin:127',
'webgl fragment shader medium float precision rangeMax:127',
'webgl fragment shader low float precision:23',
'webgl fragment shader low float precision rangeMin:127',
'webgl fragment shader low float precision rangeMax:127',
'webgl vertex shader high int precision:0',
'webgl vertex shader high int precision rangeMin:31',
'webgl vertex shader high int precision rangeMax:30',
'webgl vertex shader medium int precision:0',
'webgl vertex shader medium int precision rangeMin:31',
'webgl vertex shader medium int precision rangeMax:30',
'webgl vertex shader low int precision:0',
'webgl vertex shader low int precision rangeMin:31',
'webgl vertex shader low int precision rangeMax:30',
'webgl fragment shader high int precision:0',
'webgl fragment shader high int precision rangeMin:31',
'webgl fragment shader high int precision rangeMax:30',
'webgl fragment shader medium int precision:0',
'webgl fragment shader medium int precision rangeMin:31',
'webgl fragment shader medium int precision rangeMax:30',
'webgl fragment shader low int precision:0',
'webgl fragment shader low int precision rangeMin:31',
'webgl fragment shader low int precision rangeMax:30'
], // webgl_params, cab be set to [] if webgl is not supported
'6bc5': 'Google Inc. (Intel)~ANGLE (Intel, Intel(R) HD Graphics Direct3D11 vs_5_0 ps_5_0), or similar', // webglVendorAndRenderer
'ed31': 0,
'72bd': 0,
'097b': 0,
'52cd': [0, 0, 0],
'a658': [
'Arial',
'Arial Black',
'Calibri',
'Cambria',
'Cambria Math',
'Comic Sans MS',
'Consolas',
'Courier',
'Courier New',
'Georgia',
'Helvetica',
'Impact',
'Lucida Console',
'Lucida Sans Unicode',
'Microsoft Sans Serif',
'MS Gothic',
'MS PGothic',
'MS Sans Serif',
'MS Serif',
'Palatino Linotype',
'Segoe Print',
'Segoe Script',
'Segoe UI',
'Segoe UI Light',
'Segoe UI Symbol',
'Tahoma',
'Times',
'Times New Roman',
'Trebuchet MS',
'Verdana',
'Wingdings'
],
'd02f': '35.749972093850374'
},
'54ef': {
'in_new_ab ': true,
'ab_version ': {
'waterfall_article ': 'SHOW '
},
'ab_split_num ': {
'waterfall_article ': 0
}
},
'8b94': '',
'df35': `${_uuid}`, // _uuid, set from cookie, generated by client side(algorithm remains unknown)
'07a4': 'zh-CN',
'5f45': null,
'db46': 0
};
}

/**返回Bilibili Fingerprint data */
BILIBILI_FINGERPRINT_DATA(_uuid: string) {
return {
userAgent: this.USER_AGENT, // 用户代理
webdriver: false, // 是否是 WebDriver(例如 Selenium)
language: 'zh-CN', // 浏览器语言
colorDepth: 24, // 屏幕颜色深度
deviceMemory: 'not available', // 设备内存(GB)
pixelRatio: 2, // 设备像素比
hardwareConcurrency: 8, // 处理器核心数量
screenResolution: '1920x1200', // 屏幕分辨率
availableScreenResolution: '1920x1152', // 可用屏幕分辨率
timezoneOffset: -480, // 时区偏移,单位为分钟
timezone: 'Asia/Shanghai', // 时区
sessionStorage: true, // 是否支持 sessionStorage
localStorage: true, // 是否支持 localStorage
indexedDb: true, // 是否支持 IndexedDB
addBehavior: false, // 是否支持 addBehavior
openDatabase: false, // 是否支持 openDatabase
cpuClass: 'not available', // CPU 类型amd 或 intel 或 not available
platform: this.USER_AGENT.includes('Windows') ? 'Win32' : 'Linux', // 操作系统平台,例如 Windows,Linux,Mac
doNotTrack: null, // DNT 设置,通常是 `navigator.doNotTrack`
plugins: [
{ name: 'PDF Viewer', description: 'Portable Document Format', mimeTypes: [['application/pdf', 'pdf']] },
{ name: 'Chrome PDF Viewer', description: 'Portable Document Format', mimeTypes: [['application/pdf', 'pdf']] },
{ name: 'Chromium PDF Viewer', description: 'Portable Document Format', mimeTypes: [['application/pdf', 'pdf']] },
{ name: 'Microsoft Edge PDF Viewer', description: 'Portable Document Format', mimeTypes: [['application/pdf', 'pdf']] },
{ name: 'WebKit built-in PDF', description: 'Portable Document Format', mimeTypes: [['application/pdf', 'pdf']] }
],
canvas: 'f3YAAAAASUVORK5CYII=', // Canvas 指纹
webgl: 'kABYpRAGAVYzWJooB9Bf4P+UortSvxRY0AAAAASUVORK5CYII=', // WebGL 参数
webglVendorAndRenderer: 'Google Inc. (Intel)~ANGLE (Intel, Intel(R) HD Graphics Direct3D11 vs_5_0 ps_5_0), or similar', // WebGL 的厂商和渲染器信息
adBlock: false, // 是否检测到广告拦截器
hasLiedLanguages: false, // 是否谎称语言
hasLiedResolution: false, // 是否谎称分辨率
hasLiedOs: false, // 是否谎称操作系统
hasLiedBrowser: false, // 是否谎称浏览器
touchSupport: 0, // 支持的触摸点数
fonts: [
'Arial',
'Arial Black',
'Calibri',
'Cambria',
'Cambria Math',
'Comic Sans MS',
'Consolas',
'Courier',
'Courier New',
'Georgia',
'Helvetica',
'Impact',
'Lucida Console',
'Lucida Sans Unicode',
'Microsoft Sans Serif',
'MS Gothic',
'MS PGothic',
'MS Sans Serif',
'MS Serif',
'Palatino Linotype',
'Segoe Print',
'Segoe Script',
'Segoe UI',
'Segoe UI Light',
'Segoe UI Symbol',
'Tahoma',
'Times',
'Times New Roman',
'Trebuchet MS',
'Verdana',
'Wingdings'
],
fontsFlash: false, // Flash 插件是否安装
audio: '35.749972093850374', // 音频指纹
enumerateDevices: [`id=${_uuid};gid=groupId1;kind=videoinput;label=Camera1`, `id=${_uuid};gid=groupId2;kind=audioinput;label=Microphone1`]
// 枚举设备指纹,Unreliable on Windows, see https://github.com/fingerprintjs/fingerprintjs/issues/375
};
}
}

export default new BiliApi();
1 change: 0 additions & 1 deletion models/bilibili/bilibili.main.get.web.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export class BiliGetWebData {
const { w_rid, time_stamp } = await getWbiSign(data, BiliApi.BILIBILI_HEADERS, signCookie);
const params = {
...data,
w_webid: w_webid,
w_rid: w_rid,
wts: time_stamp
};
Expand Down
Loading

0 comments on commit db28a6c

Please sign in to comment.