八字API配置助手.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>八字API配置助手</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. box-sizing: border-box;
  12. }
  13. body {
  14. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  15. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  16. min-height: 100vh;
  17. padding: 20px;
  18. }
  19. .container {
  20. max-width: 1200px;
  21. margin: 0 auto;
  22. background: rgba(255, 255, 255, 0.95);
  23. border-radius: 16px;
  24. padding: 30px;
  25. box-shadow: 0 20px 40px rgba(0,0,0,0.1);
  26. }
  27. .header {
  28. text-align: center;
  29. margin-bottom: 40px;
  30. }
  31. .header h1 {
  32. font-size: 2.5rem;
  33. color: #333;
  34. margin-bottom: 10px;
  35. }
  36. .header p {
  37. color: #666;
  38. font-size: 1.1rem;
  39. }
  40. .api-grid {
  41. display: grid;
  42. grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  43. gap: 20px;
  44. margin-bottom: 40px;
  45. }
  46. .api-card {
  47. background: #fff;
  48. border-radius: 12px;
  49. padding: 25px;
  50. box-shadow: 0 8px 16px rgba(0,0,0,0.1);
  51. border: 2px solid transparent;
  52. transition: all 0.3s ease;
  53. cursor: pointer;
  54. }
  55. .api-card:hover {
  56. transform: translateY(-5px);
  57. box-shadow: 0 15px 30px rgba(0,0,0,0.15);
  58. }
  59. .api-card.selected {
  60. border-color: #667eea;
  61. background: linear-gradient(135deg, #f8f9ff 0%, #e8f0ff 100%);
  62. }
  63. .api-card .title {
  64. display: flex;
  65. align-items: center;
  66. margin-bottom: 15px;
  67. }
  68. .api-card .icon {
  69. font-size: 2rem;
  70. margin-right: 12px;
  71. }
  72. .api-card .name {
  73. font-size: 1.3rem;
  74. font-weight: bold;
  75. color: #333;
  76. }
  77. .api-card .badge {
  78. margin-left: auto;
  79. padding: 4px 12px;
  80. border-radius: 20px;
  81. font-size: 0.8rem;
  82. color: #fff;
  83. }
  84. .badge.recommended { background: #4CAF50; }
  85. .badge.enterprise { background: #FF9800; }
  86. .badge.free { background: #2196F3; }
  87. .api-info {
  88. margin-bottom: 15px;
  89. }
  90. .price {
  91. font-size: 1.5rem;
  92. font-weight: bold;
  93. color: #667eea;
  94. margin-bottom: 8px;
  95. }
  96. .description {
  97. color: #666;
  98. margin-bottom: 15px;
  99. line-height: 1.5;
  100. }
  101. .features {
  102. list-style: none;
  103. }
  104. .features li {
  105. display: flex;
  106. align-items: center;
  107. margin-bottom: 5px;
  108. color: #555;
  109. }
  110. .features li::before {
  111. content: "✅";
  112. margin-right: 8px;
  113. }
  114. .pros-cons {
  115. margin-top: 15px;
  116. font-size: 0.9rem;
  117. }
  118. .pros {
  119. color: #4CAF50;
  120. margin-bottom: 5px;
  121. }
  122. .cons {
  123. color: #FF5722;
  124. }
  125. .config-section {
  126. background: #f8f9fa;
  127. border-radius: 12px;
  128. padding: 30px;
  129. margin-top: 30px;
  130. }
  131. .config-section h2 {
  132. color: #333;
  133. margin-bottom: 20px;
  134. }
  135. .form-group {
  136. margin-bottom: 20px;
  137. }
  138. .form-group label {
  139. display: block;
  140. font-weight: bold;
  141. margin-bottom: 8px;
  142. color: #555;
  143. }
  144. .form-group input,
  145. .form-group select {
  146. width: 100%;
  147. padding: 12px;
  148. border: 2px solid #ddd;
  149. border-radius: 8px;
  150. font-size: 1rem;
  151. transition: border-color 0.3s;
  152. }
  153. .form-group input:focus,
  154. .form-group select:focus {
  155. outline: none;
  156. border-color: #667eea;
  157. }
  158. .generated-config {
  159. background: #2d3748;
  160. color: #e2e8f0;
  161. padding: 20px;
  162. border-radius: 8px;
  163. font-family: 'Monaco', 'Menlo', monospace;
  164. font-size: 0.9rem;
  165. line-height: 1.5;
  166. margin-top: 20px;
  167. overflow-x: auto;
  168. }
  169. .buttons {
  170. text-align: center;
  171. margin-top: 30px;
  172. }
  173. .btn {
  174. display: inline-block;
  175. padding: 12px 30px;
  176. margin: 0 10px;
  177. border: none;
  178. border-radius: 8px;
  179. font-size: 1rem;
  180. font-weight: bold;
  181. cursor: pointer;
  182. transition: all 0.3s;
  183. text-decoration: none;
  184. }
  185. .btn-primary {
  186. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  187. color: #fff;
  188. }
  189. .btn-primary:hover {
  190. transform: translateY(-2px);
  191. box-shadow: 0 8px 16px rgba(102, 126, 234, 0.3);
  192. }
  193. .btn-secondary {
  194. background: #6c757d;
  195. color: #fff;
  196. }
  197. .tips {
  198. background: #e8f4f8;
  199. border-left: 4px solid #2196F3;
  200. padding: 20px;
  201. margin-top: 30px;
  202. border-radius: 8px;
  203. }
  204. .tips h3 {
  205. color: #2196F3;
  206. margin-bottom: 15px;
  207. }
  208. .tips ul {
  209. padding-left: 20px;
  210. }
  211. .tips li {
  212. margin-bottom: 8px;
  213. line-height: 1.5;
  214. }
  215. </style>
  216. </head>
  217. <body>
  218. <div class="container">
  219. <div class="header">
  220. <h1>🔮 八字API配置助手</h1>
  221. <p>选择最适合您项目的专业八字API接口</p>
  222. </div>
  223. <div class="api-grid">
  224. <!-- 极速数据 -->
  225. <div class="api-card" data-api="JISU_API">
  226. <div class="title">
  227. <span class="icon">🥇</span>
  228. <span class="name">极速数据</span>
  229. <span class="badge recommended">推荐</span>
  230. </div>
  231. <div class="api-info">
  232. <div class="price">0.01元/次</div>
  233. <div class="description">性价比之王,新用户100次免费</div>
  234. <ul class="features">
  235. <li>精确四柱计算</li>
  236. <li>完整纳音五行</li>
  237. <li>节气准确对应</li>
  238. <li>响应速度快</li>
  239. </ul>
  240. <div class="pros-cons">
  241. <div class="pros">✅ 价格便宜,功能齐全</div>
  242. <div class="cons">❌ 高级分析功能较少</div>
  243. </div>
  244. </div>
  245. </div>
  246. <!-- 聚合数据 -->
  247. <div class="api-card" data-api="JUHE_API">
  248. <div class="title">
  249. <span class="icon">🏢</span>
  250. <span class="name">聚合数据</span>
  251. <span class="badge">全面</span>
  252. </div>
  253. <div class="api-info">
  254. <div class="price">0.02元/次</div>
  255. <div class="description">功能全面,分析详细</div>
  256. <ul class="features">
  257. <li>详细性格分析</li>
  258. <li>运势预测</li>
  259. <li>婚配建议</li>
  260. <li>事业指导</li>
  261. </ul>
  262. <div class="pros-cons">
  263. <div class="pros">✅ 分析内容丰富</div>
  264. <div class="cons">❌ 价格略高</div>
  265. </div>
  266. </div>
  267. </div>
  268. <!-- 阿里云市场 -->
  269. <div class="api-card" data-api="ALIYUN_API">
  270. <div class="title">
  271. <span class="icon">🌟</span>
  272. <span class="name">阿里云市场</span>
  273. <span class="badge enterprise">企业级</span>
  274. </div>
  275. <div class="api-info">
  276. <div class="price">0.015元/次</div>
  277. <div class="description">企业级稳定,技术支持好</div>
  278. <ul class="features">
  279. <li>99.9%可用性</li>
  280. <li>7x24技术支持</li>
  281. <li>SLA保障</li>
  282. <li>批量调用优化</li>
  283. </ul>
  284. <div class="pros-cons">
  285. <div class="pros">✅ 稳定可靠,支持好</div>
  286. <div class="cons">❌ 需要实名认证</div>
  287. </div>
  288. </div>
  289. </div>
  290. <!-- 开源方案 -->
  291. <div class="api-card" data-api="OPEN_SOURCE">
  292. <div class="title">
  293. <span class="icon">🆓</span>
  294. <span class="name">开源方案</span>
  295. <span class="badge free">免费</span>
  296. </div>
  297. <div class="api-info">
  298. <div class="price">0元</div>
  299. <div class="description">完全免费,功能基础</div>
  300. <ul class="features">
  301. <li>永久免费</li>
  302. <li>无调用限制</li>
  303. <li>代码可控</li>
  304. <li>离线使用</li>
  305. </ul>
  306. <div class="pros-cons">
  307. <div class="pros">✅ 零成本,可定制</div>
  308. <div class="cons">❌ 准确度相对较低</div>
  309. </div>
  310. </div>
  311. </div>
  312. </div>
  313. <div class="config-section">
  314. <h2>📝 配置生成器</h2>
  315. <div class="form-group">
  316. <label for="selected-api">选择的API:</label>
  317. <select id="selected-api">
  318. <option value="">请先选择上面的API卡片</option>
  319. </select>
  320. </div>
  321. <div class="form-group">
  322. <label for="api-key">API Key:</label>
  323. <input type="text" id="api-key" placeholder="请输入您的API Key">
  324. </div>
  325. <div class="form-group">
  326. <label for="strategy">选择策略:</label>
  327. <select id="strategy">
  328. <option value="cost_first">成本优先</option>
  329. <option value="accuracy_first">准确度优先</option>
  330. <option value="speed_first">速度优先</option>
  331. </select>
  332. </div>
  333. <div class="form-group">
  334. <label for="daily-budget">每日预算 (元):</label>
  335. <input type="number" id="daily-budget" value="10" min="0" step="0.1">
  336. </div>
  337. <div class="generated-config" id="generated-config">
  338. <div style="color: #a0aec0;">// 请先选择API并填写配置信息</div>
  339. </div>
  340. <div class="buttons">
  341. <button class="btn btn-primary" onclick="generateConfig()">生成配置</button>
  342. <button class="btn btn-secondary" onclick="copyConfig()">复制配置</button>
  343. </div>
  344. </div>
  345. <div class="tips">
  346. <h3>💡 配置提示</h3>
  347. <ul>
  348. <li><strong>个人开发者</strong>:推荐选择极速数据,性价比最高</li>
  349. <li><strong>小型企业</strong>:推荐聚合数据或阿里云市场</li>
  350. <li><strong>大型企业</strong>:推荐阿里云市场,企业级支持</li>
  351. <li><strong>预算有限</strong>:可以选择开源方案作为起步</li>
  352. <li><strong>配置完成后</strong>:记得在小程序后台添加API域名到白名单</li>
  353. </ul>
  354. </div>
  355. </div>
  356. <script>
  357. const apiConfigs = {
  358. JISU_API: {
  359. name: '极速数据',
  360. baseUrl: 'https://api.jisuapi.com',
  361. endpoint: '/bazi/query',
  362. keyParam: 'appkey',
  363. domains: ['api.jisuapi.com']
  364. },
  365. JUHE_API: {
  366. name: '聚合数据',
  367. baseUrl: 'https://apis.juhe.cn',
  368. endpoint: '/bazi/query',
  369. keyParam: 'key',
  370. domains: ['apis.juhe.cn']
  371. },
  372. ALIYUN_API: {
  373. name: '阿里云市场',
  374. baseUrl: 'https://xxxxxxx.market.alicloudapi.com',
  375. endpoint: '/bazi',
  376. keyParam: 'Authorization',
  377. domains: ['*.market.alicloudapi.com']
  378. },
  379. OPEN_SOURCE: {
  380. name: '开源方案',
  381. baseUrl: 'local',
  382. endpoint: 'lunar-javascript',
  383. keyParam: 'none',
  384. domains: []
  385. }
  386. }
  387. let selectedAPI = null;
  388. // API卡片点击事件
  389. document.querySelectorAll('.api-card').forEach(card => {
  390. card.addEventListener('click', () => {
  391. // 移除其他选中状态
  392. document.querySelectorAll('.api-card').forEach(c => c.classList.remove('selected'));
  393. // 添加选中状态
  394. card.classList.add('selected');
  395. selectedAPI = card.dataset.api;
  396. const select = document.getElementById('selected-api');
  397. select.innerHTML = `<option value="${selectedAPI}">${apiConfigs[selectedAPI].name}</option>`;
  398. select.value = selectedAPI;
  399. generateConfig();
  400. });
  401. });
  402. // 生成配置代码
  403. function generateConfig() {
  404. if (!selectedAPI) {
  405. document.getElementById('generated-config').innerHTML =
  406. '<div style="color: #a0aec0;">// 请先选择API</div>';
  407. return;
  408. }
  409. const apiKey = document.getElementById('api-key').value || 'YOUR_API_KEY';
  410. const strategy = document.getElementById('strategy').value;
  411. const budget = document.getElementById('daily-budget').value;
  412. const config = apiConfigs[selectedAPI];
  413. let configCode = '';
  414. if (selectedAPI === 'OPEN_SOURCE') {
  415. configCode = `// 开源方案配置 - lunar-javascript
  416. // 1. 安装依赖
  417. // npm install lunar-javascript
  418. // 2. 在页面中使用
  419. import { Solar } from 'lunar-javascript';
  420. // 八字计算示例
  421. function calculateBaziOpenSource(year, month, day, hour) {
  422. const solar = Solar.fromYmdHms(year, month, day, hour, 0, 0);
  423. const lunar = solar.getLunar();
  424. const baZi = lunar.getEightChar();
  425. return {
  426. year: baZi.getYear(),
  427. month: baZi.getMonth(),
  428. day: baZi.getDay(),
  429. hour: baZi.getTime(),
  430. yearGanZhi: baZi.getYearInGanZhi(),
  431. monthGanZhi: baZi.getMonthInGanZhi(),
  432. dayGanZhi: baZi.getDayInGanZhi(),
  433. hourGanZhi: baZi.getTimeInGanZhi()
  434. };
  435. }`;
  436. } else {
  437. configCode = `// 配置文件:config/api-config.js
  438. export const BAZI_API_CONFIG = {
  439. ${selectedAPI}: {
  440. BASE_URL: '${config.baseUrl}',
  441. API_KEY: '${apiKey}', // 请替换为您的真实API Key
  442. ENDPOINTS: {
  443. bazi: '${config.endpoint}'
  444. },
  445. PRIORITY: 1,
  446. COST_PER_CALL: ${selectedAPI === 'JISU_API' ? '0.01' : selectedAPI === 'JUHE_API' ? '0.02' : '0.015'},
  447. DESCRIPTION: '${config.name}'
  448. },
  449. SETTINGS: {
  450. ENABLE_VALIDATION: true,
  451. AUTO_FAILOVER: true,
  452. DAILY_BUDGET: ${budget},
  453. STRATEGY: '${strategy}',
  454. ENABLED_APIS: ['${selectedAPI}'],
  455. TIMEOUT: 10000,
  456. RETRY_COUNT: 2
  457. }
  458. }
  459. // 小程序域名白名单配置
  460. // 需要在微信小程序后台添加以下域名:
  461. ${config.domains.map(domain => `// ${domain}`).join('\n')}`;
  462. }
  463. document.getElementById('generated-config').innerHTML = configCode;
  464. }
  465. // 复制配置代码
  466. function copyConfig() {
  467. const configText = document.getElementById('generated-config').textContent;
  468. navigator.clipboard.writeText(configText).then(() => {
  469. alert('配置代码已复制到剪贴板!');
  470. }).catch(() => {
  471. // 降级方案
  472. const textArea = document.createElement('textarea');
  473. textArea.value = configText;
  474. document.body.appendChild(textArea);
  475. textArea.select();
  476. document.execCommand('copy');
  477. document.body.removeChild(textArea);
  478. alert('配置代码已复制到剪贴板!');
  479. });
  480. }
  481. // 监听输入变化
  482. document.getElementById('api-key').addEventListener('input', generateConfig);
  483. document.getElementById('strategy').addEventListener('change', generateConfig);
  484. document.getElementById('daily-budget').addEventListener('input', generateConfig);
  485. </script>
  486. </body>
  487. </html>