Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/service/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { SearchTypes } from "../const/ENUM";
import { SearchAPI } from "../const/URL";
import axios from "axios";
import { getCookieJar } from "../global/cookie";
import { b } from '../util/g_encrypt'
import * as md5 from 'md5';
import { genXZse96 } from "../util/genXZse96";

export const SearchDict = [
{ value: SearchTypes.general, ch: '综合' },
{ value: SearchTypes.question, ch: '问题' },
Expand All @@ -30,18 +30,15 @@ export class SearchService {
search_source: "Normal",
};
const cookie = getCookieJar().getCookieStringSync(SearchAPI);
let cookieData = cookie.split("d_c0=")[1].split(';')[0];
const str = `101_3_2.0+/api/v4/search_v3?t=${searchType}&q=${keyword}&correction=1&offset=0&limit=20&filter_fields=&lc_idx=0&show_all_topics=0&search_source=Normal+${cookieData}`
console.log({str})
const data = md5(str);
const x_zse_96 = "2.0_" + b(data)
const api = `/api/v4/search_v3?t=${searchType}&q=${encodeURIComponent(keyword)}&correction=1&offset=0&limit=20&filter_fields=&lc_idx=0&show_all_topics=0&search_source=Normal`

const result = await axios({
url: `https://www.zhihu.com/api/v4/search_v3`,
params,
method: "GET",
headers: {
"x-zse-93": "101_3_2.0",
"x-zse-96": x_zse_96,
"x-zse-96": genXZse96(api, cookie),
cookie
},
});
Expand Down
22 changes: 19 additions & 3 deletions src/service/webview.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { CollectionTreeviewProvider } from "../treeview/collection-treeview-prov
import { CollectionService, ICollectionItem } from "./collection.service";
import { HttpService, sendRequest } from "./http.service";
import { getExtensionPath, getSubscriptions } from "../global/globa-var";
import { getCookieJar } from "../global/cookie";
import { genXZse96 } from "../util/genXZse96";

export interface IWebviewPugRender {
viewType?: string,
Expand Down Expand Up @@ -79,7 +81,7 @@ export class WebviewService {
"questions-answers.pug"
),
pugObjects: {
answers: body.data.map(t => {
answers: body.data.map(t => {
t.content = this.actualSrcNormalize(t.content);
return t;
}),
Expand Down Expand Up @@ -140,6 +142,8 @@ export class WebviewService {
}

private registerEvent(panel: vscode.WebviewPanel, c: ICollectionItem, link?: string) {
const cookie = getCookieJar().getCookieStringSync(AnswerAPI);

panel.webview.onDidReceiveMessage(e => {
if (e.command == WebviewEvents.collect) {
if (this.collectService.addItem(c)) {
Expand All @@ -155,20 +159,32 @@ export class WebviewService {
vscode.window.showInformationMessage('链接已复制至粘贴板。');
})
} else if (e.command == WebviewEvents.upvoteAnswer) {
const tempApi = `/api/v4/answers/${e.id}/voters`
sendRequest({
uri: `${AnswerAPI}/${e.id}/voters`,
method: 'post',
headers: {},
headers: {
"x-requested-with": "fetch",
"x-zse-93": "101_3_2.0",
"x-zse-96": genXZse96(tempApi,cookie,['{"type":"up"}']),
cookie
},
json: true,
body: { type: "up" },
resolveWithFullResponse: true
}).then(r => {if(r.statusCode == 200) vscode.window.showInformationMessage('点赞成功!')
else if(r.statusCode == 403) vscode.window.showWarningMessage('你已经投过票了!')})
} else if (e.command == WebviewEvents.upvoteArticle) {
const tempApi = `/api/v4/articles/${e.id}/voters`
sendRequest({
uri: `${ArticleAPI}/${e.id}/voters`,
method: 'post',
headers: {},
headers: {
"x-requested-with": "fetch",
"x-zse-93": "101_3_2.0",
"x-zse-96": genXZse96(tempApi,cookie,['{"voting":1}']),
cookie
},
json: true,
body: { voting: 1 },
resolveWithFullResponse: true
Expand Down
30 changes: 30 additions & 0 deletions src/util/genXZse96.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { b } from "./g_encrypt";
import * as md5 from "md5";

/**
*
* @param api api(去除https://zhihu.com后的部分),可能携带参数,如:101_3_2.0+/api/v4/answers/529335326/voters+"AKCftBUl9BOPTrRxAbXw2tHou6s3tz8zIns=|1635581798"+{"type":"up"}
* @param cookie cookie的某个字段
* @param x_zse_93
* @param cookieKey
* @param dataArr 字符串数组,添加到末尾的其他字段
* @returns
*/
export function genXZse96(
api: string,
cookie: string,
dataArr: string[] = [],
x_zse_93: string = "101_3_2.0",
cookieKey: string = "d_c0="
) {
const cookieStr = cookie.split(cookieKey)[1].split(";")[0];
let tempStr = `${x_zse_93}+${api}+${cookieStr}`;
let len = dataArr.length;
if (len) {
dataArr.map((item, index) => {
tempStr += "+" + item;
});
}
console.log({ tempStr });
return `2.0_${b(md5(tempStr))}`;
}