export default { async fetch(request, env, ctx) { const url = new URL(request.url); // 处理 API 请求 if (url.pathname === '/api/add-ssl' && request.method === 'POST') { return handleApiRequest(request); } // 返回 HTML 页面 return new Response(getHTML(), { headers: { 'Content-Type': 'text/html; charset=utf-8', }, }); }, }; async function handleApiRequest(request) { try { const { email, zone_id, api_key } = await request.json(); // 验证输入 if (!email || !zone_id || !api_key) { return new Response(JSON.stringify({ success: false, errors: ['所有字段都是必需的'] }), { status: 400, headers: { 'Content-Type': 'application/json' } }); } // 调用 Cloudflare API const response = await fetch(`https://api.cloudflare.com/client/v4/zones/${zone_id}/ssl/universal/settings`, { method: 'PATCH', headers: { 'X-Auth-Email': email, 'X-Auth-Key': api_key, 'Content-Type': 'application/json', }, body: JSON.stringify({ enabled: true, certificate_authority: "ssl_com" }), }); const result = await response.json(); return new Response(JSON.stringify(result), { headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'POST', 'Access-Control-Allow-Headers': 'Content-Type', }, }); } catch (error) { return new Response(JSON.stringify({ success: false, errors: [`请求失败: ${error.message}`] }), { status: 500, headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*', } }); } } function getHTML() { return ` IP6.ARPA域名自动添加SSL证书

IP6.ARPA域名自动添加SSL证书

注册ip6.arpa域名
请输入有效的邮箱地址
请输入区域ID
请输入API密钥

使用说明

1. 请确保您输入的Cloudflare账户信息正确

2. 请确保您的ip6.arpa域名已在cloudflare激活状态再添加

3. 添加成功后,请等待10分钟,然后在域名菜单检查SSL/TLS证书

4. 此工具使用Cloudflare API为您的IP6.ARPA域名添加SSL证书

`; }