v1.10.3: 修「买完仍显示试用倒计时」与「到期时间显示永久」

根因:CardAuth 自动发卡只写 ca_cards(status=used + bind_info.machine_id),
从不写 ca_authorizations,而插件只查 /public/authorizations/query → 已购用户恒为空。

- checkLicense 增加卡密直验兜底:用本地记住的卡密调 /public/verify,
  返回 valid/expire_time/is_permanent,直接作为授权状态与到期时间
- activateCard 成功即持久化 activeCardKey + activeCardInfo(换机/过期自动清除)
- buy.js 不再用「永久」兜底到期时间(订单接口不返回 expire_time),
  改为只在服务端明确给出时显示,否则显示套餐名
- 侧边栏已授权态显示套餐名 + 真实到期时间
This commit is contained in:
jinghui committed 2026-10-20 23:32:43 +08:00
1 parent 99d1d1fe92
commit 226e4fbbf9
5 files changed
+81 -4

No files matched your search

+56 -1
View File
@@ -125,6 +125,36 @@ async function checkLicense() {
offline = true; // 网络/超时 → 放行
}
// 兜底:卡密直验。自动发卡不写 ca_authorizations,上面的查询对已购用户恒为空;
// 用本地记住的卡密直接调 /public/verify(它读 ca_cards,返回真实到期时间)。
let cardInfo = null;
if (!authorized) {
try {
const saved = await chrome.storage.local.get(["activeCardKey"]);
const key = String(saved.activeCardKey || "").trim();
if (key) {
const v = await authFetch("/public/verify", {
method: "POST",
headers: { "Content-Type": "application/json", "X-Api-Key": CARD_API_KEY },
body: JSON.stringify({
card_key: key,
machine_id: machine,
client_version: chrome.runtime.getManifest().version
})
}, 12000);
const vd = (v && v.data) || {};
if (v && v.code === 200 && vd.valid) {
authorized = true;
expire = vd.expire_time || "";
cardInfo = { type: vd.type || "", expireTime: expire, isPermanent: !!vd.is_permanent, remainingDays: vd.remaining_days };
} else if (v && v.code === 200 && vd.valid === false) {
// 换机绑定或已过期:清掉本地卡密,别每次都拿废卡打接口
await chrome.storage.local.remove(["activeCardKey", "activeCardInfo"]);
}
}
} catch (e) { /* 直验失败不影响试用判定 */ }
}
const st = await chrome.storage.local.get(["trialStart", "trialComments"]);
let trialStart = Number(st.trialStart) || 0;
if (!trialStart) {
@@ -146,6 +176,7 @@ async function checkLicense() {
offline: offline,
realAuthorized: authorized,
expire: expire,
cardInfo: cardInfo,
machine: machine,
trialStart: trialStart,
trialEnd: trialEnd,
@@ -172,7 +203,27 @@ async function activateCard(cardKey) {
}, 12000);
const d = (r && r.data) || {};
if (r && r.code === 200 && d.valid) {
return { ok: true, message: d.message || "激活成功", days: d.duration_days || 0 };
// 记住这张卡:CardAuth 的自动发卡只把 ca_cards 标成 used 并绑定机器码,
// 从不写 ca_authorizations,所以 /public/authorizations/query 对已购用户恒为空。
// 插件自己留着卡密,才能持续向 /public/verify 校验真实授权状态。
const key = String(cardKey || "").trim();
await chrome.storage.local.set({
activeCardKey: key,
activeCardInfo: {
type: d.type || "",
durationDays: Number(d.duration_days) || 0,
expireTime: d.expire_time || "",
isPermanent: !!d.is_permanent,
activatedAt: Date.now()
}
});
return {
ok: true, message: d.message || "激活成功",
days: d.duration_days || 0,
cardType: d.type || "",
expireTime: d.expire_time || "",
isPermanent: !!d.is_permanent
};
}
return { ok: false, message: (d && d.message) || (r && r.message) || "激活失败" };
}
@@ -623,6 +674,10 @@ async function authQueryOrder(orderNo) {
const act = await activateCard(out.cardKey);
out.activated = !!(act && act.ok);
out.message = (act && act.message) || "";
// /public/orders/query 不返回到期时间,verify 返回的才是真值——别用「永久」兜底
out.expireTime = (act && act.expireTime) || "";
out.isPermanent = !!(act && act.isPermanent);
out.planName = d.card_type_name || "";
if (out.activated) {
await chrome.storage.local.remove(["pendingOrder"]);
await clearOrderAlarm();