Skip to content

Commit 2cd2ccd

Browse files
zyszys
authored andcommitted
fix(checkin): send full device fingerprint so Global sign-in works
Captured the international (qoder.com) desktop sign-in flow with mitmproxy and compared it against ours: the official client sends seven extra cosy-* fingerprint headers that we never sent. cosy-version, cosy-machineid, cosy-machinetoken, cosy-machinetype, cosy-machinecode, cosy-machinehostname, cosy-machineos Without them the server withholds the CLAIM_BENEFIT campaign, so campaigns returns no sign-in entry and the account reports 'no_campaign'. CN happened to work because its activity dispatch is looser, which masked the defect. Fingerprint is derived with the same cosy.FingerprintSeed rule the bridge uses (uid first, credential fallback), so check-in and inference present as one physical device per account. Account id is used as the uid seed since check-in does not call userinfo. Verified: the global account moved from no_campaign to a successful claim (grantId issued, quota +100). Also note in README that server-side per-account gating still applies - brand new accounts may not get the campaign even with a complete fingerprint.
1 parent 6199925 commit 2cd2ccd

2 files changed

Lines changed: 97 additions & 15 deletions

File tree

‎README.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@
5858

5959
- **权威签到走 `campaigns`**:这是唯一真实发放积分的接口,返回 `grantId` 可核验到账
6060
- **不依赖 `daily-check-in`**:该 legacy 端点在国内已 `DISABLED` 且对未领取日恒返回 `409`(会误判为已领取而漏领),海外则直接 `404`
61+
- **⚠️ 必须携带完整设备指纹**:国际版(`qoder.com`)的签到活动**按设备指纹下发**——
62+
请求若缺少 `cosy-version` / `cosy-machineid` / `cosy-machinetoken` / `cosy-machinetype` /
63+
`cosy-machinecode` / `cosy-machinehostname` / `cosy-machineos` 这 7 个头,
64+
服务端会**不下发 `CLAIM_BENEFIT` 签到活动**,表现为「无可用签到活动」而无法领取。
65+
本项目复用 Bridge 的同一套 `cosy.FingerprintSeed` 派生规则(uid 优先、凭证兜底),
66+
保证签到与推理在同一账号上表现为同一台物理设备
67+
- **账号准入**:服务端按账号状态灰度下发签到活动。实测新注册账号(如当天创建)
68+
即使携带完整指纹也不下发活动,需账号有一定使用记录后才可见
6169
- **领取窗口**:`10:00 → 次日 09:59 (UTC+8)`,窗口未开启时点击会明确提示下次开放时间
6270
- **连续天数本地统计**:上游 legacy 统计恒为 0,故由 qoder2api 记录 `checkin_history.json` 并按**活动窗口 `startAt` 日期**(而非自然日)计算,避免 10:00 前误记
6371
- **调度容错**:签到时刻若活动尚未下发,不标记当日完成,每分钟重试至 12:00,避免漏签
@@ -94,6 +102,13 @@ curl -X POST http://127.0.0.1:3588/api/checkin -d '{"account_id":"acct_xxx"}'
94102
- **双区域签到**(`b84c41b`):`account.Endpoints` 新增 `OpenAPIHost`,签到域名按账号 `region` 自动路由
95103
(`cn` → `openapi.qoder.com.cn`,`global` → `openapi.qoder.sh`),
96104
同一控制台实例可同时管理国内版与国际版账号,无需分实例
105+
- **修复国际版签到不可用(重要)**:抓包对比官方客户端发现,国际版签到活动**按设备指纹下发**。
106+
此前签到请求只带 `Authorization` + `cosy-clienttype`,缺少
107+
`cosy-version` / `cosy-machineid` / `cosy-machinetoken` / `cosy-machinetype` /
108+
`cosy-machinecode` / `cosy-machinehostname` / `cosy-machineos` 共 7 个头,
109+
服务端因此不下发 `CLAIM_BENEFIT` 活动,表现为「无可用签到活动」。
110+
现已复用 Bridge 的 `cosy.FingerprintSeed` 派生规则补齐全部指纹头,
111+
国际版账号签到恢复正常(实测由 `no_campaign` 变为可领取并成功到账)
97112
- **修复空签到(重要)**:`daily-check-in/claim` 在国内已 `DISABLED`,却对**未领取日也恒返回 409**
98113
(被误读为「已领取」而跳过真实领取);海外该端点直接 404。
99114
现已**彻底移除**对它的领取调用,`campaigns` 成为唯一权威签到路径(返回 `grantId` 可核验到账)

‎checkin.go‎

Lines changed: 82 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@ package main
22

33
import (
44
"bytes"
5+
"crypto/sha256"
56
"crypto/tls"
7+
"encoding/hex"
68
"encoding/json"
79
"fmt"
810
"io"
911
"net/http"
1012
"os"
1113
"path/filepath"
14+
"runtime"
1215
"strconv"
1316
"strings"
1417
"sync"
1518
"time"
1619

1720
"qoder2api/account"
21+
"qoder2api/internal/cosy"
1822
"qoder2api/logger"
1923
)
2024

@@ -68,19 +72,79 @@ var checkinClient = &http.Client{
6872
}
6973

7074
// checkinHeaders 构造桌面端签到请求头(抓包确认的必需头)
71-
func checkinHeaders(deviceToken string) map[string]string {
75+
// checkinFP 承载签到请求所需的设备指纹字段。
76+
// 国际版(qoder.com)实测:campaigns 活动下发需完整设备指纹头,
77+
// 缺失会导致服务端不下发 CLAIM_BENEFIT 签到活动(表现为 no_campaign)。
78+
type checkinFP struct {
79+
machineID string
80+
machineToken string
81+
machineType string
82+
machineCode string
83+
hostname string
84+
machineOS string
85+
version string
86+
}
87+
88+
// newCheckinFP 用与 Bridge 相同的 seed 规则派生指纹,
89+
// 保证签到与推理在同一账号上表现为同一台物理设备。
90+
func newCheckinFP(uid, pat string) checkinFP {
91+
seed := cosy.FingerprintSeed(uid, pat)
92+
fp := checkinFP{
93+
machineID: cosy.DeriveMachineID(seed),
94+
machineToken: cosy.DeriveMachineToken(seed),
95+
machineType: cosy.DeriveMachineType(seed),
96+
hostname: "localhost",
97+
machineOS: goOS(),
98+
version: "0.4.4", // 对齐国际版桌面端
99+
}
100+
fp.machineCode = machineCodeFrom(fp.machineID)
101+
return fp
102+
}
103+
104+
// goOS 返回与官方客户端一致的 machineos 格式,如 aarch64_darwin
105+
func goOS() string {
106+
arch := "x86_64"
107+
if runtime.GOARCH == "arm64" {
108+
arch = "aarch64"
109+
}
110+
osName := "linux"
111+
switch runtime.GOOS {
112+
case "darwin":
113+
osName = "darwin"
114+
case "windows":
115+
osName = "windows"
116+
}
117+
return arch + "_" + osName
118+
}
119+
120+
// machineCodeFrom 由 machineid 派生 16 位十六进制 machinecode(官方格式)
121+
func machineCodeFrom(machineID string) string {
122+
sum := sha256.Sum256([]byte("cosy-machine-code:" + machineID))
123+
return hex.EncodeToString(sum[:])[:16]
124+
}
125+
126+
// checkinHeaders 构造签到请求头。
127+
// 必须携带完整 cosy 设备指纹:国际版缺少这些头时服务端不下发签到活动。
128+
func checkinHeaders(deviceToken string, fp checkinFP) map[string]string {
72129
return map[string]string{
73-
"authorization": "Bearer " + deviceToken,
74-
"accept": "application/json",
75-
"accept-language": "zh-CN",
76-
"user-agent": "Qoder",
77-
"cosy-clienttype": "10",
130+
"authorization": "Bearer " + deviceToken,
131+
"accept": "application/json",
132+
"accept-language": "zh-CN",
133+
"user-agent": "Qoder",
134+
"cosy-clienttype": "10",
135+
"cosy-version": fp.version,
136+
"cosy-machineid": fp.machineID,
137+
"cosy-machinetoken": fp.machineToken,
138+
"cosy-machinetype": fp.machineType,
139+
"cosy-machinecode": fp.machineCode,
140+
"cosy-machinehostname": fp.hostname,
141+
"cosy-machineos": fp.machineOS,
78142
}
79143
}
80144

81145
// doCheckinRequest 发送签到相关请求,返回 (httpStatus, parsedJSON, rawBody)
82146
// reqBody 为 nil 时发送空 body(抓包确认 campaigns/claim 即为空 body)
83-
func doCheckinRequest(method, path, deviceToken string, reqBody interface{}, host string) (int, interface{}, string) {
147+
func doCheckinRequest(method, path, deviceToken string, reqBody interface{}, host string, fp checkinFP) (int, interface{}, string) {
84148
if host == "" {
85149
host = checkinHost
86150
}
@@ -96,7 +160,7 @@ func doCheckinRequest(method, path, deviceToken string, reqBody interface{}, hos
96160
if err != nil {
97161
return 0, nil, fmt.Sprintf("build request: %v", err)
98162
}
99-
for k, v := range checkinHeaders(deviceToken) {
163+
for k, v := range checkinHeaders(deviceToken, fp) {
100164
req.Header.Set(k, v)
101165
}
102166
if method == "POST" {
@@ -321,10 +385,13 @@ func checkinAccount(acct *account.Account) CheckinResult {
321385
// 注意:不走 daily-check-in/claim —— 该 legacy 端点已 DISABLED,
322386
// 却对未领取日也恒返回 409,会误判"已领取"导致跳过真实领取(实测 2026-09-21 不发积分)
323387
host := checkinHostFor(acct.Region)
324-
r := campaignsCheckin(deviceToken, &res, host)
388+
// 指纹 seed 优先用账号 ID(签到不做 userinfo 往返,且账号 ID 稳定唯一),
389+
// 退回凭证种子,与 Bridge 的 uid 派生保持同一套设备身份。
390+
fp := newCheckinFP(acct.ID, secret)
391+
r := campaignsCheckin(deviceToken, &res, host, fp)
325392

326393
// 只读补充 legacy 统计(DISABLED 时恒 0,不影响结果;上游恢复后可提供 streak)
327-
readDailyCheckinStats(deviceToken, &r, host)
394+
readDailyCheckinStats(deviceToken, &r, host, fp)
328395

329396
return finalizeCheckin(acct.ID, r)
330397
}
@@ -355,8 +422,8 @@ func finalizeCheckin(accountID string, r CheckinResult) CheckinResult {
355422
// 背景:该端点的 legacy 活动已 DISABLED,claim 会恒返回 409 造成误判,
356423
// 且不发放任何积分(2026-09-21 实测)。真实领取只走 campaigns 流程。
357424
// 上游恢复后若返回非 0 统计,可作为 streak 的补充数据源。
358-
func readDailyCheckinStats(deviceToken string, res *CheckinResult, host string) {
359-
status, body, raw := doCheckinRequest("GET", "/sash/api/v1/me/daily-check-in/status", deviceToken, nil, host)
425+
func readDailyCheckinStats(deviceToken string, res *CheckinResult, host string, fp checkinFP) {
426+
status, body, raw := doCheckinRequest("GET", "/sash/api/v1/me/daily-check-in/status", deviceToken, nil, host, fp)
360427
if status != 200 {
361428
if status != 404 && status != 401 {
362429
logger.Info("[Checkin] daily-check-in/status HTTP %d: %s", status, truncate(raw, 150))
@@ -422,9 +489,9 @@ func windowHint(res *CheckinResult, fallback string) string {
422489
}
423490

424491
// campaignsCheckin 兜底:走桌面端抓包还原的 campaigns 流程
425-
func campaignsCheckin(deviceToken string, res *CheckinResult, host string) CheckinResult {
492+
func campaignsCheckin(deviceToken string, res *CheckinResult, host string, fp checkinFP) CheckinResult {
426493
// Step 1: 查询活动列表
427-
status, body, raw := doCheckinRequest("GET", "/sash/api/v1/me/campaigns", deviceToken, nil, host)
494+
status, body, raw := doCheckinRequest("GET", "/sash/api/v1/me/campaigns", deviceToken, nil, host, fp)
428495
if status != 200 {
429496
res.Message = fmt.Sprintf("查询活动失败 HTTP %d: %s", status, truncate(raw, 300))
430497
return *res
@@ -487,7 +554,7 @@ func campaignsCheckin(deviceToken string, res *CheckinResult, host string) Check
487554

488555
// Step 2: 领取(空 body,抓包确认)
489556
claimPath := fmt.Sprintf("/sash/api/v1/me/campaigns/%s/claim", target.CampaignID)
490-
status, body, raw = doCheckinRequest("POST", claimPath, deviceToken, nil, host)
557+
status, body, raw = doCheckinRequest("POST", claimPath, deviceToken, nil, host, fp)
491558
if status != 200 {
492559
res.Message = fmt.Sprintf("领取失败 HTTP %d: %s", status, truncate(raw, 300))
493560
return *res

0 commit comments

Comments
 (0)