349 lines
12 KiB
HTML
349 lines
12 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>兑换码生成器</title>
|
|
<style>
|
|
body {
|
|
font-family: 'Arial', sans-serif;
|
|
max-width: 800px;
|
|
margin: 0 auto;
|
|
padding: 20px;
|
|
background-color: #f5f5f5;
|
|
}
|
|
h1 {
|
|
color: #333;
|
|
text-align: center;
|
|
}
|
|
.container {
|
|
background-color: white;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
|
}
|
|
.generator-section {
|
|
margin-bottom: 30px;
|
|
padding: 15px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 5px;
|
|
}
|
|
.generator-section h2 {
|
|
margin-top: 0;
|
|
color: #444;
|
|
}
|
|
.input-group {
|
|
margin-bottom: 15px;
|
|
}
|
|
label {
|
|
display: block;
|
|
margin-bottom: 5px;
|
|
font-weight: bold;
|
|
}
|
|
input[type="text"] {
|
|
width: 100%;
|
|
padding: 8px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
box-sizing: border-box;
|
|
}
|
|
button {
|
|
background-color: #4CAF50;
|
|
color: white;
|
|
border: none;
|
|
padding: 10px 15px;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
font-size: 16px;
|
|
margin-right: 10px;
|
|
margin-bottom: 10px;
|
|
}
|
|
button:hover {
|
|
background-color: #45a049;
|
|
}
|
|
button.secondary {
|
|
background-color: #2196F3;
|
|
}
|
|
button.secondary:hover {
|
|
background-color: #0b7dda;
|
|
}
|
|
.code-display {
|
|
margin: 20px 0;
|
|
padding: 15px;
|
|
background-color: #f9f9f9;
|
|
border: 1px dashed #ccc;
|
|
border-radius: 4px;
|
|
font-family: 'Courier New', monospace;
|
|
word-break: break-all;
|
|
min-height: 20px;
|
|
}
|
|
.note {
|
|
font-size: 14px;
|
|
color: #666;
|
|
margin-top: 5px;
|
|
}
|
|
.success-message {
|
|
color: #4CAF50;
|
|
margin-top: 10px;
|
|
font-weight: bold;
|
|
}
|
|
.error-message {
|
|
color: #f44336;
|
|
margin-top: 10px;
|
|
font-weight: bold;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>兑换码生成器</h1>
|
|
|
|
<!-- 6位兑换码生成器 -->
|
|
<div class="generator-section">
|
|
<h2>6位兑换码</h2>
|
|
<p class="note">1500金币 + 锤子,时间停止,魔法棒各3个道具</p>
|
|
|
|
<div class="input-group">
|
|
<label for="code6">兑换码(留空则随机生成):</label>
|
|
<input type="text" id="code6" placeholder="输入6位字母数字组合或留空">
|
|
</div>
|
|
|
|
<button onclick="generateCode(6)">随机生成</button>
|
|
<button onclick="copyCode('code6')">复制兑换码</button>
|
|
<button class="secondary" onclick="sendToServer('code6')">保存到服务器</button>
|
|
|
|
<div class="code-display" id="display6"></div>
|
|
<div id="message6"></div>
|
|
</div>
|
|
|
|
<!-- 7位兑换码生成器 -->
|
|
<div class="generator-section">
|
|
<h2>7位兑换码</h2>
|
|
<p class="note">600金币 + 锤子,时间停止,魔法棒各1个道具</p>
|
|
|
|
<div class="input-group">
|
|
<label for="code7">兑换码(留空则随机生成):</label>
|
|
<input type="text" id="code7" placeholder="输入7位字母数字组合或留空">
|
|
</div>
|
|
|
|
<button onclick="generateCode(7)">随机生成</button>
|
|
<button onclick="copyCode('code7')">复制兑换码</button>
|
|
<button class="secondary" onclick="sendToServer('code7')">保存到服务器</button>
|
|
|
|
<div class="code-display" id="display7"></div>
|
|
<div id="message7"></div>
|
|
</div>
|
|
<!-- 8位兑换码生成器 -->
|
|
<!-- <div class="generator-section">
|
|
<h2>8位兑换码</h2>
|
|
<p class="note">600金币 + 1个道具</p>
|
|
|
|
<div class="input-group">
|
|
<label for="code8">兑换码(留空则随机生成):</label>
|
|
<input type="text" id="code8" placeholder="输入8位字母数字组合或留空">
|
|
</div>
|
|
|
|
<button onclick="generateCode(8)">随机生成</button>
|
|
<button onclick="copyCode('code8')">复制兑换码</button>
|
|
<button class="secondary" onclick="sendToServer('code8')">保存到服务器</button>
|
|
|
|
<div class="code-display" id="display8"></div>
|
|
<div id="message8"></div>
|
|
</div> -->
|
|
</div>
|
|
|
|
<script>
|
|
// 生成随机兑换码
|
|
function generateRandomCode(length) {
|
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
let result = '';
|
|
for (let i = 0; i < length; i++) {
|
|
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// 生成兑换码
|
|
function generateCode(length) {
|
|
let inputId;
|
|
let displayId;
|
|
let messageId;
|
|
switch(length){
|
|
case 6:
|
|
inputId="code6";
|
|
displayId="display6";
|
|
messageId="message6";
|
|
break;
|
|
case 7:
|
|
inputId="code7";
|
|
displayId="display7";
|
|
messageId="message7";
|
|
break;
|
|
case 8:
|
|
inputId="code8";
|
|
displayId="display8";
|
|
messageId="message8";
|
|
break;
|
|
}
|
|
|
|
|
|
const input = document.getElementById(inputId);
|
|
const display = document.getElementById(displayId);
|
|
const message = document.getElementById(messageId);
|
|
|
|
// 清空消息
|
|
message.innerHTML = '';
|
|
|
|
// 如果输入为空,则生成随机码
|
|
if (!input.value.trim()) {
|
|
input.value = generateRandomCode(length);
|
|
}
|
|
|
|
// 验证长度
|
|
if (input.value.length !== length) {
|
|
message.innerHTML = `<div class="error-message">错误:兑换码必须是${length}位</div>`;
|
|
return;
|
|
}
|
|
|
|
// 验证字符(只允许字母和数字)
|
|
if (!/^[A-Za-z0-9]+$/.test(input.value)) {
|
|
message.innerHTML = '<div class="error-message">错误:兑换码只能包含字母和数字</div>';
|
|
return;
|
|
}
|
|
|
|
// 显示兑换码
|
|
display.textContent = input.value;
|
|
}
|
|
|
|
// 复制兑换码
|
|
function copyCode(inputId) {
|
|
const input = document.getElementById(inputId);
|
|
let displayId;
|
|
let messageId;
|
|
switch(inputId){
|
|
case "code6":
|
|
displayId="display6";
|
|
messageId="message6";
|
|
break;
|
|
case "code7":
|
|
displayId="display7";
|
|
messageId="message7";
|
|
break;
|
|
case "code8":
|
|
displayId="display8";
|
|
messageId="message8";
|
|
break;
|
|
}
|
|
const display = document.getElementById(displayId);
|
|
|
|
const message = document.getElementById(messageId);
|
|
|
|
if (!display.textContent) {
|
|
message.innerHTML = '<div class="error-message">错误:没有可复制的兑换码</div>';
|
|
return;
|
|
}
|
|
|
|
// 创建一个临时的textarea元素来复制文本
|
|
const textarea = document.createElement('textarea');
|
|
textarea.value = display.textContent;
|
|
document.body.appendChild(textarea);
|
|
textarea.select();
|
|
|
|
try {
|
|
const successful = document.execCommand('copy');
|
|
if (successful) {
|
|
message.innerHTML = '<div class="success-message">兑换码已复制到剪贴板</div>';
|
|
} else {
|
|
message.innerHTML = '<div class="error-message">复制失败,请手动选择并复制</div>';
|
|
}
|
|
} catch (err) {
|
|
message.innerHTML = '<div class="error-message">复制失败,请手动选择并复制</div>';
|
|
}
|
|
|
|
document.body.removeChild(textarea);
|
|
}
|
|
|
|
// 发送到服务器
|
|
function sendToServer(inputId) {
|
|
let displayId;
|
|
let messageId;
|
|
switch(inputId){
|
|
case "code6":
|
|
displayId="display6";
|
|
messageId="message6";
|
|
break;
|
|
case "code7":
|
|
displayId="display7";
|
|
messageId="message7";
|
|
break;
|
|
case "code8":
|
|
displayId="display8";
|
|
messageId="message8";
|
|
break;
|
|
}
|
|
const input = document.getElementById(inputId);
|
|
const display = document.getElementById(displayId);
|
|
const message = document.getElementById(messageId);
|
|
|
|
if (!display.textContent) {
|
|
message.innerHTML = '<div class="error-message">错误:没有可保存的兑换码</div>';
|
|
return;
|
|
}
|
|
|
|
// 准备发送的数据
|
|
const codeType = inputId === 'code6' ? 'type6' : 'type7';
|
|
const data = {
|
|
cdk: display.textContent,
|
|
type: codeType,
|
|
timestamp: new Date().toISOString()
|
|
};
|
|
console.log(data);
|
|
// 发送POST请求
|
|
fetch('https://q6rvwvtnga.sealoshzh.site/creatCdk', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(data)
|
|
})
|
|
.then(response => {
|
|
if (!response.ok) {
|
|
throw new Error('网络响应不正常');
|
|
}
|
|
return response.json();
|
|
})
|
|
.then(data => {
|
|
message.innerHTML = '<div class="success-message">兑换码已成功保存到服务器</div>';
|
|
console.log('成功:', data);
|
|
})
|
|
.catch(error => {
|
|
message.innerHTML = `<div class="error-message">保存失败: ${error.message}</div>`;
|
|
console.error('错误:', error);
|
|
});
|
|
|
|
fetch('https://cnsl1li6q4.sealoshzh.site/creatCdk', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(data)
|
|
})
|
|
.then(response => {
|
|
if (!response.ok) {
|
|
throw new Error('网络响应不正常');
|
|
}
|
|
return response.json();
|
|
})
|
|
.then(data => {
|
|
message.innerHTML = '<div class="success-message">兑换码已成功保存到服务器</div>';
|
|
console.log('成功:', data);
|
|
})
|
|
.catch(error => {
|
|
message.innerHTML = `<div class="error-message">保存失败: ${error.message}</div>`;
|
|
console.error('错误:', error);
|
|
});
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|