From c35af318d060627a0ad52b5f9352b24fc031961e Mon Sep 17 00:00:00 2001 From: wood Date: Fri, 1 Sep 2023 17:17:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A2=84=E4=BB=98=E8=B4=B9?= =?UTF-8?q?=E9=A2=9D=E5=BA=A6=E8=B4=A6=E5=8F=B7=E7=9A=84=E6=80=BB=E9=A2=9D?= =?UTF-8?q?=E5=BA=A6=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98=20Fixes=20#18?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- static/js.js | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ca416dd..fdfef9e 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Telegram交流群:https://t.me/ai_cn2023 ## 最新示意图(2023.08.28) -![1693240108324.png](https://cdn-img.czl.net/2023/09/01/64f1a1dbf0e93.png) +![示意图](https://cdn-img.czl.net/2023/09/01/64f1ab8497308.png) ## SESS ID获取方法 diff --git a/static/js.js b/static/js.js index fd08ddd..28c2c4a 100644 --- a/static/js.js +++ b/static/js.js @@ -42,6 +42,7 @@ async function checkBilling(apiKey, apiUrl) { const urlsetid = apiUrl + '/v1/organizations'; const urlPaymentmethods = `${apiUrl}/v1/dashboard/billing/payment_methods`; const urlRatelimits = `${apiUrl}/v1/dashboard/rate_limits`; + const urlAdvanceData = apiUrl + '/dashboard/billing/credit_grants'; // 预付费查询接口 try { let totalAmount, totalUsage, remaining, GPT35CheckResult, GPT4CheckResult, GPT432kCheckResult, setid, isSubscrible; @@ -55,9 +56,17 @@ async function checkBilling(apiKey, apiUrl) { const formattedDate = `${expiryDate.getFullYear()}-${(expiryDate.getMonth() + 1).toString().padStart(2, '0')}-${expiryDate.getDate().toString().padStart(2, '0')}`; try { - totalAmount = subscriptionData.system_hard_limit_usd; + totalAmount = subscriptionData.hard_limit_usd; - if (totalAmount > 3) { + + const advanceDataResponse = await fetch(urlAdvanceData, { headers }); + const advanceData = await advanceDataResponse.json(); + if ((subscriptionData.billing_mechanism === 'advance') || (totalAmount <= 6 && !subscriptionData.has_credit_card)) { + totalAmount = advanceData.total_granted; + } + + + if (totalAmount > 6) { startDate = subDate; urlUsage = `${apiUrl}/v1/dashboard/billing/usage?start_date=${formatDate(startDate)}&end_date=${formatDate(endDate)}`; response = await fetch(urlUsage, { headers }); @@ -66,11 +75,13 @@ async function checkBilling(apiKey, apiUrl) { response = await fetch(urlUsage, { headers }); const usageData = await response.json(); totalUsage = usageData.total_usage / 100; - remaining = currentDate > expiryDate ? "❌过期" : (totalAmount - totalUsage).toFixed(3); + remaining = (totalAmount - totalUsage).toFixed(3); + } catch (error) { console.error(error); errors['subscription'] = error.message; } + //获取是否绑卡 try { if (subscriptionData.plan.id.includes('payg')) { @@ -254,8 +265,6 @@ function sendRequest() { let apiUrlSelect = document.getElementById("api-url-select"); let customUrlInput = document.getElementById("custom-url-input"); let table = document.getElementById("result-table"); - // let h2 = document.getElementById("result-head"); - // h2.style.visibility = "visible"; table.style.visibility = "visible"; if (apiKeyInput.value.trim() === "") { @@ -336,7 +345,7 @@ function sendRequest() { let totalUsedCell = document.createElement("td"); if (!isNaN(data[1])) { - totalUsedCell.textContent = data[1].toFixed(3); + totalUsedCell.textContent = data[1]; } else { totalUsedCell.textContent = '❌' } @@ -473,7 +482,7 @@ function sendRequest() { queriedApiKeys = []; } serialNumber++; // 增加序列号 - h2.style.display = 'block'; + // h2.style.display = 'block'; table.style.display = 'table'; hideLoadingAnimation();