- Home
- Plugin
- Utilizzo e fatturazione
- dsh-student-perks
dsh-student-perks
ixxgal/dsh-student-perks
Two pills in the bottom bar show the Aliyun student cash coupon (unclaimed, N days left, or expired) and the DeepSeek API balance; the panel adds voucher and cash balance, the peak/off-peak pricing phase, and a refresh button. Its HTTP routes have no DSH access check, so a web page open in your browser could call them.
Installazione
dsh plugin --profile web add github:ixxgal/dsh-student-perksREADME
dsh-student-perks
窗口最底部状态栏常驻的三枚小胶囊(shell.bottom 槽,root 作用域,布局单独让出一行):
- 🎓 阿里云券 / 账户余额:配了 AccessKey 就自动查——显示学生券面额、剩余天数,点开还有账户可用余额、现金余额与全部代金券;没配就退回手动记账。
- 面板大数字可切换口径(卡片顶部
券 / 账户 / 现金 / 信控四段选择器):券看的是代金券余额(独立记账,和账户余额不是一回事,所以账户显示¥0.00、券还有一百多是正常的);账户 / 现金 / 信控看的是QueryAccountBalance那三个字段。选过的口径记在本机localStorage,宿主重启后还会写进state.json的prefs.aliyunMetric(跨设备一起记)。
- 面板大数字可切换口径(卡片顶部
- 💳 DeepSeek API 余额:CNY 总额,点开面板还有赠金、充值余额与更新时间。
- 🌙/☀️ DeepSeek 计价时段:谷期(绿)或峰期(红),后面是当前时段还剩多久(
剩 13h04m)。纯本地按北京时间算,不打接口:官方价目表规定周一至周五 9:00–12:00、14:00–18:00 是高峰价,其余时段(含周末)是空闲价,价格只有高峰的一半。法定节假日官方也按空闲价,但插件不认识节假日表,那几天会误显示成峰期。
为什么不挂在会话里、也不浮在右下角:
conversation.session.header.actions属于 session 作用域,新建对话、空会话时没有那个 header,胶囊会整组消失;sidebar.footer.action被别的插件占了,且 Windows 标题栏模式下侧边栏折叠会隐藏。shell.overlay是浮层(position:absolute盖在内容上),在窗口右下角正好压在输入框的发送按钮上。shell.bottom是.frame网格里minmax(0,1fr) auto的第二行、grid-column:1/-1,属于真正的布局行:状态栏占自己的高度,聊天区自动让位,永远不会遮挡任何控件。
安装
dsh plugin add github:ixxgal/dsh-student-perks
装完重启一次 DSH(宿主侧要挂 /dsh-student-perks/*.json 四个端点),状态栏底部才会出现胶囊。
也可以从插件索引装(插件 → 实验性插件 → 打开「自定义插件索引」→ 插件 → 发现 → 添加索引源):
https://ixxgal.github.io/dsh-plugins/index.json
本地开发用 dsh plugin add link:<插件目录的绝对路径>。
这个仓库里没有任何钥匙。 阿里云 AccessKey、DeepSeek API Key、桌面版账号会话都不进 git(见下面「密钥放哪」与 .gitignore),装完是「未配置」状态,你在面板里填一次就行。
数据从哪来
- 阿里云(自动):费用与成本 OpenAPI
BssOpenApi 2017-12-14QueryAccountBalance→ 可用余额 / 现金余额 / 信控额度(Data.AvailableAmount等)QueryCashCoupons→ 代金券列表(面额NominalValue、余额Balance、状态Available|Expired|Cancelled、ExpiryTime)- 签名是 RPC 那套:参数排序 →
GET&%2F&percentEncode(query)→HMAC-SHA1(secret + "&")→ base64,见aliyun.js。 - 需要的权限:
AliyunBSSReadOnlyAccess(只读就够)。国内站business.aliyuncs.com,国际站business.ap-southeast-1.aliyuncs.com。 - 学生券规则:学生认证后每年 1 张 300 元无门槛券,领券起 1 年内有效,不与 99 元学生机叠加;活动页 https://www.aliyun.com/activity/ecs/student-benefits。接口里它只是一张
NominalValue=300的代金券,面板会优先挑它来显示。
- DeepSeek:两种口径,优先用 Key,没有就用桌面版登录的账号会话
- 有 API Key:
GET https://api.deepseek.com/user/balance,Authorization: Bearer <key>,返回 CNY/USD 各自的总额、赠金、充值余额;面板优先显示 CNY。 - 没有 Key:
GET https://platform.deepseek.com/api/v0/users/get_user_summary,带x-dsh-auth-token: <token>,token 取自$DSH_HOME/.credentials.yaml的records["deepseek-account-platform/default"].payload.token(D·S·H 自己登录桌面版时写下的)。这就是「用量」页那个钱包:normal_wallets+bonus_wallets,外加total_costs当累计消耗显示。只读,不发到别处。 - 想彻底用 API Key 口径:面板里填 Key,或在
cordis.patch.yml里把useAccountBalance设成false。
- 有 API Key:
密钥放哪
阿里云 AccessKey(ID + Secret 必须成对)与 DeepSeek API Key 都按同一个顺序取:
- 面板里填的(存
$DSH_HOME/student-perks/state.json,本地明文,注意备份权限) - 配置里的
aliyunAccessKeyId/aliyunAccessKeySecret、apiKey - 环境变量
ALIBABA_CLOUD_ACCESS_KEY_ID/ALIBABA_CLOUD_ACCESS_KEY_SECRET、DEEPSEEK_API_KEY $DSH_HOME/.credentials.yaml的refs[...]
DeepSeek 这一路还有第 5 层兜底:以上都没有、且 useAccountBalance !== false 时,直接用 .credentials.yaml 里桌面版账号的 grant token 读钱包(面板会标「本机账号会话」,不可「清除」,因为那不是你填的密钥)。
HTTP 响应只回 LTAI…abcd / sk-…abcd 这种提示,不回明文密钥。
凭据和插件本体怎么隔开
凡是「绑第三方账号」的插件都按同一条规矩做,这个插件是第一个落地样本:
| 层 | 放哪 | 有没有进仓库 |
|---|---|---|
| 面板里填的密钥 | $DSH_HOME/student-perks/state.json(默认 %USERPROFILE%\.dsh\student-perks\state.json) | 永不进 —— 这个路径在插件目录之外 |
| 环境变量 | ALIBABA_CLOUD_ACCESS_KEY_ID / _SECRET、DEEPSEEK_API_KEY | 不进 —— 只写变量名,不写值 |
| 账号会话 token | $DSH_HOME/.credentials.yaml(DSH 登录桌面版时自己写的) | 不进 —— 只读引用 |
| 配置文件 | cordis.patch.yml 里 aliyunAccessKeyId / apiKey 留空 | 进仓库,但值是空串 |
仓库侧的防线有三道:.gitignore 拦掉 state.json / .env / cookies*.json / *.pem 这类文件;cordis.patch.yml 只允许出现变量名(aliyunKeyIdEnv: ALIBABA_CLOUD_ACCESS_KEY_ID),出现明文值就被拦;发布脚本 dsh-plugins/scripts/add-plugin.mjs 在登记前再扫一遍明文密钥与凭据文件,命中直接中止。
所以:换了电脑,插件照装,钥匙要重新填一次;反过来说,仓库被人看光也拿不到任何账号。
共享这台机器的第二个人要注意:state.json 是本机明文(写权限 0600),能读你用户目录的人就能读到——那已经不是插件该管的边界了。
端点
| 方法 | 路径 | 作用 |
|---|---|---|
| GET | /dsh-student-perks/state.json | 快照(券视图 + 阿里云账户 + 余额缓存) |
| POST | /dsh-student-perks/refresh.json | 两边都强制刷新一次 |
| POST | /dsh-student-perks/deepseek.json | 存/清 API Key、改 baseUrl({"apiKey":null} 清空) |
| POST | /dsh-student-perks/aliyun.json | 存/清 AccessKey(accessKeyId/accessKeySecret/endpoint)或改手动券状态(claimed/expiresAt/amount/link),带 "refresh":true 时立刻重查 |
写请求只接受回环 Host;快照里没有明文密钥。缓存默认 5 分钟(refreshMs),阿里云和 DeepSeek 各算各的;某个接口失败时保留上一轮数字,只把错误写进 error。
配置
见 cordis.patch.yml:aliyunAmount、aliyunLink、aliyunAccessKeyId、aliyunAccessKeySecret、aliyunKeyIdEnv、aliyunKeySecretEnv、aliyunKeyIdRef、aliyunKeySecretRef、aliyunEndpoint、apiKey、apiKeyEnv、credentialsRef、baseUrl、refreshMs、timeoutMs、autoRefresh、controlRoute。
controlRoute: false 时不注册任何端点,胶囊退化成静态提示(券状态与余额都读不到,显示 … / 未配置)。
本地状态
{
"version": 2,
"aliyun": { "claimed": false, "claimedAt": null, "expiresAt": null, "amount": null, "link": null },
"aliyunCreds": { "accessKeyId": "LTAI…", "accessKeySecret": "…", "endpoint": "cn", "updatedAt": 1763500000000 },
"aliyunCache": {
"at": 1763500000000,
"cash": { "available": "12.34", "cash": "10.00", "credit": "0.00", "mybankCredit": "0.00", "currency": "CNY" },
"coupons": [{ "id": 123, "no": "…", "amount": 300, "balance": 300, "state": "available", "expiresAt": 1820000000000, "note": "高校学生 300 元无门槛券" }],
"error": null
},
"deepseek": { "apiKey": "sk-…", "baseUrl": "", "updatedAt": 1763500000000 },
"cache": { "at": 1763500000000, "currency": "CNY", "total": "12.34", "granted": "0.00", "toppedUp": "12.34", "available": true, "error": null }
}
原子写(先写 .tmp-<pid> 再 rename)。删掉这个文件等于恢复出厂设置。
开发
node --test test/host.test.js test/client.test.js test/aliyun.test.js
测试全用假 fetch,不会打真接口,也不需要任何密钥。
Plugin correlati
DeepSeek-Balance-Whale-Widget
meteornox/deepseek-balance-whale-widget
dsh-context
bowenliang123/dsh-context
dsh-cost-meter
han-1413141/dsh-cost-meter
dsh-damage-pulse
wssfk12138/dsh-damage-pulse