看看能不能看到
(async () => {
const sessionResp = await fetch('/api/auth/session', { credentials: 'include' });
if (!sessionResp.ok) throw new Error('session HTTP ' + sessionResp.status);
const session = await sessionResp.json();
const accessToken = session.accessToken;
if (!accessToken) throw new Error('没有拿到 accessToken,确认已登录 chatgpt.com');
const headers = {
Authorization: Bearer ${accessToken},
Accept: 'application/json',
'Content-Type': 'application/json',
'oai-language': 'zh-Hant',
'oai-device-id': crypto.randomUUID(),
};
const getJson = async (url) => {
const r = await fetch(url, { headers });
const text = await r.text();
if (!r.ok) throw new Error(${url} HTTP ${r.status}: ${text.slice(0, 300)});
return JSON.parse(text);
};
const accountCheck = await getJson('/backend-api/accounts/check/v4-2023-04-27');
const accounts = accountCheck.accounts || {};
const firstKey = Object.keys(accounts)[0];
const accountId =
accounts[firstKey]?.account?.account_id ||
session.account?.id ||
firstKey;
if (!accountId) throw new Error('没有拿到 account_id');
const [invoices, paymentMethods, billingInfo] = await Promise.all([
getJson(/backend-api/invoices?limit=10&account_id=${encodeURIComponent(accountId)}),
getJson(/backend-api/payments/payment_methods?account_id=${encodeURIComponent(accountId)}),
getJson(/backend-api/payments/billing_info?account_id=${encodeURIComponent(accountId)}),
]);
const result = {
email: session.user?.email,
plan: accounts[firstKey]?.account?.plan_type || session.account?.planType,
accountId,
accessTokenStatus: accessToken ? exists (${accessToken.length} chars) : 'missing',
invoices,
paymentMethods,
billingInfo,
};
console.log('账单提取结果:', result);
console.log('Stripe/账单管理页:', https://chatgpt.com/account/manage?account_id=${encodeURIComponent(accountId)});
window.__billingResult = result;
return result;
})();