From 2608b14b812ce6e4954026a6c60bfa950bf632d3 Mon Sep 17 00:00:00 2001 From: wood Date: Mon, 4 Sep 2023 13:25:08 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=9F=A5=E4=B8=AD=E8=BD=AC=E6=B8=A0?= =?UTF-8?q?=E9=81=93=E4=BD=99=E9=A2=9D=E6=98=BE=E7=A4=BA=E9=94=99=E8=AF=AF?= =?UTF-8?q?=20Fixes=20#28?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/js.js | 70 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 25 deletions(-) diff --git a/static/js.js b/static/js.js index c9cf751..03c2d8b 100644 --- a/static/js.js +++ b/static/js.js @@ -34,6 +34,14 @@ toggleSetidInfo(); let queriedApiKeys = []; let serialNumber = 1; +function formatDate(date) { + const year = date.getFullYear(); + const month = (date.getMonth() + 1).toString().padStart(2, '0'); + const day = date.getDate().toString().padStart(2, '0'); + + return `${year}-${month}-${day}`; +} + async function checkBilling(apiKey, apiUrl) { const now = new Date(); let startDate = new Date(now - 90 * 24 * 60 * 60 * 1000); @@ -67,28 +75,29 @@ async function checkBilling(apiKey, apiUrl) { try { totalAmount = subscriptionData.hard_limit_usd; - 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; } - + } catch (error) { + console.error(error); + } + try { if (totalAmount > 6) { startDate = subDate; - urlUsage = `${apiUrl}/v1/dashboard/billing/usage?start_date=${formatDate(startDate)}&end_date=${formatDate(endDate)}`; - response = await fetch(urlUsage, { headers }); - const usageData = await response.json(); } response = await fetch(urlUsage, { headers }); const usageData = await response.json(); + totalUsage = usageData.total_usage / 100; remaining = (totalAmount - totalUsage).toFixed(3); } catch (error) { console.error(error); - errors['subscription'] = error.message; + } //获取是否绑卡 @@ -115,14 +124,13 @@ async function checkBilling(apiKey, apiUrl) { } //获取绑卡信息 try { - // 从 subscriptionData 中获取 SubscribleInformation 的值... SubscribleInformation.account_name = subscriptionData.account_name; SubscribleInformation.po_number = subscriptionData.po_number; SubscribleInformation.billing_email = subscriptionData.billing_email; SubscribleInformation.tax_ids = subscriptionData.tax_ids; - let billingAddress = subscriptionData.billing_address; // 定义并赋值 billingAddress - let businessAddress = subscriptionData.business_address; // 定义并赋值 businessAddress + let billingAddress = subscriptionData.billing_address; + let businessAddress = subscriptionData.business_address; SubInformation = "名称: " + SubscribleInformation.account_name + "\n"; SubInformation += "PO号: " + SubscribleInformation.po_number + "\n"; @@ -131,7 +139,7 @@ async function checkBilling(apiKey, apiUrl) { //使用 JavaScript 的可选链式调用来确定是否为null,避免异常控制台报错 SubInformation += "账单地址: " + (billingAddress?.line1 ? billingAddress.line1 : '') + ", " + (billingAddress?.city ? billingAddress.city : '') + ", " + (billingAddress?.state ? billingAddress.state : '') + ", " + (billingAddress?.country ? billingAddress.country : '') + ", " + (billingAddress?.postal_code ? billingAddress.postal_code : '') + "\n"; SubInformation += "商业地址: " + (businessAddress?.line1 ? businessAddress.line1 : '') + ", " + (businessAddress?.city ? businessAddress.city : '') + ", " + (businessAddress?.state ? businessAddress.state : '') + ", " + (businessAddress?.country ? businessAddress.country : '') + ", " + (businessAddress?.postal_code ? businessAddress.postal_code : '\n'); - // 获取付款方法信息 + response = await fetch(urlPaymentmethods, { headers }); const paymentMethodsData = await response.json(); @@ -216,8 +224,9 @@ async function checkBilling(apiKey, apiUrl) { GPT432kCheckResult = Array.isArray(modelsCheckData.data) && modelsCheckData.data.some(item => item.id.includes('gpt-4-32k')) ? '✅' : '❌'; } catch (error) { console.error(error); - errors['modelsCheck'] = error.message; } + + // 发起请求查有效 async function checkCompletion(apiKey, apiUrl) { const urlCompletion = `${apiUrl}/v1/chat/completions`; const headers = { @@ -256,17 +265,12 @@ async function checkBilling(apiKey, apiUrl) { } } -function formatDate(date) { - const year = date.getFullYear(); - const month = (date.getMonth() + 1).toString().padStart(2, '0'); - const day = date.getDate().toString().padStart(2, '0'); - return `${year}-${month}-${day}`; -} //查询函数 function sendRequest() { showLoadingAnimation(); + toggleProgressBar(); toggleSubInfo(); toggleSetidInfo(); @@ -373,26 +377,31 @@ function sendRequest() { let totalAmount = document.createElement("td"); totalAmount.classList.add("border"); totalAmount.classList.add("border-slate-500"); - totalAmount.textContent = data[0]; + totalAmount.textContent = typeof data[0] === "number" ? data[0] : "无值"; row.appendChild(totalAmount); let totalUsedCell = document.createElement("td"); totalUsedCell.classList.add("border"); totalUsedCell.classList.add("border-slate-500"); - if (!isNaN(data[1])) { + typeof data[1] === "number" ? data[1].toFixed(3) : '无值'; + if(isNaN(data[1])){ + totalUsedCell.textContent = "无值"; + }else{ totalUsedCell.textContent = data[1].toFixed(3); - } else { - totalUsedCell.textContent = '❌' } row.appendChild(totalUsedCell); let totalAvailableCell = document.createElement("td"); totalAvailableCell.classList.add("border"); totalAvailableCell.classList.add("border-slate-500"); - totalAvailableCell.textContent = typeof data[2] === 'number' ? data[2] : data[2]; + if(isNaN(data[2])){ + totalAvailableCell.textContent = "无值"; + }else{ + totalAvailableCell.textContent = data[2]; + } row.appendChild(totalAvailableCell); - + // 进度条 let progressCell = document.createElement("td"); progressCell.classList.add("progressbar"); progressCell.classList.add("border"); @@ -420,7 +429,13 @@ function sendRequest() { let expireTime = document.createElement("td"); expireTime.classList.add("border"); expireTime.classList.add("border-slate-500"); - expireTime.textContent = data[3]; + if (data[3] === "1970-01-01") { + expireTime.textContent = "永久有效"; + }else if(data[3] === "NaN-NaN-NaN"){ + expireTime.textContent = "无值"; + }else{ + expireTime.textContent = data[3]; + } row.appendChild(expireTime); @@ -450,6 +465,12 @@ function sendRequest() { isSubscribe.classList.add("border-slate-500"); isSubscribe.style.whiteSpace = "pre"; // 添加这一行来保留换行 isSubscribe.textContent = data[7]; + if (data[7] === "Not Found.") { + isSubscribe.textContent = "无值"; + } else { + isSubscribe.textContent = data[7]; + } + row.appendChild(isSubscribe); let SubInformation = document.createElement("td"); @@ -525,7 +546,6 @@ function sendRequest() { queriedApiKeys = []; } serialNumber++; // 增加序列号 - // h2.style.display = 'block'; table.style.display = 'table'; hideLoadingAnimation(); From 407f53647b9260d58aef21e3c03c8472311eee74 Mon Sep 17 00:00:00 2001 From: wood Date: Mon, 4 Sep 2023 14:14:38 +0800 Subject: [PATCH 2/6] update --- index.html | 8 ++++---- static/css-1.css | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 15deb2f..08a970d 100644 --- a/index.html +++ b/index.html @@ -12,7 +12,7 @@ -
+
-
+

