fix(route): zhihu x-zse-96 v3 (#11022)

* fix(route): zhihu x-zse-96 v3

* revert: "chore: fix docker build (#10956)"

This reverts commit 5af05ea618.

* revert: "fix(dockerfile): add missing librsvg2 for arm64/v7 (#11021)"

This reverts commit f340a9072e.

* chore: yarn rebuild

* fix: typo

* refactor: simpler got request

* fix: misc fixes
This commit is contained in:
Tony 2022-10-08 04:11:58 +09:00 committed by GitHub
parent f340a9072e
commit 8486e9dd2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 130 additions and 634 deletions

View File

@ -6,7 +6,6 @@ WORKDIR /app
# place ARG statement before RUN statement which need it to avoid cache miss
ARG USE_CHINA_NPM_REGISTRY=0
ARG TARGETPLATFORM
RUN \
set -ex && \
if [ "$USE_CHINA_NPM_REGISTRY" = 1 ]; then \
@ -18,15 +17,6 @@ RUN \
COPY ./yarn.lock /app/
COPY ./package.json /app/
# required for building canvas in arm64 and arm/v7 (introduce in #10954)
RUN \
set -ex && \
if [ "$TARGETPLATFORM" != "linux/amd64" ]; then \
apt-get update && \
apt-get install -yq --no-install-recommends \
libpango1.0-dev ; \
fi;
# lazy install Chromium to avoid cache miss, only install production dependencies to minimize the image size
RUN \
set -ex && \
@ -146,7 +136,7 @@ RUN \
; \
else \
apt-get install -yq --no-install-recommends \
chromium librsvg2-2 \
chromium \
&& \
echo 'CHROMIUM_EXECUTABLE_PATH=chromium' | tee /app/.env ; \
fi; \

View File

@ -1,9 +1,8 @@
/* eslint-disable no-console */
const got = require('@/utils/got');
const utils = require('./utils');
const { parseDate } = require('@/utils/parse-date');
const g_encrypt = require('./execlib/g_encrypt_3');
const zhihu_hash = require('./execlib/hash.js');
const g_encrypt = require('./execlib/x-zse-96_v3');
const md5 = require('@/utils/md5');
module.exports = async (ctx) => {
const id = ctx.params.id;
@ -14,9 +13,7 @@ module.exports = async (ctx) => {
// fisrt: get cookie(dc_0) from zhihu.com
const cookie_mes = await ctx.cache.tryGet('zhihu:cookies:d_c0', async () => {
const response = await got({
method: 'get',
url: `https://www.zhihu.com/people/${id}`,
const response = await got(`https://www.zhihu.com/people/${id}`, {
headers: {
...utils.header,
},
@ -38,12 +35,10 @@ module.exports = async (ctx) => {
// calculate x-zse-96, refer to https://github.com/srx-2000/spider_collection/issues/18
const f = `101_3_3.0+${apiPath}+${cookie_mes}`;
const xzse96 = '2.0_' + g_encrypt(zhihu_hash(f));
const xzse96 = '2.0_' + g_encrypt(md5(f));
const _header = { cookie, 'x-zse-96': xzse96, 'x-app-za': 'OS=Web', 'x-zse-93': '101_3_3.0' };
const response = await got({
method: 'get',
url: `https://www.zhihu.com/api/v3/moments/${id}/activities?limit=7&desktop=true`,
const response = await got(`https://www.zhihu.com${apiPath}`, {
headers: {
...utils.header,
..._header,

File diff suppressed because one or more lines are too long

View File

@ -1,155 +0,0 @@
function o(e, t) {
const n = (65535 & e) + (65535 & t);
return (((e >> 16) + (t >> 16) + (n >> 16)) << 16) | (65535 & n);
}
function a(e, t, n, r, i, a) {
let c, u;
return o(((c = o(o(t, e), o(r, a))) << (u = i)) | (c >>> (32 - u)), n);
}
function c(e, t, n, r, i, o, c) {
return a((t & n) | (~t & r), e, t, i, o, c);
}
function u(e, t, n, r, i, o, c) {
return a((t & r) | (n & ~r), e, t, i, o, c);
}
function s(e, t, n, r, i, o, c) {
return a(t ^ n ^ r, e, t, i, o, c);
}
function l(e, t, n, r, i, o, c) {
return a(n ^ (t | ~r), e, t, i, o, c);
}
function d(e, t) {
let n, r, i, a, d;
(e[t >> 5] |= 128 << t % 32), (e[14 + (((t + 64) >>> 9) << 4)] = t);
let f = 1732584193,
p = -271733879,
h = -1732584194,
b = 271733878;
for (n = 0; n < e.length; n += 16) {
(r = f),
(i = p),
(a = h),
(d = b),
(f = c(f, p, h, b, e[n], 7, -680876936)),
(b = c(b, f, p, h, e[n + 1], 12, -389564586)),
(h = c(h, b, f, p, e[n + 2], 17, 606105819)),
(p = c(p, h, b, f, e[n + 3], 22, -1044525330)),
(f = c(f, p, h, b, e[n + 4], 7, -176418897)),
(b = c(b, f, p, h, e[n + 5], 12, 1200080426)),
(h = c(h, b, f, p, e[n + 6], 17, -1473231341)),
(p = c(p, h, b, f, e[n + 7], 22, -45705983)),
(f = c(f, p, h, b, e[n + 8], 7, 1770035416)),
(b = c(b, f, p, h, e[n + 9], 12, -1958414417)),
(h = c(h, b, f, p, e[n + 10], 17, -42063)),
(p = c(p, h, b, f, e[n + 11], 22, -1990404162)),
(f = c(f, p, h, b, e[n + 12], 7, 1804603682)),
(b = c(b, f, p, h, e[n + 13], 12, -40341101)),
(h = c(h, b, f, p, e[n + 14], 17, -1502002290)),
(f = u(f, (p = c(p, h, b, f, e[n + 15], 22, 1236535329)), h, b, e[n + 1], 5, -165796510)),
(b = u(b, f, p, h, e[n + 6], 9, -1069501632)),
(h = u(h, b, f, p, e[n + 11], 14, 643717713)),
(p = u(p, h, b, f, e[n], 20, -373897302)),
(f = u(f, p, h, b, e[n + 5], 5, -701558691)),
(b = u(b, f, p, h, e[n + 10], 9, 38016083)),
(h = u(h, b, f, p, e[n + 15], 14, -660478335)),
(p = u(p, h, b, f, e[n + 4], 20, -405537848)),
(f = u(f, p, h, b, e[n + 9], 5, 568446438)),
(b = u(b, f, p, h, e[n + 14], 9, -1019803690)),
(h = u(h, b, f, p, e[n + 3], 14, -187363961)),
(p = u(p, h, b, f, e[n + 8], 20, 1163531501)),
(f = u(f, p, h, b, e[n + 13], 5, -1444681467)),
(b = u(b, f, p, h, e[n + 2], 9, -51403784)),
(h = u(h, b, f, p, e[n + 7], 14, 1735328473)),
(f = s(f, (p = u(p, h, b, f, e[n + 12], 20, -1926607734)), h, b, e[n + 5], 4, -378558)),
(b = s(b, f, p, h, e[n + 8], 11, -2022574463)),
(h = s(h, b, f, p, e[n + 11], 16, 1839030562)),
(p = s(p, h, b, f, e[n + 14], 23, -35309556)),
(f = s(f, p, h, b, e[n + 1], 4, -1530992060)),
(b = s(b, f, p, h, e[n + 4], 11, 1272893353)),
(h = s(h, b, f, p, e[n + 7], 16, -155497632)),
(p = s(p, h, b, f, e[n + 10], 23, -1094730640)),
(f = s(f, p, h, b, e[n + 13], 4, 681279174)),
(b = s(b, f, p, h, e[n], 11, -358537222)),
(h = s(h, b, f, p, e[n + 3], 16, -722521979)),
(p = s(p, h, b, f, e[n + 6], 23, 76029189)),
(f = s(f, p, h, b, e[n + 9], 4, -640364487)),
(b = s(b, f, p, h, e[n + 12], 11, -421815835)),
(h = s(h, b, f, p, e[n + 15], 16, 530742520)),
(f = l(f, (p = s(p, h, b, f, e[n + 2], 23, -995338651)), h, b, e[n], 6, -198630844)),
(b = l(b, f, p, h, e[n + 7], 10, 1126891415)),
(h = l(h, b, f, p, e[n + 14], 15, -1416354905)),
(p = l(p, h, b, f, e[n + 5], 21, -57434055)),
(f = l(f, p, h, b, e[n + 12], 6, 1700485571)),
(b = l(b, f, p, h, e[n + 3], 10, -1894986606)),
(h = l(h, b, f, p, e[n + 10], 15, -1051523)),
(p = l(p, h, b, f, e[n + 1], 21, -2054922799)),
(f = l(f, p, h, b, e[n + 8], 6, 1873313359)),
(b = l(b, f, p, h, e[n + 15], 10, -30611744)),
(h = l(h, b, f, p, e[n + 6], 15, -1560198380)),
(p = l(p, h, b, f, e[n + 13], 21, 1309151649)),
(f = l(f, p, h, b, e[n + 4], 6, -145523070)),
(b = l(b, f, p, h, e[n + 11], 10, -1120210379)),
(h = l(h, b, f, p, e[n + 2], 15, 718787259)),
(p = l(p, h, b, f, e[n + 9], 21, -343485551)),
(f = o(f, r)),
(p = o(p, i)),
(h = o(h, a)),
(b = o(b, d));
}
return [f, p, h, b];
}
function f(e) {
let t,
n = '';
const r = 32 * e.length;
for (t = 0; t < r; t += 8) {
n += String.fromCharCode((e[t >> 5] >>> t % 32) & 255);
}
return n;
}
function p(e) {
let t;
const n = [];
for (n[(e.length >> 2) - 1] = void 0, t = 0; t < n.length; t += 1) {
n[t] = 0;
}
const r = 8 * e.length;
for (t = 0; t < r; t += 8) {
n[t >> 5] |= (255 & e.charCodeAt(t / 8)) << t % 32;
}
return n;
}
function h(e) {
let t,
n,
r = '';
for (n = 0; n < e.length; n += 1) {
(t = e.charCodeAt(n)), (r += '0123456789abcdef'.charAt((t >>> 4) & 15) + '0123456789abcdef'.charAt(15 & t));
}
return r;
}
function b(e) {
return unescape(encodeURIComponent(e));
}
function v(e) {
return (function (e) {
return f(d(p(e), 8 * e.length));
})(b(e));
}
function A(e) {
return h(v(e));
}
module.exports = A;

View File

@ -0,0 +1,122 @@
// Credit:
// https://blog.csdn.net/zjq592767809/article/details/126512798
// https://blog.csdn.net/zhoumi_/article/details/126659351
function i(e, t, n) {
(t[n] = 255 & (e >>> 24)), (t[n + 1] = 255 & (e >>> 16)), (t[n + 2] = 255 & (e >>> 8)), (t[n + 3] = 255 & e);
}
function B(e, t) {
return ((255 & e[t]) << 24) | ((255 & e[t + 1]) << 16) | ((255 & e[t + 2]) << 8) | (255 & e[t + 3]);
}
function Q(e, t) {
return ((4294967295 & e) << t) | (e >>> (32 - t));
}
function G(e) {
const t = new Array(4);
const n = new Array(4);
i(e, t, 0), (n[0] = h.zb[255 & t[0]]), (n[1] = h.zb[255 & t[1]]), (n[2] = h.zb[255 & t[2]]), (n[3] = h.zb[255 & t[3]]);
const r = B(n, 0);
return r ^ Q(r, 2) ^ Q(r, 10) ^ Q(r, 18) ^ Q(r, 24);
}
const __g = {
x(e, t) {
let n = [];
for (let r = e.length, i = 0; 0 < r; r -= 16) {
const a = new Array(16);
for (let o = e.slice(16 * i, 16 * (i + 1)), c = 0; c < 16; c++) {
a[c] = o[c] ^ t[c];
}
(t = __g.r(a)), (n = n.concat(t)), i++;
}
return n;
},
r(e) {
const t = new Array(16);
const n = new Array(36);
(n[0] = B(e, 0)), (n[1] = B(e, 4)), (n[2] = B(e, 8)), (n[3] = B(e, 12));
for (let r = 0; r < 32; r++) {
const o = G(n[r + 1] ^ n[r + 2] ^ n[r + 3] ^ h.zk[r]);
n[r + 4] = n[r] ^ o;
}
return i(n[35], t, 0), i(n[34], t, 4), i(n[33], t, 8), i(n[32], t, 12), t;
},
};
const h = {
zk: [
1170614578, 1024848638, 1413669199, -343334464, -766094290, -1373058082, -143119608, -297228157, 1933479194, -971186181, -406453910, 460404854, -547427574, -1891326262, -1679095901, 2119585428, -2029270069, 2035090028,
-1521520070, -5587175, -77751101, -2094365853, -1243052806, 1579901135, 1321810770, 456816404, -1391643889, -229302305, 330002838, -788960546, 363569021, -1947871109,
],
zb: [
20, 223, 245, 7, 248, 2, 194, 209, 87, 6, 227, 253, 240, 128, 222, 91, 237, 9, 125, 157, 230, 93, 252, 205, 90, 79, 144, 199, 159, 197, 186, 167, 39, 37, 156, 198, 38, 42, 43, 168, 217, 153, 15, 103, 80, 189, 71, 191, 97, 84,
247, 95, 36, 69, 14, 35, 12, 171, 28, 114, 178, 148, 86, 182, 32, 83, 158, 109, 22, 255, 94, 238, 151, 85, 77, 124, 254, 18, 4, 26, 123, 176, 232, 193, 131, 172, 143, 142, 150, 30, 10, 146, 162, 62, 224, 218, 196, 229, 1,
192, 213, 27, 110, 56, 231, 180, 138, 107, 242, 187, 54, 120, 19, 44, 117, 228, 215, 203, 53, 239, 251, 127, 81, 11, 133, 96, 204, 132, 41, 115, 73, 55, 249, 147, 102, 48, 122, 145, 106, 118, 74, 190, 29, 16, 174, 5, 177,
129, 63, 113, 99, 31, 161, 76, 246, 34, 211, 13, 60, 68, 207, 160, 65, 111, 82, 165, 67, 169, 225, 57, 112, 244, 155, 51, 236, 200, 233, 58, 61, 47, 100, 137, 185, 64, 17, 70, 234, 163, 219, 108, 170, 166, 59, 149, 52, 105,
24, 212, 78, 173, 45, 0, 116, 226, 119, 136, 206, 135, 175, 195, 25, 92, 121, 208, 126, 139, 3, 75, 141, 21, 130, 98, 241, 40, 154, 66, 184, 49, 181, 46, 243, 88, 101, 183, 8, 23, 72, 188, 104, 179, 210, 134, 250, 201, 164,
89, 216, 202, 220, 50, 221, 152, 140, 33, 235, 214,
],
// zm: [120, 50, 98, 101, 99, 98, 119, 100, 103, 107, 99, 119, 97, 99, 110, 111], // not used
};
const encode = (param) => {
const salt = '6fpLRqJO8M/c3jnYxFkUVC4ZIG12SiH=5v0mXDazWBTsuw7QetbKdoPyAl+hN9rgE';
let result = '';
for (const x of [0, 6, 12, 18]) {
const a = param >>> x;
const b = a & 63;
const c = salt.charAt(b);
result += c;
}
return result;
};
const preProcess = (md5Str) => {
const md5CharCodeAtArr = [];
for (let i = 0; i < md5Str.length; i++) {
md5CharCodeAtArr.push(md5Str.charCodeAt(i));
}
md5CharCodeAtArr.unshift(0);
md5CharCodeAtArr.unshift(Math.random() * 127);
for (let i = 0; i < 15; i++) {
md5CharCodeAtArr.push(14);
}
const md5CharCodeAtFrontArr = md5CharCodeAtArr.slice(0, 16);
const fixArr = [48, 53, 57, 48, 53, 51, 102, 55, 100, 49, 53, 101, 48, 49, 100, 55];
const new_md5_charCodeAt_arr = [];
for (let i = 0; i < md5CharCodeAtFrontArr.length; i++) {
new_md5_charCodeAt_arr.push(md5CharCodeAtFrontArr[i] ^ fixArr[i] ^ 42);
}
const __g_r = __g.r(new_md5_charCodeAt_arr);
const md5CharCodeAtBackArr = md5CharCodeAtArr.slice(16, 48);
const __g_x = __g.x(md5CharCodeAtBackArr, __g_r);
return __g_r.concat(__g_x);
};
const encrypt = (md5Str) => {
const processed = preProcess(md5Str);
let current = 0;
let resultStr = '';
for (let i = 0; i < processed.length; i++) {
const pop = processed[processed.length - i - 1];
const i_mod_4 = i % 4;
const i_mod_3 = i % 3;
const a = 8 * i_mod_4;
const b = 58 >>> a;
const c = b & 255;
const d = pop ^ c;
const e = d << (8 * i_mod_3);
current |= e;
if (i_mod_3 === 2) {
resultStr += encode(current);
current = 0;
}
}
return resultStr;
};
module.exports = encrypt;

View File

@ -87,7 +87,6 @@
"aes-js": "3.1.2",
"art-template": "4.13.2",
"bbcodejs": "0.0.4",
"canvas": "2.10.1",
"cheerio": "1.0.0-rc.12",
"chrono-node": "2.4.1",
"city-timezones": "1.2.1",

View File

@ -1333,7 +1333,7 @@
resolved "https://registry.yarnpkg.com/@lifeomic/attempt/-/attempt-3.0.3.tgz#e742a5b85eb673e2f1746b0f39cb932cbc6145bb"
integrity sha512-GlM2AbzrErd/TmLL3E8hAHmb5Q7VhDJp35vIbyPVA5Rz55LZuRr8pwL3qrwwkVNo05gMX1J44gURKb4MHQZo7w==
"@mapbox/node-pre-gyp@^1.0.0", "@mapbox/node-pre-gyp@^1.0.5":
"@mapbox/node-pre-gyp@^1.0.5":
version "1.0.10"
resolved "https://registry.yarnpkg.com/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.10.tgz#8e6735ccebbb1581e5a7e652244cadc8a844d03c"
integrity sha512-4ySo4CjzStuprMwk35H5pPbkymjv1SF3jGLj6rAHp/xT/RF7TL7bd9CTm1xDY49K2qF7jmR/g7k+SkLETP6opA==
@ -3713,15 +3713,6 @@ caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001400:
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001409.tgz#6135da9dcab34cd9761d9cdb12a68e6740c5e96e"
integrity sha512-V0mnJ5dwarmhYv8/MzhJ//aW68UpvnQBXv8lJ2QUsvn2pHcmAuNtu8hQEDz37XnA1iE+lRR9CIfGWWpgJ5QedQ==
canvas@2.10.1:
version "2.10.1"
resolved "https://registry.yarnpkg.com/canvas/-/canvas-2.10.1.tgz#fbfd4b1b3b106c3454481d79d363ebadf8811c08"
integrity sha512-29pIjn9uwTUsIgJUNd7GXxKk8sg4iyJwLm1wIilNIqX1mVzXSc2nUij9exW1LqNpis1d2ebMYfMqTWcokZ4pdA==
dependencies:
"@mapbox/node-pre-gyp" "^1.0.0"
nan "^2.15.0"
simple-get "^3.0.3"
caseless@~0.12.0:
version "0.12.0"
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"
@ -4744,13 +4735,6 @@ decompress-response@^3.3.0:
dependencies:
mimic-response "^1.0.0"
decompress-response@^4.2.0:
version "4.2.1"
resolved "https://registry.yarnpkg.com/decompress-response/-/decompress-response-4.2.1.tgz#414023cc7a302da25ce2ec82d0d5238ccafd8986"
integrity sha512-jOSne2qbyE+/r8G1VU+G/82LBs2Fs4LAsTiLSHOCOMZQl2OKZ6i8i4IyHemTe+/yIXOtTcRQMzPcgyhoFlqPkw==
dependencies:
mimic-response "^2.0.0"
decompress-response@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/decompress-response/-/decompress-response-5.0.0.tgz#7849396e80e3d1eba8cb2f75ef4930f76461cb0f"
@ -9931,7 +9915,7 @@ mz@^2.7.0:
object-assign "^4.0.1"
thenify-all "^1.0.0"
nan@^2.12.1, nan@^2.15.0, nan@^2.16.0:
nan@^2.12.1, nan@^2.16.0:
version "2.16.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.16.0.tgz#664f43e45460fb98faf00edca0bb0d7b8dce7916"
integrity sha512-UdAqHyFngu7TfQKsCBgAA6pWDkT8MAO7d0jyOecVhN5354xbLqdn8mV9Tat9gepAupm0bt2DbeaSC8vS52MuFA==
@ -12448,15 +12432,6 @@ simple-concat@^1.0.0:
resolved "https://registry.yarnpkg.com/simple-concat/-/simple-concat-1.0.1.tgz#f46976082ba35c2263f1c8ab5edfe26c41c9552f"
integrity sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==
simple-get@^3.0.3:
version "3.1.1"
resolved "https://registry.yarnpkg.com/simple-get/-/simple-get-3.1.1.tgz#cc7ba77cfbe761036fbfce3d021af25fc5584d55"
integrity sha512-CQ5LTKGfCpvE1K0n2us+kuMPbk/q0EKl82s4aheV9oXjFEz6W/Y7oQFVJuU6QG77hRT4Ghb5RURteF5vnWjupA==
dependencies:
decompress-response "^4.2.0"
once "^1.3.1"
simple-concat "^1.0.0"
simple-get@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/simple-get/-/simple-get-4.0.1.tgz#4a39db549287c979d352112fa03fd99fd6bc3543"