Skip to content

Commit

Permalink
Merge pull request #15 from woodchen-ink:woodchen-ink/issue14
Browse files Browse the repository at this point in the history
通过access token 获取sess
  • Loading branch information
woodchen-ink authored Aug 30, 2023
2 parents 0db7de1 + 232b613 commit 712c500
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 124 deletions.
53 changes: 0 additions & 53 deletions get_sess.html

This file was deleted.

69 changes: 69 additions & 0 deletions get_sess1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>通过access_token来获取sess</title>
<meta name="description" content="批量快速查询OPENAI的余额,支持可视化展现已用比例、额度、已用量、未用量、是否GPT-4、是否GPT4-32K、是否绑卡、绑卡信息、组织信息、是否有效">
<link rel="stylesheet" href="./static/css.css" type="text/css" />
</head>

<body>
<header>
<h1 class="text-3xl font-semibold text-center mb-8 text-gradient">通过access token来获取sess</h1>
<p style="color:#FFF;text-align: center;">页面列表:<a href="index.html" style="color:#FFF;text-decoration: underline;">查API信息</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="get_sess1.html" style="color:#FFF;text-decoration: underline;">通过access token获取sess</a> </p>
</header>

<div class="query">
<div>
<h2 style="display: inline-block;">输入 Access Token</h2>
<p style="display: inline-block; font-size: smaller;">本站不保存 KEY 信息,查询后请自行保存</p>
</div>
<textarea id="api-key-input" placeholder="请输入 access_token,多个换行分开"></textarea></p>
<!-- API链接选择框 -->
<div class="api-url-container"></div>
<!-- API链接选择 -->
<div>
<h2 style="display: inline-block;">选择查询线路</h2>
<p style="display: inline-block; font-size: smaller;">支持自定义线路,官网线路需要魔法</p>
</div>
<select id="api-url-select" style="width:49%;">
<option value="https://api.openai.com">【官网线路】api.openai.com</option>
<option value="https://oapi.czl.net">【CZLoapi线路】oapi.czl.net</option>
<option value="https://openai.996.lat">【群友提供公益CF反代,勿测重要key】openai.996.lat</option>
<option value="custom">【已前置https】自定义 ...</option>
</select>

<!-- 自定义API链接输入框 -->
<input type="text" id="custom-url-input" placeholder="输入自定义API,填域名即可,无需https://" style="width:45%;" />
</div>
<button :class="{ loading }" :disabled="loading" onclick="sendRequest()">查询</button>
</div>
<h2 id="result-head" style="visibility:hidden">查询结果</h2>
<table id="result-table" style="visibility:hidden">
<thead>
<tr>
<th style="width:50px">序号</th>
<th>Access_Token</th>
<th >sess id</th>
</tr>
</thead>
<tbody></tbody>
</table>

<footer>
<p>广告链接:
<a href="https://chat.czl.net" target="_blank">CZLChat</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://oapi.czl.net" target="_blank">CZLOapi</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://store0.czl.net" target="_blank">CZL Store</a>
<br>
本网页由<a href="https://woodchen.ink" target="_blank">woodchen</a>开源于<a
href="https://github.com/woodchen-ink/openai-billing-query" target="_blank">Github</a>,欢迎给个star
</p>

</footer>
<script src="./static/sess1.js"></script>

</body>

</html>
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<h1 class="text-3xl font-semibold text-center mb-8 text-gradient">OpenAI API 信息查询</h1>
<p class=" text-center text-gradient" style="text-align: center;">7月22日更新后,需使用sess码进行查询。使用key只能查询总额度、绑卡、GPT4和组织ID。
</p>
</a>
<p style="color:#FFF;text-align: center;">页面列表:<a href="index.html" style="color:#FFF;text-decoration: underline;">查API信息</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="get_sess1.html" style="color:#FFF;text-decoration: underline;">通过access token获取sess</a> </p>
</header>

<div class="query">
Expand Down
5 changes: 5 additions & 0 deletions static/css.css
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ input#custom-url-input {
/* border: 1px solid #d3d3d3; */
}

/* #result-table tr{
border-radius: 8px;
} */

