Skip to content

Commit b84c41b

Browse files
committed
fix(checkin): use region-correct OpenAPI host for check-in
Check-in hard-coded openapi.qoder.com.cn, so international accounts sent their token to the CN endpoint and got 401 TOKEN_EXPIRE. Add Endpoints.OpenAPIHost (global openapi.qoder.sh, cn openapi.qoder.com.cn) and thread it through checkinAccount -> campaignsCheckin / readDailyCheckinStats -> doCheckinRequest.
1 parent fcde08e commit b84c41b

3 files changed

Lines changed: 37 additions & 11 deletions

File tree

‎account/region.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type Endpoints struct {
1818
ChatStreamURL string // SSE chat
1919
ModelListURL string // model list
2020
JobTokenURL string // PAT exchange
21+
OpenAPIHost string // OpenAPI 主机(签到/活动等 /sash、/api 接口)
2122
}
2223

2324
var endpointsGlobal = Endpoints{
@@ -29,6 +30,7 @@ var endpointsGlobal = Endpoints{
2930
ChatStreamURL: "https://api1.qoder.sh/algo/api/v2/service/pro/sse/agent_chat_generation?FetchKeys=llm_model_result&AgentId=agent_common&Encode=1",
3031
ModelListURL: "https://api2.qoder.sh/algo/api/v2/model/list?Encode=1",
3132
JobTokenURL: "https://center.qoder.sh/algo/api/v3/user/jobToken?Encode=1",
33+
OpenAPIHost: "openapi.qoder.sh",
3234
}
3335

3436
var endpointsCN = Endpoints{
@@ -40,6 +42,7 @@ var endpointsCN = Endpoints{
4042
ChatStreamURL: "https://gateway.qoder.com.cn/algo/api/v2/service/pro/sse/agent_chat_generation?FetchKeys=llm_model_result&AgentId=agent_common&Encode=1",
4143
ModelListURL: "https://gateway.qoder.com.cn/algo/api/v2/model/list?Encode=1",
4244
JobTokenURL: "https://gateway.qoder.com.cn/algo/api/v3/user/jobToken?Encode=1",
45+
OpenAPIHost: "openapi.qoder.com.cn",
4346
}
4447

4548
// GetEndpoints 根据 region 返回对应端点配置,空值或未知值视为 global

‎checkin.go‎

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,19 @@ import (
1818
"qoder2api/logger"
1919
)
2020

21-
// checkinHost 是签到 API 域名(抓包确认为 openapi.qoder.com.cn)
21+
// checkinHost 是签到 API 的兜底域名(国内)。国际走 openapi.qoder.sh,
22+
// 由 checkinHostFor 按账号区域选择——此前写死国内域名导致国际号签到
23+
// 返回 401 TOKEN_EXPIRE(拿国际 token 打国内端点)。
2224
const checkinHost = "openapi.qoder.com.cn"
2325

26+
// checkinHostFor 返回该区域的签到/OpenAPI 主机。
27+
func checkinHostFor(region account.Region) string {
28+
if h := account.GetEndpoints(region).OpenAPIHost; h != "" {
29+
return h
30+
}
31+
return checkinHost
32+
}
33+
2434
// CheckinResult 单个账号的签到结果
2535
type CheckinResult struct {
2636
Account string `json:"account"`
@@ -70,8 +80,11 @@ func checkinHeaders(deviceToken string) map[string]string {
7080

7181
// doCheckinRequest 发送签到相关请求,返回 (httpStatus, parsedJSON, rawBody)
7282
// reqBody 为 nil 时发送空 body(抓包确认 campaigns/claim 即为空 body)
73-
func doCheckinRequest(method, path, deviceToken string, reqBody interface{}) (int, interface{}, string) {
74-
url := "https://" + checkinHost + path
83+
func doCheckinRequest(method, path, deviceToken string, reqBody interface{}, host string) (int, interface{}, string) {
84+
if host == "" {
85+
host = checkinHost
86+
}
87+
url := "https://" + host + path
7588

7689
var body io.Reader
7790
var bodyBytes []byte
@@ -87,7 +100,7 @@ func doCheckinRequest(method, path, deviceToken string, reqBody interface{}) (in
87100
req.Header.Set(k, v)
88101
}
89102
if method == "POST" {
90-
req.Header.Set("origin", "https://"+checkinHost)
103+
req.Header.Set("origin", "https://"+host)
91104
if reqBody == nil {
92105
req.ContentLength = 0 // 抓包确认 claim 无 body
93106
}
@@ -307,10 +320,11 @@ func checkinAccount(acct *account.Account) CheckinResult {
307320
// ========== 权威领取:campaigns 流程(真实发放积分的系统) ==========
308321
// 注意:不走 daily-check-in/claim —— 该 legacy 端点已 DISABLED,
309322
// 却对未领取日也恒返回 409,会误判"已领取"导致跳过真实领取(实测 2026-09-21 不发积分)
310-
r := campaignsCheckin(deviceToken, &res)
323+
host := checkinHostFor(acct.Region)
324+
r := campaignsCheckin(deviceToken, &res, host)
311325

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

315329
return finalizeCheckin(acct.ID, r)
316330
}
@@ -341,8 +355,8 @@ func finalizeCheckin(accountID string, r CheckinResult) CheckinResult {
341355
// 背景:该端点的 legacy 活动已 DISABLED,claim 会恒返回 409 造成误判,
342356
// 且不发放任何积分(2026-09-21 实测)。真实领取只走 campaigns 流程。
343357
// 上游恢复后若返回非 0 统计,可作为 streak 的补充数据源。
344-
func readDailyCheckinStats(deviceToken string, res *CheckinResult) {
345-
status, body, raw := doCheckinRequest("GET", "/sash/api/v1/me/daily-check-in/status", deviceToken, nil)
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)
346360
if status != 200 {
347361
if status != 404 && status != 401 {
348362
logger.Info("[Checkin] daily-check-in/status HTTP %d: %s", status, truncate(raw, 150))
@@ -408,9 +422,9 @@ func windowHint(res *CheckinResult, fallback string) string {
408422
}
409423

410424
// campaignsCheckin 兜底:走桌面端抓包还原的 campaigns 流程
411-
func campaignsCheckin(deviceToken string, res *CheckinResult) CheckinResult {
425+
func campaignsCheckin(deviceToken string, res *CheckinResult, host string) CheckinResult {
412426
// Step 1: 查询活动列表
413-
status, body, raw := doCheckinRequest("GET", "/sash/api/v1/me/campaigns", deviceToken, nil)
427+
status, body, raw := doCheckinRequest("GET", "/sash/api/v1/me/campaigns", deviceToken, nil, host)
414428
if status != 200 {
415429
res.Message = fmt.Sprintf("查询活动失败 HTTP %d: %s", status, truncate(raw, 300))
416430
return *res
@@ -473,7 +487,7 @@ func campaignsCheckin(deviceToken string, res *CheckinResult) CheckinResult {
473487

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

‎checkin_test.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,12 @@ func TestCheckinTimesDefaultAndConfigured(t *testing.T) {
3939
t.Errorf("configured = %v, want [09:15 17:00]", got)
4040
}
4141
}
42+
43+
func TestCheckinHostForRegion(t *testing.T) {
44+
if got := checkinHostFor(account.RegionCN); got != "openapi.qoder.com.cn" {
45+
t.Errorf("cn host = %q", got)
46+
}
47+
if got := checkinHostFor(account.RegionGlobal); got != "openapi.qoder.sh" {
48+
t.Errorf("global host = %q", got)
49+
}
50+
}

0 commit comments

Comments
 (0)