← 返回首页
👶 宝宝取名
根据生辰八字,为宝宝取一个吉祥好名
姓氏
性别
请选择性别
男
女
出生日期
出生时辰
请选择出生时辰
子时 (23:00-01:00)
丑时 (01:00-03:00)
寅时 (03:00-05:00)
卯时 (05:00-07:00)
辰时 (07:00-09:00)
巳时 (09:00-11:00)
午时 (11:00-13:00)
未时 (13:00-15:00)
申时 (15:00-17:00)
酉时 (17:00-19:00)
戌时 (19:00-21:00)
亥时 (21:00-23:00)
出生地点
父母期望
开始取名
温馨提示:
• 取名结果仅供参考,最终决定请结合家庭文化和个人喜好
• 我们会根据八字五行、诗词典故为您推荐5个名字
• 每个名字都会附带详细解析和评分
免费次数已用完
单次付费可继续使用取名服务
¥2.00/次
取消
立即支付
// 关闭付费弹窗 function closePaymentDialog() { document.getElementById('paymentOverlay').classList.remove('active'); } // 处理支付 async function handlePayment() { const token = localStorage.getItem('token'); if (!token) { alert('请先登录'); window.location.href = 'login.html'; return; } try { // 判断是否在微信浏览器内 const isWechat = /MicroMessenger/i.test(navigator.userAgent); // 1. 创建订单 const createResponse = await fetch('/api/payment/create-order', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` }, body: JSON.stringify({ serviceType: 'naming', amount: 2.00, paymentType: isWechat ? 'jsapi' : 'native' // 微信内用JSAPI,PC端用Native }) }); const createResult = await createResponse.json(); if (createResult.code !== 200) { alert(createResult.message || '创建订单失败'); return; } const orderNo = createResult.data.orderNo; // 2. 获取支付参数 const payResponse = await fetch(`/api/payment/service/${orderNo}/pay`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` } }); const payResult = await payResponse.json(); if (payResult.code !== 200) { alert(payResult.message || '获取支付参数失败'); return; } const payData = payResult.data; if (isWechat) { // 微信浏览器内:JSAPI支付 invokeWechatPay(payData, orderNo); } else { // PC端:显示二维码 showQRCode(payData.code_url, orderNo); } } catch (error) { console.error('支付失败:', error); alert('支付失败,请稍后重试'); } } // 微信浏览器内:调起微信支付 function invokeWechatPay(payParams, orderNo) { if (typeof WeixinJSBridge === 'undefined') { if (document.addEventListener) { document.addEventListener('WeixinJSBridgeReady', () => doWechatPay(payParams, orderNo), false); } return; } doWechatPay(payParams, orderNo); } function doWechatPay(payParams, orderNo) { WeixinJSBridge.invoke('getBrandWCPayRequest', { "appId": payParams.appId, "timeStamp": payParams.timeStamp, "nonceStr": payParams.nonceStr, "package": payParams.package, "signType": payParams.signType, "paySign": payParams.paySign }, function(res) { if (res.err_msg === 'get_brand_wcpay_request:ok') { // 支付成功,轮询确认 pollOrderStatus(orderNo); } else if (res.err_msg === 'get_brand_wcpay_request:cancel') { alert('支付已取消'); } else { alert('支付失败'); } }); } // PC端:显示二维码 function showQRCode(codeUrl, orderNo) { // 关闭付费弹窗 closePaymentDialog(); // 创建二维码弹窗 const qrModal = document.createElement('div'); qrModal.id = 'qrModal'; qrModal.className = 'payment-overlay active'; qrModal.innerHTML = `
微信扫码支付
请使用微信扫一扫完成支付
¥2.00
取消支付
`; document.body.appendChild(qrModal); // 生成二维码(使用qrcode.js库) if (typeof QRCode !== 'undefined') { new QRCode(document.getElementById('qrcode'), { text: codeUrl, width: 200, height: 200, colorDark: '#000000', colorLight: '#ffffff', correctLevel: QRCode.CorrectLevel.H }); } else { // 如果没有QRCode库,显示链接 document.getElementById('qrcode').innerHTML = `
请复制以下链接到微信打开:
`; } // 开始轮询订单状态 pollOrderStatus(orderNo); } function closeQRModal() { const qrModal = document.getElementById('qrModal'); if (qrModal) { qrModal.remove(); } } // 轮询订单状态 async function pollOrderStatus(orderNo) { const token = localStorage.getItem('token'); let attempts = 0; const maxAttempts = 30; // 最多轮询30次(30秒) const poll = async () => { attempts++; try { const response = await fetch(`/api/payment/order/${orderNo}/status`, { headers: { 'Authorization': `Bearer ${token}` } }); const result = await response.json(); if (result.code === 200 && result.data.status === 2) { // 支付成功 closeQRModal(); alert('支付成功!'); closePaymentDialog(); location.reload(); return; } if (attempts < maxAttempts) { setTimeout(poll, 1000); } else { alert('支付确认中,请稍后刷新页面查看'); } } catch (error) { console.error('查询订单状态失败:', error); if (attempts < maxAttempts) { setTimeout(poll, 1000); } } }; poll(); } const API_BASE = '/api'; document.getElementById('namingForm').addEventListener('submit', async (e) => { e.preventDefault(); const submitBtn = document.getElementById('submitBtn'); submitBtn.disabled = true; submitBtn.textContent = '正在生成...'; const formData = { surname: document.getElementById('surname').value, gender: document.getElementById('gender').value, birth_date: document.getElementById('birth_date').value, birth_hour: document.getElementById('birth_hour').value, birth_place: document.getElementById('birth_place').value, expectations: document.getElementById('expectations').value || '健康平安' }; try { const token = localStorage.getItem('token'); const response = await fetch(`${API_BASE}/fortune/submit`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` }, body: JSON.stringify({ serviceType: 'baby_naming', inputData: JSON.stringify(formData) }) }); const result = await response.json(); if (result.code === 200) { const recordId = result.data.recordId; localStorage.setItem('currentRecordId', recordId); window.location.href = `naming_result.html?recordId=${recordId}`; } else if (result.code === 402) { // 配额不足,显示付费界面 showPaymentDialog(result.message); submitBtn.disabled = false; submitBtn.textContent = '开始取名'; } else { alert(result.message || '提交失败'); submitBtn.disabled = false; submitBtn.textContent = '开始取名'; } } catch (error) { console.error('提交失败:', error); alert('网络错误,请稍后重试'); submitBtn.disabled = false; submitBtn.textContent = '开始取名'; } });