-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(src/search-app/hono-app): add: 4399 用户名查询,哔哩哔哩用户查询
- Loading branch information
Showing
7 changed files
with
288 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,7 @@ dist | |
package-lock.json | ||
yarn.lock | ||
pnpm-lock.yaml | ||
bun.lockb | ||
bun.lockb | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,65 @@ | ||
import { Hono } from 'hono' | ||
import { Hono } from "hono"; | ||
import { cors } from "hono/cors"; | ||
import { env } from "hono/adapter"; | ||
import { swaggerUI } from "@hono/swagger-ui"; | ||
import game4399account from "./plugins/game4399account"; | ||
import bilibiliUser from "./plugins/bilibili-user"; | ||
|
||
const app = new Hono() | ||
const app = new Hono(); | ||
// https://hono.dev/middleware/builtin/cors | ||
app.use("/*", cors()); | ||
// https://github.com/honojs/middleware/tree/main/packages/swagger-ui | ||
// Use the middleware to serve Swagger UI at /ui | ||
// app.get('/ui', swaggerUI({ url: '/doc' })) | ||
|
||
app.get('/', (c) => { | ||
return c.text('Hello Hono!') | ||
}) | ||
app.get("/", (c) => { | ||
return c.json({ | ||
name: "搜索 API", | ||
version: "1.0.0", | ||
plugins: [ | ||
{ | ||
name: "4399 用户名查询", | ||
url: "/api/plugins/game4399account?q={q}", | ||
test: "/api/plugins/game4399account?q=21434", | ||
}, | ||
{ | ||
name: "哔哩哔哩用户查询", | ||
url: "/api/plugins/bilibili-user?q={q}", | ||
test: "/api/plugins/bilibili-user?q=测试用户", | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
export default app | ||
app.get("/api/plugins/game4399account", async (c) => { | ||
const q = c.req.query("q"); | ||
if (!q) { | ||
return c.json({ | ||
code: -1, | ||
message: "参数错误", | ||
data: [], | ||
}); | ||
} | ||
const res = await game4399account(q); | ||
|
||
return c.json(res); | ||
}); | ||
|
||
app.get("/api/plugins/bilibili-user", async (c) => { | ||
const q = c.req.query("q"); | ||
if (!q) { | ||
return c.json({ | ||
code: -1, | ||
message: "参数错误", | ||
data: [], | ||
}); | ||
} | ||
const { PLUGINS_BILIBILI_USER_COOKIE } = env<{ | ||
PLUGINS_BILIBILI_USER_COOKIE: string; | ||
}>(c); | ||
const res = await bilibiliUser(q, PLUGINS_BILIBILI_USER_COOKIE); | ||
|
||
return c.json(res); | ||
}); | ||
|
||
export default app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import type { BaseResponseModel } from "../types/baseReponseModel"; | ||
|
||
|
||
interface BilibiliUserDataItemModel { | ||
/** | ||
* 用户名 | ||
*/ | ||
uname: string; | ||
/** | ||
* 头像 | ||
*/ | ||
upic: string; | ||
|
||
/** | ||
* 签名 | ||
*/ | ||
usign: string; | ||
|
||
/** | ||
* 投稿视频个数 | ||
*/ | ||
videos: number; | ||
|
||
/** | ||
* 粉丝个数 | ||
*/ | ||
fans: number; | ||
|
||
/** | ||
* 等级 | ||
*/ | ||
level: number; | ||
|
||
/** | ||
* https://space.bilibili.com/25057459 | ||
*/ | ||
url: string; | ||
} | ||
|
||
export default async function query( | ||
query: string, | ||
cookie: string, | ||
): Promise<BaseResponseModel<BilibiliUserDataItemModel>> { | ||
const responseModel: BaseResponseModel<BilibiliUserDataItemModel> = { | ||
code: -1, | ||
message: "失败", | ||
data: [], | ||
}; | ||
try { | ||
const res = await fetch( | ||
`https://api.bilibili.com/x/web-interface/wbi/search/type?` + | ||
new URLSearchParams({ | ||
category_id: "", | ||
search_type: "bili_user", | ||
ad_resource: "5646", | ||
__refresh__: "true", | ||
page: "1", | ||
page_size: "36", | ||
platform: "pc", | ||
highlight: "1", | ||
single_column: "0", | ||
keyword: query.trim(), | ||
qv_id: "drhuMbLFmLakkilY2NVwvZlCArwuxzso", | ||
source_tag: "3", | ||
order_sort: "0", | ||
user_type: "0", | ||
dynamic_offset: "0", | ||
web_location: "1430654", | ||
w_rid: "c69cf3c4599ba1fcd0429dcfad83f2e8", | ||
wts: "1712952282", | ||
}), | ||
{ | ||
method: "GET", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"User-Agent": `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36`, | ||
Referer: | ||
`https://search.bilibili.com/upuser?` + | ||
new URLSearchParams({ | ||
keyword: query.trim(), | ||
search_source: "5", | ||
}), | ||
Accept: "application/json, text/plain, */*", | ||
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8", | ||
Origin: "https://search.bilibili.com", | ||
"Sec-Ch-Ua": `"Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123"`, | ||
Cookie: `${cookie}` | ||
}, | ||
} | ||
); | ||
|
||
console.log("res", res); | ||
|
||
if (res.ok) { | ||
responseModel.code = 1; | ||
responseModel.message = "成功"; | ||
const resJson: any = await res.json(); | ||
if ( | ||
resJson.code === 0 && | ||
resJson.data?.result && | ||
resJson.data?.result.length > 0 | ||
) { | ||
resJson.data.result.forEach((item: any) => { | ||
responseModel.data.push({ | ||
uname: item.uname, | ||
upic: `${item.upic.replace("//", "http://")}`, | ||
usign: item.usign, | ||
videos: item.videos, | ||
fans: item.fans, | ||
level: item.level, | ||
url: `https://space.bilibili.com/${item.mid}`, | ||
}); | ||
}); | ||
} | ||
} | ||
} catch (error) { | ||
console.log("error", error); | ||
} | ||
|
||
return responseModel; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import type { BaseResponseModel } from "../types/baseReponseModel"; | ||
|
||
interface Gamme4399AccountDataItemModel { | ||
/** | ||
* 4399账号 | ||
*/ | ||
account: string; | ||
/** | ||
* 此账号在4399平台不存在 | ||
* 此账号在4399平台已存在 | ||
*/ | ||
message: string; | ||
|
||
/** | ||
* https://www.4399.com | ||
*/ | ||
url: string; | ||
} | ||
|
||
/** | ||
* https://u.4399.com/anquan/pwd/?from=u&sfrom= | ||
* @param query | ||
* @returns | ||
*/ | ||
export default async function query( | ||
query: string | ||
): Promise<BaseResponseModel<Gamme4399AccountDataItemModel>> { | ||
const responseModel: BaseResponseModel<Gamme4399AccountDataItemModel> = { | ||
code: -1, | ||
message: "失败", | ||
data: [], | ||
}; | ||
try { | ||
// 创建一个新的 Date 对象 | ||
const date = new Date(); | ||
// 获得以毫秒为单位的时间戳 | ||
const timeStamp = date.getTime(); | ||
const res = await fetch( | ||
`https://u.4399.com/anquan/pwd/?` + | ||
new URLSearchParams({ | ||
_c: "verify", | ||
_a: "userAllowFind", | ||
userName: query.trim(), | ||
jsoncallback: "jQuery110206197225005545752_1712947018019", | ||
_: `${timeStamp}`, | ||
}), | ||
{ | ||
method: "GET", | ||
headers: { | ||
"User-Agent": | ||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36", | ||
Referer: "https://u.4399.com/anquan/pwd/?from=u&sfrom=", | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
Accept: `text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01`, | ||
"X-Requested-With": "XMLHttpRequest", | ||
"Sec-Ch-Ua-Platform": `"Windows"`, | ||
}, | ||
} | ||
); | ||
|
||
if (res.ok) { | ||
responseModel.code = 1; | ||
responseModel.message = "成功"; | ||
const text = await res.text(); | ||
// decoded: jQuery110206197225005545752_1712947018007({status: false, msg: "此账号在4399平台不存在"}) | ||
// jQuery110206197225005545752_1712947018007({"status":false,"msg":"\u6b64\u8d26\u53f7\u57284399\u5e73\u53f0\u4e0d\u5b58\u5728"}) | ||
// jQuery110206197225005545752_1712947018007({"status":true}) | ||
if (text.indexOf(`"status":true`) > 0) { | ||
responseModel.message = "成功"; | ||
responseModel.data = [ | ||
{ | ||
account: query.trim(), | ||
message: "此账号在4399平台已存在", | ||
url: "https://www.4399.com", | ||
}, | ||
]; | ||
} else if (text.indexOf(`"status":false`) > 0) { | ||
responseModel.message = `成功: 此账号 (${query.trim()}) 在4399平台不存在`; | ||
// 不存在就不需要展示列表了 | ||
responseModel.data = []; | ||
} else { | ||
responseModel.code = -1; | ||
responseModel.message = "未知错误"; | ||
} | ||
} | ||
} catch (error) {} | ||
|
||
return responseModel; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
export interface BaseResponseModel<TDataItem> { | ||
code: number | ||
message: string | ||
data: TDataItem[] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters