通过access token 获取sess

Fixes #14
This commit is contained in:
wood 2023-08-30 21:38:37 +08:00
parent 0db7de1f51
commit 1aa9aeebca
5 changed files with 240 additions and 124 deletions

View File

@ -1,53 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>获取SESS</title>
<meta name="description" content="批量获取OPENAI账号的sess id">
<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">获取SESS</h1>
</header>
<div class="query">
<div>
<h2 style="display: inline-block;">输入 API KEY</h2>
<p style="display: inline-block; font-size: smaller;">通过fakeopen.com获取自行考虑风险。</p>
</div>
<textarea id="api-key-input" placeholder="请输入 账号和密码,用 --- 分开,前后有两个空格"></textarea></p>
</div>
<button :class="{ loading }" :disabled="loading" onclick="sendRequest()">查询</button> </p>
</div>
<h2 id="result-head" style="visibility:hidden">查询结果</h2>
<table id="result" style="visibility:hidden">
<thead>
<tr>
<th style="width:35px">序号</th>
<th>邮箱</th>
<th style="width: 50px;">user-id</th>
<th >sess</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>
<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/sess.js"></script>
</body>
</html>

69
get_sess1.html Normal file
View File

@ -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>

View File

@ -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">

View File

@ -1,70 +0,0 @@
// 定义一个异步函数来发送请求
async function sendRequest() {
//获取用户输入的账号和密码
let input = document.getElementById('api-key-input').value.split('\n');
let users = input.map(user => {
const [username, password] = user.split(' --- ');
return { username, password };
});
//获取前一天的日期
let day = new Date();
day.setDate(day.getDate() - 1);
let yesterday = day.toISOString().slice(0, 10).replace(/-/g, '');
for (let i = 0; i < users.length; i++) {
let user = users[i];
//发送第一个请求
const response1 = await fetch('https://ai-' + yesterday + '.fakeopen.com/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Origin': `https://ai-${yesterday}.fakeopen.com`,
'Referer': `https://ai-${yesterday}.fakeopen.com/auth1`
},
body: new URLSearchParams({
username: user.username,
password: user.password,
mfa_code: ''
}),
});
const data1 = await response1.json();
const accessToken = data1.access_token;
//发送第二个请求
const response2 = await fetch('https://ai.fakeopen.com/dashboard/onboarding/login', {
method: 'GET',
headers: {
'Authorization': 'Bearer ' + accessToken,
},
});
const data2 = await response2.json();
//打印结果到 #result 表格
let result = document.getElementById('result');
result.style.visibility = 'visible';
result.innerHTML += `<tr><td>${i + 1}</td><td>${data2.user.email}</td><td>${data2.user.id}</td><td>${data2.user.session.sensitive_id}</td></tr>`;
}
//显示结果标题
document.getElementById('result-head').style.visibility = 'visible';
//为每个用户添加一个按钮,点击复制 sensitive_id
let button = document.createElement('button');
button.innerText = '复制 sensitive_id';
document.body.appendChild(button);
let sensitive_ids = Array.from(document.getElementById('result').querySelectorAll('tr td:nth-child(4)')).map(td => td.innerText);
button.addEventListener('click', function () {
let copyText = sensitive_ids.join('\n');
navigator.clipboard.writeText(copyText)
.then(() => {
alert('Copied!');
})
.catch(err => {
alert('Error in copying text: ', err);
});
});
}

170
static/sess1.js Normal file
View File

@ -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";
}
});