查询结果

-
- +
+
diff --git a/static/css-1.css b/static/css-1.css index 010ee41..fd7e7a6 100644 --- a/static/css-1.css +++ b/static/css-1.css @@ -9,7 +9,6 @@ body { } .container { - /* display: flex; */ height: 100%; } From c90b5717491801bc8407ac4605c9f41ac029b42d Mon Sep 17 00:00:00 2001 From: wood chen <95951386+woodchen-ink@users.noreply.github.com> Date: Thu, 12 Oct 2023 23:15:32 -0500 Subject: [PATCH 3/6] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index fdfef9e..78f782d 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,10 @@ Telegram交流群:https://t.me/ai_cn2023 ## 怎么部署 下载index.html直接打开就行,除了背景图片,没有任何外部资源。 +## 赞赏码,如果觉得好用,可以请我喝杯咖啡 + +![IMG_1768.png](https://cdn-img-r2.czl.net/2023/10/13/6528c3c44100a.png) + ## 贡献列表 | 人员 | 贡献内容 | From e0c7bbe9bcfdc7cc4392a02c5aa88cf3d9ce405c Mon Sep 17 00:00:00 2001 From: wood Date: Fri, 13 Oct 2023 12:47:39 +0800 Subject: [PATCH 4/6] udpate --- index.html | 14 +++++--------- static/css-1.css | 2 +- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/index.html b/index.html index 08a970d..28dcdd3 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@ - + @@ -79,17 +79,13 @@ 查询 - diff --git a/static/css-1.css b/static/css-1.css index fd7e7a6..658b5e9 100644 --- a/static/css-1.css +++ b/static/css-1.css @@ -1,5 +1,5 @@ body { - background: url('https://cdn-img.czl.net/2023/05/23/pjbczr.webp') no-repeat center center fixed; + background: url('https://cdn-img-r2.czl.net/2023/05/23/pjbczr.webp') no-repeat center center fixed; background-size:cover; } From 2513055b205aa907bb4b2f07ae43af259ab05b17 Mon Sep 17 00:00:00 2001 From: wood chen <95951386+woodchen-ink@users.noreply.github.com> Date: Tue, 17 Oct 2023 04:59:46 -0500 Subject: [PATCH 5/6] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 78f782d..6408971 100644 --- a/README.md +++ b/README.md @@ -43,3 +43,6 @@ Telegram交流群:https://t.me/ai_cn2023 - [CZLOapi](https://oapi.czl.net),OPENAI代理服务,无需翻墙。 - 个人博客:https://woodchen.ink +## Star History + +[![Star History Chart](https://api.star-history.com/svg?repos=woodchen-ink/openai-billing-query&type=Date)](https://api.star-history.com/svg?repos=woodchen-ink/openai-billing-query&type=Date) From 352f3fd129dbbca17e8735630473a3f5e7ca6837 Mon Sep 17 00:00:00 2001 From: wood chen <95951386+woodchen-ink@users.noreply.github.com> Date: Thu, 19 Oct 2023 00:38:12 -0500 Subject: [PATCH 6/6] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6408971..3226456 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,10 @@ star,please. -## [English](README_EN.md) - Telegram交流群:https://t.me/ai_cn2023 +QQ群:https://qm.qq.com/q/cCKTiXSn3G + +## [English](README_EN.md) ## 最新示意图(2023.08.28)
序号