Skip to content

Commit aee8248

Browse files
authored
fix: wangyihao detection logic (#191)
1 parent 560b33d commit aee8248

3 files changed

Lines changed: 53 additions & 23 deletions

File tree

packages/detection/src/configs.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,6 @@ export const ToutiaoLoginConfig = {
4242
}),
4343
}
4444

45-
// 博客园
46-
export const CnblogsLoginConfig = {
47-
api: 'https://www.cnblogs.com/api/users/current',
48-
method: 'GET',
49-
checkLogin: (response) => response?.UserId,
50-
getUserInfo: (response) => ({
51-
username: response?.DisplayName,
52-
avatar: response?.Avatar,
53-
}),
54-
}
55-
5645
// 百家号
5746
export const BaijiahaoLoginConfig = {
5847
api: 'https://baijiahao.baidu.com/builder/app/appinfo',
@@ -64,17 +53,6 @@ export const BaijiahaoLoginConfig = {
6453
}),
6554
}
6655

67-
// 网易号
68-
export const WangyihaoLoginConfig = {
69-
api: 'https://mp.163.com/api/account/info',
70-
method: 'GET',
71-
checkLogin: (response) => response?.code === 1000 && response?.data?.nickname,
72-
getUserInfo: (response) => ({
73-
username: response?.data?.nickname,
74-
avatar: response?.data?.headImg,
75-
}),
76-
}
77-
7856
// 抖音
7957
export const DouyinLoginConfig = {
8058
api: 'https://creator.douyin.com/web/api/media/user/info/',
@@ -93,6 +71,5 @@ export const LOGIN_CHECK_CONFIG = {
9371
toutiao: ToutiaoLoginConfig,
9472

9573
baijiahao: BaijiahaoLoginConfig,
96-
wangyihao: WangyihaoLoginConfig,
9774
douyin: DouyinLoginConfig,
9875
}

packages/detection/src/detect.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { detectInfoQUser } from './platforms/infoq.js'
2424
import { detectModelScopeUser } from './platforms/modelscope.js'
2525
import { detectVolcengineUser } from './platforms/volcengine.js'
2626
import { detectCnblogsUser } from './platforms/cnblogs.js'
27+
import { detectWangyihaoUser } from './platforms/wangyihao.js'
2728

2829
// Platform-specific detectors map
2930
const PLATFORM_DETECTORS = {
@@ -51,6 +52,7 @@ const PLATFORM_DETECTORS = {
5152
'modelscope': detectModelScopeUser,
5253
'volcengine': detectVolcengineUser,
5354
'cnblogs': detectCnblogsUser,
55+
'wangyihao': detectWangyihaoUser,
5456
}
5557

5658
export async function detectUser(platformId) {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { convertAvatarToBase64 } from '../utils.js'
2+
3+
/**
4+
* 网易号 detection logic
5+
* Strategy:
6+
* 1. Collect cookies via chrome.cookies.getAll (MV3 service worker compatible)
7+
* 2. Fetch user info via mp.163.com/wemedia/navinfo.do with cookies attached manually
8+
* 3. Extract username and avatar from API response
9+
*/
10+
export async function detectWangyihaoUser() {
11+
try {
12+
const cookies = await chrome.cookies.getAll({ domain: '.163.com' })
13+
const mpCookies = await chrome.cookies.getAll({ url: 'https://mp.163.com' })
14+
const allCookies = [...cookies, ...mpCookies]
15+
const seen = new Set()
16+
const uniqueCookies = allCookies.filter(c => {
17+
const key = `${c.name}=${c.value}`
18+
if (seen.has(key)) return false
19+
seen.add(key)
20+
return true
21+
})
22+
const cookieStr = uniqueCookies.map(c => `${c.name}=${c.value}`).join('; ')
23+
24+
if (!cookieStr) return { loggedIn: false }
25+
26+
const response = await fetch(`https://mp.163.com/wemedia/navinfo.do?_=${Date.now()}`, {
27+
method: 'GET',
28+
headers: {
29+
'Accept': 'application/json',
30+
'Cookie': cookieStr,
31+
},
32+
})
33+
34+
if (!response.ok) return { loggedIn: false }
35+
36+
const data = await response.json()
37+
if (data?.code !== 1 || !data?.data?.wemediaId) return { loggedIn: false }
38+
39+
const username = data.data.tname || ''
40+
let avatar = data.data.icon || ''
41+
42+
if (avatar && (avatar.includes('126.net') || avatar.includes('163.com'))) {
43+
avatar = await convertAvatarToBase64(avatar, 'https://mp.163.com/')
44+
}
45+
46+
return { loggedIn: true, username, avatar }
47+
} catch (e) {
48+
console.error('[COSE] Wangyihao Detection Error:', e)
49+
return { loggedIn: false, error: e.message }
50+
}
51+
}

0 commit comments

Comments
 (0)