|
基于 Claude sessionkey批量测活 - #12,来自 tibbar 中的sh脚本,我使用 Claude 3.5 简单写了一个可以在cf worker部署的代码,实现Session Key批量测试。代码如下:
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
if (request.method === 'POST') {
const formData = await request.formData()
const sessionKeysInput = formData.get('sessionKeys')
if (!sessionKeysInput) {
return new Response(JSON.stringify({ error: '没有输入Session Keys' }), {
status: 400,
headers: { 'Content-Type': 'application/json' }
})
}
const sessionKeys = sessionKeysInput.split('\n').filter(key => key.trim() !== '')
let csvContent = '"SessionKey","Name","Capabilities","是否可用"\n'
for (const sessionKey of sessionKeys) {
try {
console.log(`处理session key: ${sessionKey}`)
const response = await fetch('https://api.claude.ai/api/organizations', {
headers: {
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8',
'accept-language': 'en-US,en;q=0.9',
'cache-control': 'max-age=0',
'cookie': `sessionKey=${sessionKey}`,
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64)',
'sec-fetch-mode': 'navigate',
'sec-fetch-site': 'none'
}
})
if (!response.ok) {
throw new Error(`HTTP错误! 状态: ${response.status}`)
}
const responseText = await response.text()
console.log(`响应: ${responseText}`)
if (responseText.toLowerCase().includes('unauthorized')) {
console.log(`无效的session key: ${sessionKey}`)
csvContent += `"${sessionKey}","无效","","否"\n`
continue
}
if (responseText.trim() === '') {
console.log(`session key无响应: ${sessionKey}`)
csvContent += `"${sessionKey}","无响应","","否"\n`
continue
}
const objects = JSON.parse(responseText)
for (const object of objects) {
const name = object.name
const capabilities = object.capabilities ? object.capabilities.join(';') : ''
if (!name) {
console.log(`在session key的响应中未找到名称: ${sessionKey}`)
continue
}
const escapedName = name.replace(/"/g, '""')
const escapedCapabilities = capabilities.replace(/"/g, '""')
csvContent += `"${sessionKey}","${escapedName}","${escapedCapabilities}","是"\n`
}
} catch (error) {
console.error(`处理session key时发生错误: ${sessionKey}`, error)
csvContent += `"${sessionKey}","处理错误","${error.message}","否"\n`
}
}
return new Response(csvContent, {
headers: { 'Content-Type': 'text/csv' }
})
} else {
return new Response(`
Session Key 批量测试
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
line-height: 1.6;
color: #333;
background-color: #f5f5f7;
}
.container {
max-width: 800px;
margin: 0 auto;
padding: 40px 20px;
}
h1 {
color: #1d1d1f;
font-size: 48px;
font-weight: 600;
letter-spacing: -0.003em;
margin-bottom: 40px;
}
.form-container {
background-color: #fff;
border-radius: 18px;
padding: 30px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
textarea.form-control {
height: 200px;
border: 1px solid #d2d2d7;
border-radius: 12px;
font-size: 16px;
resize: vertical;
}
.btn-primary {
background-color: #0071e3;
border-color: #0071e3;
border-radius: 22px;
font-size: 17px;
font-weight: 400;
letter-spacing: -0.022em;
padding: 12px 24px;
transition: all 0.3s ease;
}
.btn-primary:hover {
background-color: #0077ed;
border-color: #0077ed;
}
Claude Session Key 批量测试
处理
错误
关闭
`, {
headers: { 'Content-Type': 'text/html; charset=utf-8' }
})
}
}
部署后的效果:https://claude-test.qf722.us.kg/
|
|