/* 下面的代码定义了结果表格奇数行的背景颜色 */
#result-table tbody tr:nth-child(odd) {
background-color: #252422;
Expand Down Expand Up @@ -446,3 +450,4 @@ button.loading::before {




70 changes: 0 additions & 70 deletions static/sess.js

This file was deleted.

170 changes: 170 additions & 0 deletions static/sess1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
let queriedApiKeys = [];
let serialNumber = 1;


async function checkBilling(apiKey, apiUrl) {
const headers = {
"Authorization": "Bearer " + apiKey,
"Content-Type": "application/json"
};
const urlGetsess = `${apiUrl}/dashboard/onboarding/login`;

try {
let getSess;
try {
const response = await fetch(urlGetsess, {
method: "POST", // 设置请求方法为 POST
headers: headers,
body: JSON.stringify({}) // 此处放置要发送的数据
});

const getsessdata = await response.json();
console.log(getsessdata);

// 获取"sensitive_id"
const sensitiveId = getsessdata.user.session.sensitive_id;

// 现在,sensitiveId 包含了"sensitive_id"的值
console.log(sensitiveId);
return [sensitiveId];
} catch (error) {
console.error(error);
}

} catch (error) {
console.error(error);
return [null];
}
}

//查询函数
async function sendRequest() {
let button = document.querySelector("button");
button.textContent = "加载中...";
button.disabled = true;
button.classList.add("loading")

let apiKeyInput = document.getElementById("api-key-input");
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() === "") {
alert("请填写API KEY");
return;
}

document.getElementById("result-table").getElementsByTagName('tbody')[0].innerHTML = "";

let apiUrl = "";
if (apiUrlSelect.value === "custom") {
if (customUrlInput.value.trim() === "") {
alert("请设置API链接");
return;
} else {
apiUrl = customUrlInput.value.trim();
if (!apiUrl.startsWith("http://") && !apiUrl.startsWith("https://")) {
apiUrl = "https://" + apiUrl;
}
}
} else {
apiUrl = apiUrlSelect.value;
}

let apiKeys = apiKeyInput.value.split(/[,\s,\n]+/);

if (apiKeys.length === 0) {
alert("未匹配到 API-KEY,请检查输入内容");
return;
}

alert("成功匹配到 API Key,确认后开始查询:" + apiKeys);

let tableBody = document.querySelector("#result-table tbody");
for (let i = 0; i < apiKeys.length; i++) {
let apiKey = apiKeys[i].trim();

if (queriedApiKeys.includes(apiKey)) {
console.log(`API KEY ${apiKey} 已查询过,跳过此次查询`);
continue;
}
queriedApiKeys.push(apiKey);

// 使用 await 关键字等待 checkBilling 的结果
let data = await checkBilling(apiKey, apiUrl);

data = data.map(item => {
if (item === undefined || item === null) {
return 'Not Found.'
} else {
return item;
}
})


let row = document.createElement("tr");

checkBilling(apiKey, apiUrl).then((data) => {
data = data.map(item => {
if (item === undefined) {
return 'Not Found.'
} else {
return item
}
}
)

let row = document.createElement("tr");

let serialNumberCell = document.createElement("td"); // 创建序列号单元格
serialNumberCell.textContent = serialNumber; // 设置序列号文本
row.appendChild(serialNumberCell); // 将序列号单元格添加到行中

let apiKeyCell = document.createElement("td");
apiKeyCell.textContent = apiKey.replace(/^(.{10}).*(.{8})$/, "$1***$2");
row.appendChild(apiKeyCell);

console.log('查看查询结果', data); // 添加 console.log 以查看 data 的值

if (data[0] === undefined) {
let errorMessageCell = document.createElement("td");
errorMessageCell.colSpan = "8";
errorMessageCell.classList.add("status-error");
errorMessageCell.textContent = "不正确或已失效的API-KEY";
row.appendChild(errorMessageCell);
} else {
let sensitiveIdResult = document.createElement("td");
sensitiveIdResult.textContent = data[0];
row.appendChild(sensitiveIdResult);
}
tableBody.appendChild(row);

if (i === apiKeys.length - 1) {
queriedApiKeys = [];
}
serialNumber++; // 增加序列号
h2.style.display = 'block';
table.style.display = 'table';

button.textContent = "查询";
button.disabled = false;
button.classList.remove("loading")
})

}
}

let apiUrlSelect = document.getElementById("api-url-select");
let customUrlInput = document.getElementById("custom-url-input");

apiUrlSelect.addEventListener("change", function () {
if (apiUrlSelect.value === "custom") {
customUrlInput.style.display = "inline-block";
customUrlInput.style.marginTop = "5px";
} else {
customUrlInput.style.display = "none";
}
});

0 comments on commit 712c500

Please sign in to comment.