Repository navigation
Conversation
教师企业版账号(`type = "ultimate"` + `enterpriseId`)在个人资源体系里是真空: summary / paid / free 三接口与旧 `get-user-resource` 全部返回零包,卡片恒显示 0 (上游 issue NextAgentX#205)。 实测同一个 token 打三条新接口与旧接口,返回分别是 `{"Packages":[],"IsPaidUser":false}`、`{"Accounts":[],"TotalCount":0}`、 `{"Accounts":null,"TotalDosage":0}` —— 不是解析漏字段,是数据不在这些接口上。 其额度挂在 `POST /billing/meter/get-enterprise-user-usage`:空 body + 账号自带的 `X-Enterprise-Id` 头,返回 `credit`(已用)、`limitNum`(月度上限)、 `cycleEndTime`(UTC+8 墙钟)。上游网页端 `plans-usage` 正是按 `enterpriseId` 非空走这条,其 `UsageIntl` 组件用 `left = max(0, limitNum - credit)` 渲染「剩余」。 改动: - 新增 `ENTERPRISE_USER_USAGE_PATH` 与 `enterprise_usage_resource`,把该响应折成 一条与个人资源包同形的摘要(`total` / `remaining` / `used` / `expireAt`), 直接复用既有聚合与展示链路,不改前端 - 兜底位置放在旧接口回退**之后**:任何有个人资源包的账号都在前面分支返回, 个人账号路径零变化;仅 CN 区域、且账号带 `enterpriseId` 时才发这一次请求 - 不在兜底里再做 401 刷新:所用账号来自三路请求已刷新落盘的结果,再刷一次会重蹈 「旧 refresh token 覆盖新 token」的覆辙 - 新增 5 个单测:字段映射(credit 是已用)、`data.data` 嵌套包层、零配额不成资源、 超额钳制、非企业账号不命中 验证:`cargo test -p buddy-switch-core --lib` 通过;真实教师账号(WorkBuddy教育公益版) 该接口返回 `credit=124.72 / limitNum=2000 / cycleEndTime=2026-11-30 23:59:59`, 折算剩余 1875.28。
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
教师企业版账号读不到积分(#205)。作者说缺样本,这次用真实教师号抓到了,顺手把解析补上。
根因
不是解析漏字段。这类账号(
type = "ultimate",带enterpriseId)的额度不走个人资源包体系,同一个 token 打现有四条路径全是空的:get-user-resource-summary→{"Packages":[],"IsPaidUser":false}get-user-resource-paid-packages→{"Accounts":[],"TotalCount":0}get-user-resource-free-packages→{"Accounts":[],"TotalCount":0}v2/billing/meter/get-user-resource→{"Accounts":null,"TotalDosage":0}ProductCode换空串、去掉、Status扩到[0,1,2,3,4]、只留PageSize都试过,一直是 0,所以不是过滤器的问题。额度在另一个接口上:
POST /billing/meter/get-enterprise-user-usage,空 body,头里带X-Enterprise-Id。这是网页端profile/plans-usage对enterpriseId非空账号走的路径,前端打包后的定义是:真实响应(数值替换过,结构原样):
{"code":0,"msg":"OK","data":{ "credit":124.72, "cycleStartTime":"2026-11-01 00:00:00", "cycleEndTime":"2026-11-30 23:59:59", "limitNum":2000, "cycleResetTime":"2026-12-01 00:00:00"}}怎么改的
只动
crates/buddy-switch-core/src/modules/credits.rs一个文件。1. 加常量
2. 三个小函数
enterprise_id(account):取enterpriseId/enterprise_id,空白串当没有。enterprise_usage_payload(response):兼容data和data.data两种包层 —— 网页端自己写的就是m.data?.data || m.data,说明两种都在线上跑。enterprise_usage_resource(response, now):把配额折成一条和普通资源包同形的摘要。3. 一个请求函数
头不用手拼:现有的
build_auth_headers已经会按enterpriseId补X-Enterprise-Id和X-Tenant-Id。4. 挂到
get_credit_expiry_for末尾位置在「旧接口也失败」之后、「返回 error」之前:
放最后一级是有意的:任何有个人资源包的账号都在上面两个分支 return 了,所以个人账号路径一行都没变;将来企业号如果自己也有了个人包,也会优先用个人包,企业配额只是兜底。
这里没有再做 401 刷新。
fallback_account是三条新接口刷新并落盘后的结果,再刷一次就是拿旧 refresh token 覆盖新 token —— 文件里原本就有这段注释在提醒别这么干。字段怎么映射
折出来的这条 resource 直接喂给
credit_result,所以聚合、快照、前端显示全都不用改:creditusedlimitNumtotallimitNum - creditremainingcycleEndTimeexpireAtparse_timestamp_mspackageCode = "enterprise_monthly_quota"merge_resources靠它去重credit是「已用」这一点容易搞反,依据是上游UsageIntl:limitNum <= 0直接返回None,让调用方继续走原来的失败分支 —— 不能把「查不到」显示成「额度 0」。测试
5 个新单测,都不联网:
enterprise_quota_maps_credit_as_used:字段映射 +cycleEndTime按 UTC+8 解析。把remaining写成credit会红。enterprise_quota_accepts_nested_payload:兼容data.data包层。enterprise_quota_without_limit_yields_nothing:零配额 / 缺字段 / 失败响应都不成资源。enterprise_quota_clamps_overuse:credit > limitNum时剩余归零、已用截到上限。enterprise_id_only_matches_enterprise_accounts:个人账号不命中,不会多发一次请求。全量
cargo test -p buddy-switch-core --lib:1938 passed / 0 failed / 9 ignored。兼容性
enterpriseId的账号多发一次请求,其他账号的网络调用次数不变。check:api不受影响。另外
探测时我怀疑这个接口对
X-Enterprise-Id的校验有点问题(和本 issue 无关)。按 CONTRIBUTING 里「安全相关别公开」的约定,细节没写在这儿,需要的话我私下说。本贡献同意按 PolyForm Noncommercial License 1.0.0 分发。