apig-pay.html 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364
  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 服务充值 — BrainHack</title>
  7. <script src="https://cdn.jsdelivr.net/npm/qrcode@1.5.4/build/qrcode.min.js"></script>
  8. <script>
  9. // Fallback: if QRCode lib not loaded, provide a shim using img
  10. if (typeof QRCode === 'undefined') {
  11. console.warn('QRCode lib not loaded, will use img fallback');
  12. window.QRCode = null;
  13. }
  14. </script>
  15. <style>
  16. /* ═══════════════════════════════════════════════════
  17. BrainHack Dark Neumorphic Payment Page
  18. Color Palette: #0A0A0A bg, #00D4FF neon, #00B6C0 tech
  19. ═══════════════════════════════════════════════════ */
  20. :root {
  21. --bg: #0A0A0A;
  22. --surface: #141414;
  23. --surface-alt: #1A1A1A;
  24. --neon: #00D4FF;
  25. --neon-dim: #00B6C0;
  26. --neon-glow: rgba(0, 212, 255, 0.15);
  27. --neon-glow-s: rgba(0, 212, 255, 0.25);
  28. --text: #E0E0E0;
  29. --text-dim: #888;
  30. --text-bright: #FFFFFF;
  31. --success: #00FF88;
  32. --success-dim: #059660;
  33. --danger: #FF4D6A;
  34. --shadow-dark: rgba(0, 0, 0, 0.7);
  35. --shadow-light: rgba(255, 255, 255, 0.04);
  36. --radius: 12px;
  37. }
  38. * { margin: 0; padding: 0; box-sizing: border-box; }
  39. body {
  40. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  41. background: var(--bg);
  42. color: var(--text);
  43. min-height: 100vh;
  44. display: flex;
  45. flex-direction: column;
  46. align-items: center;
  47. overflow-x: hidden;
  48. }
  49. /* ─── Background Grid Effect ─── */
  50. body::before {
  51. content: '';
  52. position: fixed;
  53. top: 0; left: 0; right: 0; bottom: 0;
  54. background-image:
  55. radial-gradient(ellipse 600px 400px at 50% 0%, rgba(0,212,255,0.06) 0%, transparent 70%),
  56. linear-gradient(rgba(0,212,255,0.03) 1px, transparent 1px),
  57. linear-gradient(90deg, rgba(0,212,255,0.03) 1px, transparent 1px);
  58. background-size: 100% 100%, 40px 40px, 40px 40px;
  59. pointer-events: none;
  60. z-index: 0;
  61. }
  62. /* ─── Neumorphic Mixins (Dark Mode) ─── */
  63. .neu-raised {
  64. background: var(--surface);
  65. background-image: linear-gradient(145deg, rgba(255,255,255,0.03), rgba(0,0,0,0.2));
  66. border-radius: var(--radius);
  67. box-shadow:
  68. 4px 4px 8px var(--shadow-dark),
  69. -4px -4px 8px var(--shadow-light);
  70. transition: box-shadow 0.25s ease, background 0.25s ease, transform 0.15s ease;
  71. }
  72. .neu-raised:hover {
  73. box-shadow:
  74. 2px 2px 5px var(--shadow-dark),
  75. -2px -2px 5px var(--shadow-light);
  76. }
  77. .neu-pressed {
  78. box-shadow:
  79. inset 3px 3px 6px var(--shadow-dark),
  80. inset -3px -3px 6px var(--shadow-light);
  81. background-image: linear-gradient(145deg, rgba(0,0,0,0.25), rgba(255,255,255,0.02));
  82. }
  83. .neu-groove {
  84. background: rgba(10,10,10,0.6);
  85. box-shadow:
  86. inset 2px 2px 4px rgba(0,0,0,0.5),
  87. inset -2px -2px 4px rgba(255,255,255,0.03);
  88. border-radius: var(--radius);
  89. }
  90. /* ─── Header ─── */
  91. .page-header {
  92. position: relative;
  93. z-index: 1;
  94. width: 100%;
  95. padding: 20px 32px;
  96. display: flex;
  97. align-items: center;
  98. gap: 12px;
  99. border-bottom: 1px solid rgba(0,212,255,0.1);
  100. }
  101. .page-header .logo {
  102. font-size: 20px;
  103. font-weight: 700;
  104. letter-spacing: 2px;
  105. color: var(--text-bright);
  106. }
  107. .page-header .logo span { color: var(--neon); }
  108. .page-header .subtitle {
  109. font-size: 14px;
  110. color: var(--text-dim);
  111. margin-left: 8px;
  112. }
  113. /* ─── Main Container ─── */
  114. .main-container {
  115. position: relative;
  116. z-index: 1;
  117. width: 100%;
  118. max-width: 720px;
  119. padding: 32px 24px;
  120. flex: 1;
  121. }
  122. /* ─── API Info Card ─── */
  123. .api-info-card {
  124. padding: 28px;
  125. margin-bottom: 24px;
  126. }
  127. .api-info-card .api-title {
  128. font-size: 22px;
  129. font-weight: 700;
  130. color: var(--text-bright);
  131. margin-bottom: 8px;
  132. }
  133. .api-info-card .api-title .badge {
  134. display: inline-block;
  135. font-size: 11px;
  136. font-weight: 500;
  137. padding: 2px 8px;
  138. border: 1px solid var(--neon);
  139. color: var(--neon);
  140. border-radius: 4px;
  141. margin-left: 10px;
  142. vertical-align: middle;
  143. }
  144. .api-info-card .api-desc {
  145. font-size: 14px;
  146. color: var(--text-dim);
  147. line-height: 1.6;
  148. }
  149. .api-info-card .api-stats {
  150. display: flex;
  151. gap: 24px;
  152. margin-top: 16px;
  153. padding-top: 16px;
  154. border-top: 1px solid rgba(255,255,255,0.06);
  155. }
  156. .api-info-card .stat-item {
  157. display: flex;
  158. flex-direction: column;
  159. }
  160. .api-info-card .stat-label {
  161. font-size: 12px;
  162. color: var(--text-dim);
  163. }
  164. .api-info-card .stat-value {
  165. font-size: 18px;
  166. font-weight: 600;
  167. color: var(--neon);
  168. }
  169. /* ─── Tier Selection ─── */
  170. .section-title {
  171. font-size: 14px;
  172. color: var(--text-dim);
  173. margin-bottom: 12px;
  174. letter-spacing: 1px;
  175. }
  176. .tier-grid {
  177. display: grid;
  178. grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  179. gap: 14px;
  180. margin-bottom: 28px;
  181. }
  182. .tier-card {
  183. padding: 18px;
  184. cursor: pointer;
  185. border: 1px solid transparent;
  186. position: relative;
  187. overflow: hidden;
  188. }
  189. .tier-card::after {
  190. content: '';
  191. position: absolute;
  192. top: 0; left: 0; right: 0;
  193. height: 2px;
  194. background: transparent;
  195. transition: background 0.3s ease;
  196. }
  197. .tier-card:hover {
  198. transform: translateY(-1px);
  199. }
  200. .tier-card.active {
  201. border-color: var(--neon);
  202. box-shadow:
  203. 4px 4px 8px var(--shadow-dark),
  204. -4px -4px 8px var(--shadow-light),
  205. 0 0 15px var(--neon-glow);
  206. }
  207. .tier-card.active::after {
  208. background: linear-gradient(90deg, var(--neon), var(--neon-dim));
  209. }
  210. .tier-price {
  211. font-size: 28px;
  212. font-weight: 700;
  213. color: var(--neon);
  214. }
  215. .tier-price .symbol { font-size: 16px; }
  216. .tier-count {
  217. font-size: 14px;
  218. color: var(--text);
  219. margin-top: 4px;
  220. }
  221. .tier-unit-price {
  222. display: inline-block;
  223. font-size: 11px;
  224. color: var(--text-dim);
  225. background: rgba(255,255,255,0.05);
  226. padding: 2px 6px;
  227. border-radius: 4px;
  228. margin-top: 8px;
  229. }
  230. /* ─── Summary ─── */
  231. .summary-bar {
  232. padding: 20px 24px;
  233. margin-bottom: 24px;
  234. display: flex;
  235. justify-content: space-between;
  236. align-items: center;
  237. }
  238. .summary-bar .label {
  239. font-size: 14px;
  240. color: var(--text-dim);
  241. }
  242. .summary-bar .total {
  243. font-size: 28px;
  244. font-weight: 700;
  245. color: var(--neon);
  246. }
  247. .summary-bar .validity {
  248. font-size: 12px;
  249. color: var(--text-dim);
  250. margin-top: 2px;
  251. }
  252. /* ─── Pay Button (Neumorphic) ─── */
  253. .pay-btn {
  254. display: block;
  255. width: 100%;
  256. padding: 16px;
  257. border: none;
  258. cursor: pointer;
  259. font-size: 16px;
  260. font-weight: 600;
  261. letter-spacing: 2px;
  262. color: var(--text-bright);
  263. background: var(--surface);
  264. background-image: linear-gradient(145deg, rgba(0,212,255,0.15), rgba(0,0,0,0.3));
  265. border-radius: var(--radius);
  266. box-shadow:
  267. 5px 5px 10px var(--shadow-dark),
  268. -5px -5px 10px var(--shadow-light),
  269. 0 0 20px var(--neon-glow);
  270. transition: all 0.25s ease;
  271. position: relative;
  272. overflow: hidden;
  273. }
  274. .pay-btn::before {
  275. content: '';
  276. position: absolute;
  277. top: 0; left: 0; right: 0;
  278. height: 1px;
  279. background: linear-gradient(90deg, transparent, var(--neon), transparent);
  280. }
  281. .pay-btn:hover {
  282. box-shadow:
  283. 3px 3px 6px var(--shadow-dark),
  284. -3px -3px 6px var(--shadow-light),
  285. 0 0 30px var(--neon-glow-s);
  286. transform: translateY(-1px);
  287. }
  288. .pay-btn:active {
  289. box-shadow:
  290. inset 3px 3px 6px var(--shadow-dark),
  291. inset -3px -3px 6px var(--shadow-light);
  292. background-image: linear-gradient(145deg, rgba(0,0,0,0.3), rgba(0,212,255,0.1));
  293. transform: translateY(0);
  294. }
  295. .pay-btn:disabled {
  296. opacity: 0.5;
  297. cursor: not-allowed;
  298. box-shadow:
  299. 2px 2px 4px var(--shadow-dark),
  300. -2px -2px 4px var(--shadow-light);
  301. }
  302. .pay-btn .btn-icon { margin-right: 8px; }
  303. /* ─── QR Modal ─── */
  304. .modal-overlay {
  305. display: none;
  306. position: fixed;
  307. top: 0; left: 0; right: 0; bottom: 0;
  308. background: rgba(0,0,0,0.85);
  309. z-index: 100;
  310. align-items: center;
  311. justify-content: center;
  312. }
  313. .modal-overlay.show { display: flex; }
  314. .modal-box {
  315. width: 380px;
  316. max-width: 90vw;
  317. padding: 32px;
  318. text-align: center;
  319. position: relative;
  320. border: 1px solid rgba(0,212,255,0.15);
  321. }
  322. .modal-box .modal-close {
  323. position: absolute;
  324. top: 12px;
  325. right: 16px;
  326. background: none;
  327. border: none;
  328. color: var(--text-dim);
  329. font-size: 20px;
  330. cursor: pointer;
  331. transition: color 0.2s;
  332. }
  333. .modal-box .modal-close:hover { color: var(--text-bright); }
  334. .modal-box .modal-title {
  335. font-size: 18px;
  336. font-weight: 600;
  337. color: var(--text-bright);
  338. margin-bottom: 6px;
  339. }
  340. .modal-box .modal-amount {
  341. font-size: 32px;
  342. font-weight: 700;
  343. color: var(--neon);
  344. margin: 8px 0;
  345. }
  346. .modal-box .modal-amount .symbol { font-size: 18px; }
  347. .qr-wrapper {
  348. display: inline-block;
  349. padding: 16px;
  350. background: #fff;
  351. border-radius: 8px;
  352. margin: 16px 0;
  353. box-shadow: 0 0 20px var(--neon-glow);
  354. }
  355. .qr-wrapper canvas { display: block; }
  356. .modal-box .scan-hint {
  357. font-size: 13px;
  358. color: var(--text-dim);
  359. margin-top: 8px;
  360. }
  361. .modal-box .scan-hint svg {
  362. vertical-align: middle;
  363. margin-right: 4px;
  364. }
  365. .polling-status {
  366. font-size: 12px;
  367. color: var(--text-dim);
  368. margin-top: 12px;
  369. display: flex;
  370. align-items: center;
  371. justify-content: center;
  372. gap: 6px;
  373. }
  374. .polling-dot {
  375. display: inline-block;
  376. width: 6px; height: 6px;
  377. background: var(--neon);
  378. border-radius: 50%;
  379. animation: pulse 1.5s infinite;
  380. }
  381. @keyframes pulse {
  382. 0%, 100% { opacity: 0.3; }
  383. 50% { opacity: 1; }
  384. }
  385. /* ─── Success Screen ─── */
  386. .success-screen {
  387. display: none;
  388. text-align: center;
  389. padding: 48px 24px;
  390. }
  391. .success-screen.show { display: block; }
  392. .success-icon {
  393. width: 80px; height: 80px;
  394. margin: 0 auto 20px;
  395. border-radius: 50%;
  396. background: var(--surface);
  397. box-shadow:
  398. 5px 5px 10px var(--shadow-dark),
  399. -5px -5px 10px var(--shadow-light),
  400. 0 0 20px rgba(0,255,136,0.15);
  401. display: flex;
  402. align-items: center;
  403. justify-content: center;
  404. }
  405. .success-icon svg {
  406. width: 40px; height: 40px;
  407. stroke: var(--success);
  408. }
  409. .success-screen .success-title {
  410. font-size: 24px;
  411. font-weight: 700;
  412. color: var(--text-bright);
  413. margin-bottom: 8px;
  414. }
  415. .success-screen .success-detail {
  416. font-size: 14px;
  417. color: var(--text-dim);
  418. line-height: 1.8;
  419. margin-bottom: 28px;
  420. }
  421. .success-screen .back-btn {
  422. display: inline-block;
  423. padding: 12px 40px;
  424. border: none;
  425. cursor: pointer;
  426. font-size: 14px;
  427. font-weight: 600;
  428. color: var(--text-bright);
  429. background: var(--surface);
  430. background-image: linear-gradient(145deg, rgba(0,255,136,0.12), rgba(0,0,0,0.3));
  431. border-radius: var(--radius);
  432. box-shadow:
  433. 4px 4px 8px var(--shadow-dark),
  434. -4px -4px 8px var(--shadow-light),
  435. 0 0 15px rgba(0,255,136,0.1);
  436. transition: all 0.25s ease;
  437. }
  438. .success-screen .back-btn:hover {
  439. transform: translateY(-1px);
  440. box-shadow:
  441. 3px 3px 6px var(--shadow-dark),
  442. -3px -3px 6px var(--shadow-light),
  443. 0 0 25px rgba(0,255,136,0.15);
  444. }
  445. .success-screen .back-btn:active {
  446. box-shadow:
  447. inset 3px 3px 6px var(--shadow-dark),
  448. inset -3px -3px 6px var(--shadow-light);
  449. transform: translateY(0);
  450. }
  451. /* ─── Loading Skeleton ─── */
  452. .skeleton {
  453. background: linear-gradient(90deg, var(--surface) 25%, var(--surface-alt) 50%, var(--surface) 75%);
  454. background-size: 200% 100%;
  455. animation: shimmer 1.5s infinite;
  456. border-radius: 6px;
  457. }
  458. @keyframes shimmer {
  459. 0% { background-position: 200% 0; }
  460. 100% { background-position: -200% 0; }
  461. }
  462. /* ─── Error State ─── */
  463. .error-bar {
  464. display: none;
  465. padding: 12px 16px;
  466. background: rgba(255,77,106,0.1);
  467. border: 1px solid rgba(255,77,106,0.3);
  468. border-radius: 8px;
  469. color: var(--danger);
  470. font-size: 13px;
  471. margin-bottom: 16px;
  472. }
  473. .error-bar.show { display: block; }
  474. /* ─── Order History ─── */
  475. .order-history {
  476. margin-top: 36px;
  477. padding-top: 28px;
  478. border-top: 1px solid rgba(0,212,255,0.08);
  479. }
  480. .order-history .section-header {
  481. display: flex;
  482. align-items: center;
  483. justify-content: space-between;
  484. margin-bottom: 16px;
  485. }
  486. .order-history .section-header .section-title {
  487. margin-bottom: 0;
  488. }
  489. .order-history .refresh-btn {
  490. background: none;
  491. border: 1px solid rgba(0,212,255,0.2);
  492. color: var(--neon-dim);
  493. font-size: 12px;
  494. padding: 4px 12px;
  495. border-radius: 6px;
  496. cursor: pointer;
  497. transition: all 0.2s;
  498. }
  499. .order-history .refresh-btn:hover {
  500. border-color: var(--neon);
  501. color: var(--neon);
  502. background: var(--neon-glow);
  503. }
  504. .order-history .refresh-btn:disabled {
  505. opacity: 0.4;
  506. cursor: not-allowed;
  507. }
  508. .order-table {
  509. width: 100%;
  510. border-collapse: separate;
  511. border-spacing: 0;
  512. font-size: 13px;
  513. }
  514. .order-table thead th {
  515. text-align: left;
  516. padding: 10px 12px;
  517. color: var(--text-dim);
  518. font-weight: 500;
  519. font-size: 12px;
  520. letter-spacing: 0.5px;
  521. border-bottom: 1px solid rgba(255,255,255,0.06);
  522. white-space: nowrap;
  523. }
  524. .order-table tbody tr {
  525. transition: background 0.15s;
  526. }
  527. .order-table tbody tr:hover {
  528. background: rgba(0,212,255,0.03);
  529. }
  530. .order-table tbody td {
  531. padding: 12px 12px;
  532. border-bottom: 1px solid rgba(255,255,255,0.03);
  533. color: var(--text);
  534. vertical-align: middle;
  535. }
  536. .order-table tbody tr:last-child td {
  537. border-bottom: none;
  538. }
  539. .order-table .col-time {
  540. color: var(--text-dim);
  541. font-size: 12px;
  542. white-space: nowrap;
  543. }
  544. .order-table .col-amount {
  545. font-weight: 600;
  546. color: var(--neon);
  547. white-space: nowrap;
  548. }
  549. .order-table .col-count {
  550. white-space: nowrap;
  551. }
  552. .order-status {
  553. display: inline-block;
  554. font-size: 11px;
  555. font-weight: 500;
  556. padding: 2px 8px;
  557. border-radius: 4px;
  558. white-space: nowrap;
  559. }
  560. .order-status.status-paid {
  561. color: var(--success);
  562. background: rgba(0,255,136,0.08);
  563. border: 1px solid rgba(0,255,136,0.2);
  564. }
  565. .order-status.status-pending {
  566. color: #FFB800;
  567. background: rgba(255,184,0,0.08);
  568. border: 1px solid rgba(255,184,0,0.2);
  569. }
  570. .order-status.status-failed {
  571. color: var(--danger);
  572. background: rgba(255,77,106,0.08);
  573. border: 1px solid rgba(255,77,106,0.2);
  574. }
  575. .order-status.status-recharged {
  576. color: var(--neon);
  577. background: var(--neon-glow);
  578. border: 1px solid rgba(0,212,255,0.2);
  579. }
  580. .order-empty {
  581. text-align: center;
  582. padding: 32px 16px;
  583. color: var(--text-dim);
  584. font-size: 13px;
  585. }
  586. .order-empty svg {
  587. display: block;
  588. margin: 0 auto 12px;
  589. opacity: 0.3;
  590. }
  591. .order-loading {
  592. text-align: center;
  593. padding: 24px;
  594. color: var(--text-dim);
  595. font-size: 13px;
  596. }
  597. .order-loading .polling-dot {
  598. margin-right: 6px;
  599. }
  600. .order-error {
  601. text-align: center;
  602. padding: 16px;
  603. color: var(--text-dim);
  604. font-size: 12px;
  605. }
  606. .order-more-btn {
  607. display: block;
  608. width: 100%;
  609. padding: 10px;
  610. margin-top: 8px;
  611. background: none;
  612. border: 1px solid rgba(255,255,255,0.06);
  613. border-radius: 8px;
  614. color: var(--text-dim);
  615. font-size: 12px;
  616. cursor: pointer;
  617. transition: all 0.2s;
  618. }
  619. .order-more-btn:hover {
  620. border-color: rgba(0,212,255,0.2);
  621. color: var(--neon-dim);
  622. background: rgba(0,212,255,0.03);
  623. }
  624. /* ─── Responsive ─── */
  625. @media (max-width: 480px) {
  626. .main-container { padding: 20px 16px; }
  627. .api-info-card { padding: 20px; }
  628. .tier-grid { grid-template-columns: 1fr; }
  629. .modal-box { padding: 24px 20px; }
  630. .order-table { font-size: 12px; }
  631. .order-table thead th,
  632. .order-table tbody td { padding: 8px 6px; }
  633. }
  634. </style>
  635. </head>
  636. <body>
  637. <!-- Header -->
  638. <div class="page-header">
  639. <div class="logo">BRAIN<span>HACK</span></div>
  640. <div class="subtitle">API 服务充值</div>
  641. </div>
  642. <!-- Main -->
  643. <div class="main-container" id="mainContent">
  644. <!-- API Info Card -->
  645. <div class="api-info-card neu-raised" id="apiInfoCard">
  646. <div class="api-title" id="apiTitle">
  647. <span class="skeleton" style="display:inline-block;width:200px;height:24px;">&nbsp;</span>
  648. </div>
  649. <div class="api-desc" id="apiDesc">
  650. <span class="skeleton" style="display:inline-block;width:100%;height:16px;margin-top:8px;">&nbsp;</span>
  651. </div>
  652. <div class="api-stats" id="apiStats" style="display:none;">
  653. <div class="stat-item">
  654. <span class="stat-label">当前余额</span>
  655. <span class="stat-value" id="statCount">—</span>
  656. </div>
  657. <div class="stat-item">
  658. <span class="stat-label">服务状态</span>
  659. <span class="stat-value" id="statStatus">—</span>
  660. </div>
  661. </div>
  662. </div>
  663. <!-- Error -->
  664. <div class="error-bar" id="errorBar"></div>
  665. <!-- Tier Selection -->
  666. <div class="section-title">选择套餐</div>
  667. <div class="tier-grid" id="tierGrid">
  668. <div class="tier-card neu-raised skeleton" style="height:100px;"></div>
  669. <div class="tier-card neu-raised skeleton" style="height:100px;"></div>
  670. <div class="tier-card neu-raised skeleton" style="height:100px;"></div>
  671. </div>
  672. <!-- Summary -->
  673. <div class="summary-bar neu-groove" id="summaryBar" style="display:none;">
  674. <div>
  675. <div class="label">套餐配额</div>
  676. <div id="summaryCount" style="font-size:16px;font-weight:600;color:var(--text-bright);margin-top:2px;">—</div>
  677. <div class="validity">有效期 730 天(自购买之日起)</div>
  678. </div>
  679. <div style="text-align:right;">
  680. <div class="label">应付金额</div>
  681. <div class="total"><span class="symbol">¥</span><span id="summaryPrice">0</span></div>
  682. </div>
  683. </div>
  684. <!-- Pay Button -->
  685. <button class="pay-btn" id="payBtn" disabled>
  686. <span class="btn-icon">💳</span> 微信支付
  687. </button>
  688. <!-- Order History -->
  689. <div class="order-history" id="orderHistory" style="display:none;">
  690. <div class="section-header">
  691. <div class="section-title">历史订单</div>
  692. <button class="refresh-btn" id="refreshOrdersBtn" onclick="loadOrderHistory()">刷新</button>
  693. </div>
  694. <div class="neu-groove" style="padding:2px 16px;overflow-x:auto;">
  695. <div id="orderListBody">
  696. <div class="order-loading"><span class="polling-dot"></span> 加载中...</div>
  697. </div>
  698. </div>
  699. </div>
  700. <!-- Success Screen -->
  701. <div class="success-screen" id="successScreen">
  702. <div class="success-icon">
  703. <svg viewBox="0 0 24 24" fill="none" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
  704. <polyline points="20 6 9 17 4 12"></polyline>
  705. </svg>
  706. </div>
  707. <div class="success-title">充值成功</div>
  708. <div class="success-detail" id="successDetail"></div>
  709. <button class="back-btn" onclick="handleDone()">完成</button>
  710. </div>
  711. </div>
  712. <!-- QR Modal -->
  713. <div class="modal-overlay" id="qrModal">
  714. <div class="modal-box neu-raised">
  715. <button class="modal-close" onclick="cancelPayment()">&times;</button>
  716. <div class="modal-title">微信扫码支付</div>
  717. <div class="modal-amount"><span class="symbol">¥</span><span id="modalPrice">0</span></div>
  718. <div class="qr-wrapper" id="qrWrapper">
  719. <canvas id="qrCanvas"></canvas>
  720. </div>
  721. <div class="scan-hint">
  722. <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"></path><circle cx="12" cy="13" r="4"></circle></svg>
  723. 打开微信扫一扫
  724. </div>
  725. <div class="polling-status" id="pollingStatus">
  726. <span class="polling-dot"></span> 等待支付中...
  727. </div>
  728. </div>
  729. </div>
  730. <script>
  731. // ═══════════════════════════════════════════════════
  732. // APIG Payment Logic
  733. // ═══════════════════════════════════════════════════
  734. const API_BASE = 'https://server.fmode.cn';
  735. const PARSE_BASE = API_BASE + '/parse/functions';
  736. const PAY_COMPANY = '1AiWpTEDH9';
  737. const APP_ID = 'ncloudmaster';
  738. // URL params
  739. const params = new URLSearchParams(window.location.search);
  740. const authId = params.get('authid') || '';
  741. const userId = params.get('user') || params.get('userid') || '';
  742. let apig = null;
  743. let selectedIndex = 0;
  744. let order = null;
  745. let tradeNo = '';
  746. let nonceStr = '';
  747. let pollTimer = null;
  748. // ─── Init ───
  749. document.addEventListener('DOMContentLoaded', () => {
  750. if (!authId) {
  751. showError('缺少 authid 参数,请通过正确链接访问本页面。');
  752. return;
  753. }
  754. // Show loading state
  755. const titleEl = document.getElementById('apiTitle');
  756. if (titleEl) titleEl.textContent = '加载中...';
  757. loadApig();
  758. });
  759. // ─── Load APIG Info ───
  760. async function loadApig() {
  761. try {
  762. // 1. Try getApig REST endpoint (works when authId is an APIGAuth objectId)
  763. const resp = await postJSON(API_BASE + '/api/apig/getApig', { authid: authId });
  764. if (resp.code === 200 && resp.data) {
  765. apig = resp.data;
  766. applyTestTier();
  767. renderApigInfo();
  768. renderTiers();
  769. loadOrderHistory();
  770. return;
  771. }
  772. // 2. Fallback: use cloud function to query APIG by objectId
  773. // Cloud function IDs: getApigInfo=t012qy4XVe, getApigAuth=H7X7y9Wfc0
  774. // Note: FmodeParse SDK uses internal dispatch; direct REST call needs actual function name
  775. console.log('getApig returned no data, trying cloud function...');
  776. const cfFuncName = params.get('cfName') || 'getApigInfo';
  777. const cfResp = await parseCloudCall(cfFuncName, {
  778. apigId: authId
  779. }).catch(e => { console.warn('cloud function error:', e); return null; });
  780. console.log('Cloud function response:', cfResp);
  781. if (cfResp && cfResp.result) {
  782. const cfData = cfResp.result.data || cfResp.result;
  783. if (cfData && cfData.objectId) {
  784. apig = cfData;
  785. applyTestTier();
  786. renderApigInfo();
  787. renderTiers();
  788. loadOrderHistory();
  789. return;
  790. }
  791. }
  792. // 3. Fallback: accept APIG data from URL params (OpenClaw can pass these)
  793. const urlTitle = params.get('title');
  794. const urlPrices = params.get('prices');
  795. const urlCounts = params.get('counts');
  796. if (urlTitle && urlPrices && urlCounts) {
  797. console.log('Using APIG data from URL params');
  798. const prices = urlPrices.split(',').map(Number);
  799. const counts = urlCounts.split(',').map(Number);
  800. apig = {
  801. objectId: authId,
  802. title: urlTitle,
  803. content: params.get('desc') || '',
  804. count: parseInt(params.get('balance') || '0'),
  805. priceStep: prices.map((p, i) => ({ price: p, count: counts[i] || 0 }))
  806. };
  807. applyTestTier();
  808. renderApigInfo();
  809. renderTiers();
  810. loadOrderHistory();
  811. return;
  812. }
  813. showError('无法加载接口信息。请确认 authid 对应有效的 APIGAuth 记录,或通过 URL 参数传入套餐数据。');
  814. } catch (e) {
  815. showError('网络错误: ' + e.message);
  816. }
  817. }
  818. function applyTestTier() {
  819. if (params.get('test') === '1' && apig.priceStep) {
  820. apig.priceStep.unshift({ count: 1, price: 0.01 });
  821. }
  822. }
  823. function renderApigInfo() {
  824. const titleEl = document.getElementById('apiTitle');
  825. titleEl.innerHTML = apig.title + '<span class="badge">HTTPS</span>';
  826. const descEl = document.getElementById('apiDesc');
  827. descEl.textContent = apig.content || '专业API数据服务';
  828. const statsEl = document.getElementById('apiStats');
  829. statsEl.style.display = 'flex';
  830. document.getElementById('statCount').textContent =
  831. (apig.count != null ? apig.count + ' 次' : '—');
  832. document.getElementById('statStatus').textContent = '正常';
  833. document.getElementById('statStatus').style.color = 'var(--success)';
  834. }
  835. function renderTiers() {
  836. const grid = document.getElementById('tierGrid');
  837. if (!apig.priceStep || apig.priceStep.length === 0) {
  838. grid.innerHTML = '<div style="color:var(--text-dim);">暂无可用套餐</div>';
  839. return;
  840. }
  841. grid.innerHTML = '';
  842. apig.priceStep.forEach((tier, i) => {
  843. const card = document.createElement('div');
  844. card.className = 'tier-card neu-raised' + (i === 0 ? ' active' : '');
  845. const unitLabel = (apig.objectId === 'MYM5zJBKgw' || apig.objectId === 'FQtTgjcqIZ') ? 'token' : '次';
  846. const unitPrice = (tier.price / tier.count).toFixed(3);
  847. card.innerHTML = `
  848. <div class="tier-price"><span class="symbol">¥</span>${tier.price}</div>
  849. <div class="tier-count">含 ${tier.count} ${unitLabel}</div>
  850. <div class="tier-unit-price">≈ ${unitPrice} 元/${unitLabel}</div>
  851. `;
  852. card.addEventListener('click', () => selectTier(i));
  853. grid.appendChild(card);
  854. });
  855. selectTier(0);
  856. document.getElementById('payBtn').disabled = false;
  857. document.getElementById('payBtn').addEventListener('click', startPayment);
  858. }
  859. function selectTier(idx) {
  860. selectedIndex = idx;
  861. document.querySelectorAll('.tier-card').forEach((el, i) => {
  862. el.classList.toggle('active', i === idx);
  863. if (i === idx) {
  864. el.classList.remove('neu-raised');
  865. el.classList.add('neu-pressed');
  866. } else {
  867. el.classList.remove('neu-pressed');
  868. el.classList.add('neu-raised');
  869. }
  870. });
  871. const tier = apig.priceStep[idx];
  872. const unitLabel = (apig.objectId === 'MYM5zJBKgw' || apig.objectId === 'FQtTgjcqIZ') ? 'token' : '次';
  873. document.getElementById('summaryBar').style.display = 'flex';
  874. document.getElementById('summaryCount').textContent = tier.count + ' ' + unitLabel;
  875. document.getElementById('summaryPrice').textContent = tier.price;
  876. }
  877. // ─── Payment Flow ───
  878. async function startPayment() {
  879. const btn = document.getElementById('payBtn');
  880. btn.disabled = true;
  881. btn.textContent = '正在生成支付码...';
  882. hideError();
  883. try {
  884. // 1. Generate trade number
  885. const now = new Date();
  886. tradeNo = 'C' + (userId || 'U') +
  887. now.getFullYear() +
  888. String(now.getMonth() + 1).padStart(2, '0') +
  889. String(now.getDate()).padStart(2, '0') +
  890. String(now.getHours()).padStart(2, '0') +
  891. String(now.getMinutes()).padStart(2, '0') +
  892. String(now.getSeconds()).padStart(2, '0') +
  893. now.getMilliseconds();
  894. const tier = apig.priceStep[selectedIndex];
  895. // 2. Call pay_code2 to get QR URL
  896. const payResp = await postJSON(PARSE_BASE + '/pay_code2', {
  897. _ApplicationId: APP_ID,
  898. company: PAY_COMPANY,
  899. out_trade_no: tradeNo,
  900. total_fee: +tier.price,
  901. body: apig.title + ' 接口充值'
  902. });
  903. if (!payResp.result || !payResp.result.code_url) {
  904. throw new Error('获取支付码失败');
  905. }
  906. const codeUrl = payResp.result.code_url[0];
  907. nonceStr = payResp.result.nonce_str;
  908. // 3. Create order
  909. createOrder(tier);
  910. // 4. Show QR modal
  911. document.getElementById('modalPrice').textContent = tier.price;
  912. document.getElementById('qrModal').classList.add('show');
  913. document.getElementById('pollingStatus').innerHTML =
  914. '<span class="polling-dot"></span> 等待支付中...';
  915. // Generate QR code
  916. await renderQR(codeUrl);
  917. // 5. Start polling
  918. startPolling();
  919. } catch (e) {
  920. showError('支付发起失败: ' + e.message);
  921. } finally {
  922. btn.disabled = false;
  923. btn.innerHTML = '<span class="btn-icon">💳</span> 微信支付';
  924. }
  925. }
  926. async function createOrder(tier) {
  927. try {
  928. const body = {
  929. type: 'wxpay',
  930. authid: authId,
  931. params: {
  932. out_trade_no: tradeNo,
  933. total_fee: +tier.price,
  934. body: apig.title + ' 接口充值'
  935. },
  936. apigid: apig.objectId,
  937. oldCount: apig.count || 0,
  938. count: tier.count
  939. };
  940. // Server requires fcompany or user; fallback to authId if userId is empty
  941. body.user = userId || authId;
  942. body.fcompany = userId || authId;
  943. const resp = await postJSON(API_BASE + '/api/apig/created-apigorder', body);
  944. if (resp.code === 200 && resp.data) {
  945. order = resp.data;
  946. console.log('Order created:', order);
  947. }
  948. } catch (e) {
  949. console.warn('Order creation error (non-blocking):', e.message);
  950. }
  951. }
  952. function startPolling() {
  953. if (pollTimer) clearInterval(pollTimer);
  954. pollTimer = setInterval(async () => {
  955. try {
  956. const resp = await postJSON(PARSE_BASE + '/order_status2', {
  957. _ApplicationId: APP_ID,
  958. out_trade_no: tradeNo,
  959. nonce_str: nonceStr,
  960. company: PAY_COMPANY
  961. });
  962. if (resp.result && resp.result.status && resp.result.status[0] === 'SUCCESS') {
  963. clearInterval(pollTimer);
  964. pollTimer = null;
  965. document.getElementById('pollingStatus').innerHTML =
  966. '<span style="color:var(--success);">✓ 支付成功,正在充值...</span>';
  967. await doRecharge();
  968. }
  969. } catch (e) {
  970. console.warn('Poll error:', e.message);
  971. }
  972. }, 3000);
  973. }
  974. async function doRecharge() {
  975. // Show success first, then try recharge in background (saveRecharge may timeout)
  976. showSuccess();
  977. try {
  978. const tier = apig.priceStep[selectedIndex];
  979. // Build recharge body
  980. // authid = APIGAuth objectId (T0iOotHcDX)
  981. // apigid = APIG objectId from order or from getApig response
  982. const apigObjId = apig.objectId || authId;
  983. const body = {
  984. authid: authId,
  985. apigid: apigObjId,
  986. oldCount: apig.count || 0,
  987. count: tier.count,
  988. orderid: order ? order.objectId : ''
  989. };
  990. // Server requires fcompany or user; fallback to authId if userId is empty
  991. body.user = userId || authId;
  992. body.authComp = userId || authId;
  993. body.fcompany = userId || authId;
  994. console.log('saveRecharge body:', JSON.stringify(body));
  995. // Use AbortController for 15s timeout
  996. const controller = new AbortController();
  997. const timer = setTimeout(() => controller.abort(), 15000);
  998. const resp = await fetch(API_BASE + '/api/apig/saveRecharge', {
  999. method: 'POST',
  1000. headers: { 'Content-Type': 'application/json' },
  1001. body: JSON.stringify(body),
  1002. signal: controller.signal
  1003. });
  1004. clearTimeout(timer);
  1005. const result = await resp.json().catch(() => null);
  1006. console.log('saveRecharge response:', result);
  1007. // Refresh balance display
  1008. await refreshBalance();
  1009. } catch (e) {
  1010. console.warn('Recharge call failed (non-critical):', e.message);
  1011. }
  1012. // Refresh order history to show the new order
  1013. loadOrderHistory();
  1014. }
  1015. async function refreshBalance() {
  1016. try {
  1017. const resp = await postJSON(API_BASE + '/api/apig/getApig', { authid: authId });
  1018. if (resp.code === 200 && resp.data && resp.data.count != null) {
  1019. apig.count = resp.data.count;
  1020. const detail = document.getElementById('successDetail');
  1021. if (detail) {
  1022. const tier = apig.priceStep[selectedIndex];
  1023. const unitLabel = (apig.objectId === 'MYM5zJBKgw' || apig.objectId === 'FQtTgjcqIZ') ? 'token' : '次';
  1024. detail.innerHTML =
  1025. '已充值 <strong style="color:var(--neon);">' + apig.title + '</strong> 接口<br>' +
  1026. '获得 <strong style="color:var(--success);">' + tier.count + ' ' + unitLabel + '</strong>,有效期 730 天<br>' +
  1027. '<span style="color:var(--text-dim);margin-top:8px;display:inline-block;">当前余额: <strong style="color:var(--neon);">' + apig.count + ' ' + unitLabel + '</strong></span>';
  1028. }
  1029. console.log('Balance refreshed:', apig.count);
  1030. }
  1031. } catch(e) {
  1032. console.warn('Balance refresh failed:', e.message);
  1033. }
  1034. }
  1035. function showSuccess() {
  1036. document.getElementById('qrModal').classList.remove('show');
  1037. document.getElementById('mainContent').querySelector('.api-info-card').style.display = 'none';
  1038. document.querySelector('.section-title').style.display = 'none';
  1039. document.getElementById('tierGrid').style.display = 'none';
  1040. document.getElementById('summaryBar').style.display = 'none';
  1041. document.getElementById('payBtn').style.display = 'none';
  1042. const tier = apig.priceStep[selectedIndex];
  1043. const unitLabel = (apig.objectId === 'MYM5zJBKgw' || apig.objectId === 'FQtTgjcqIZ') ? 'token' : '次';
  1044. document.getElementById('successDetail').innerHTML =
  1045. '已充值 <strong style="color:var(--neon);">' + apig.title + '</strong> 接口<br>' +
  1046. '获得 <strong style="color:var(--success);">' + tier.count + ' ' + unitLabel + '</strong>,有效期 730 天';
  1047. document.getElementById('successScreen').classList.add('show');
  1048. }
  1049. async function renderQR(url) {
  1050. const wrapper = document.getElementById('qrWrapper');
  1051. const canvas = document.getElementById('qrCanvas');
  1052. // Clear previous QR (img fallback)
  1053. wrapper.querySelectorAll('img').forEach(i => i.remove());
  1054. canvas.style.display = '';
  1055. canvas.width = 200;
  1056. canvas.height = 200;
  1057. // Try canvas-based QRCode lib first
  1058. if (typeof QRCode !== 'undefined' && QRCode && QRCode.toCanvas) {
  1059. try {
  1060. await QRCode.toCanvas(canvas, url, {
  1061. width: 200,
  1062. margin: 0,
  1063. color: { dark: '#000000', light: '#ffffff' }
  1064. });
  1065. console.log('QR rendered via canvas');
  1066. return;
  1067. } catch (e) {
  1068. console.warn('QRCode.toCanvas failed:', e);
  1069. }
  1070. }
  1071. // Fallback: use img with QR server API
  1072. console.log('Using img fallback for QR');
  1073. canvas.style.display = 'none';
  1074. const img = document.createElement('img');
  1075. img.src = 'https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=' + encodeURIComponent(url);
  1076. img.width = 200;
  1077. img.height = 200;
  1078. img.alt = 'Payment QR Code';
  1079. img.style.display = 'block';
  1080. wrapper.appendChild(img);
  1081. }
  1082. function handleDone() {
  1083. // Notify parent window (OpenClaw integration)
  1084. try {
  1085. const msg = { type: 'apig-payment-done', authid: authId, user: userId };
  1086. if (window.opener) window.opener.postMessage(msg, '*');
  1087. if (window.parent !== window) window.parent.postMessage(msg, '*');
  1088. } catch(e) { console.warn('postMessage failed:', e); }
  1089. // Try to close window (works if opened via window.open)
  1090. try { window.close(); } catch(e) {}
  1091. setTimeout(() => {
  1092. // If still here, window.close didn't work — reload page
  1093. window.location.reload();
  1094. }, 500);
  1095. }
  1096. function cancelPayment() {
  1097. if (pollTimer) { clearInterval(pollTimer); pollTimer = null; }
  1098. document.getElementById('qrModal').classList.remove('show');
  1099. }
  1100. // ─── Order History ───
  1101. let orderSkip = 0;
  1102. const ORDER_PAGE_SIZE = 10;
  1103. async function loadOrderHistory(append) {
  1104. const container = document.getElementById('orderListBody');
  1105. const section = document.getElementById('orderHistory');
  1106. const refreshBtn = document.getElementById('refreshOrdersBtn');
  1107. section.style.display = '';
  1108. if (refreshBtn) refreshBtn.disabled = true;
  1109. if (!append) {
  1110. orderSkip = 0;
  1111. container.innerHTML = '<div class="order-loading"><span class="polling-dot"></span> 加载中...</div>';
  1112. }
  1113. try {
  1114. // Query APIGOrder class via Parse REST API
  1115. // Orders link to user via fromCompany/fromUser Pointer whose objectId = userId or authId
  1116. const userVal = userId || authId;
  1117. const where = JSON.stringify({
  1118. '$or': [
  1119. { fromCompany: { __type: 'Pointer', className: 'Company', objectId: userVal } },
  1120. { fromUser: { __type: 'Pointer', className: '_User', objectId: userVal } }
  1121. ]
  1122. });
  1123. const qs = new URLSearchParams({
  1124. where: where,
  1125. order: '-createdAt',
  1126. limit: String(ORDER_PAGE_SIZE),
  1127. skip: String(orderSkip)
  1128. });
  1129. const resp = await fetch(API_BASE + '/parse/classes/APIGOrder?' + qs.toString(), {
  1130. headers: {
  1131. 'X-Parse-Application-Id': APP_ID
  1132. }
  1133. });
  1134. if (!resp.ok) throw new Error('HTTP ' + resp.status);
  1135. const data = await resp.json();
  1136. const orders = data.results || [];
  1137. console.log('Order history loaded:', orders.length, 'skip:', orderSkip);
  1138. if (!append) {
  1139. if (orders.length === 0) {
  1140. container.innerHTML =
  1141. '<div class="order-empty">' +
  1142. '<svg width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2"/><rect x="9" y="3" width="6" height="4" rx="1"/></svg>' +
  1143. '暂无订单记录</div>';
  1144. if (refreshBtn) refreshBtn.disabled = false;
  1145. return;
  1146. }
  1147. container.innerHTML = '';
  1148. // Build table
  1149. const table = document.createElement('table');
  1150. table.className = 'order-table';
  1151. table.innerHTML =
  1152. '<thead><tr>' +
  1153. '<th>时间</th>' +
  1154. '<th>套餐</th>' +
  1155. '<th>金额</th>' +
  1156. '<th>状态</th>' +
  1157. '</tr></thead>';
  1158. const tbody = document.createElement('tbody');
  1159. tbody.id = 'orderTbody';
  1160. table.appendChild(tbody);
  1161. container.appendChild(table);
  1162. }
  1163. const tbody = document.getElementById('orderTbody');
  1164. orders.forEach(o => {
  1165. const tr = document.createElement('tr');
  1166. tr.innerHTML = formatOrderRow(o);
  1167. tbody.appendChild(tr);
  1168. });
  1169. // Remove old "load more" button
  1170. const oldMore = container.querySelector('.order-more-btn');
  1171. if (oldMore) oldMore.remove();
  1172. // Show "load more" if there might be more records
  1173. if (orders.length >= ORDER_PAGE_SIZE) {
  1174. orderSkip += ORDER_PAGE_SIZE;
  1175. const moreBtn = document.createElement('button');
  1176. moreBtn.className = 'order-more-btn';
  1177. moreBtn.textContent = '加载更多...';
  1178. moreBtn.onclick = () => loadOrderHistory(true);
  1179. container.appendChild(moreBtn);
  1180. }
  1181. } catch (e) {
  1182. console.warn('Order history error:', e);
  1183. if (!append) {
  1184. container.innerHTML =
  1185. '<div class="order-error">订单加载失败: ' + e.message + '</div>';
  1186. }
  1187. }
  1188. if (refreshBtn) refreshBtn.disabled = false;
  1189. }
  1190. function formatOrderRow(o) {
  1191. // Time
  1192. const dt = o.createdAt ? new Date(o.createdAt) : null;
  1193. const timeStr = dt
  1194. ? dt.getFullYear() + '-' +
  1195. String(dt.getMonth() + 1).padStart(2, '0') + '-' +
  1196. String(dt.getDate()).padStart(2, '0') + ' ' +
  1197. String(dt.getHours()).padStart(2, '0') + ':' +
  1198. String(dt.getMinutes()).padStart(2, '0')
  1199. : '—';
  1200. // Count — from detail.addCount or count field
  1201. const count = (o.detail && o.detail.addCount) || o.count || '—';
  1202. const unitLabel = (apig && (apig.objectId === 'MYM5zJBKgw' || apig.objectId === 'FQtTgjcqIZ')) ? 'token' : '次';
  1203. const countStr = count !== '—' ? count + ' ' + unitLabel : '—';
  1204. // Amount — from price field
  1205. const fee = o.price != null ? o.price : null;
  1206. const amountStr = fee != null ? '¥' + fee : '—';
  1207. // Status
  1208. const status = resolveOrderStatus(o);
  1209. return '<td class="col-time">' + timeStr + '</td>' +
  1210. '<td class="col-count">' + countStr + '</td>' +
  1211. '<td class="col-amount">' + amountStr + '</td>' +
  1212. '<td>' + status + '</td>';
  1213. }
  1214. function resolveOrderStatus(o) {
  1215. // isPay is the primary payment status flag in APIGOrder
  1216. if (o.isPay === true) {
  1217. // Check if recharge was applied (detail.oldCount exists and addCount exists)
  1218. if (o.detail && o.detail.addCount && o.detail.oldCount != null) {
  1219. return '<span class="order-status status-recharged">已充值</span>';
  1220. }
  1221. return '<span class="order-status status-paid">已支付</span>';
  1222. }
  1223. if (o.isPay === false) {
  1224. // Unpaid — check if expired (>30 min old)
  1225. const age = Date.now() - new Date(o.createdAt).getTime();
  1226. if (age > 30 * 60 * 1000) {
  1227. return '<span class="order-status status-failed">已过期</span>';
  1228. }
  1229. return '<span class="order-status status-pending">待支付</span>';
  1230. }
  1231. return '<span class="order-status status-pending">未知</span>';
  1232. }
  1233. // ─── Helpers ───
  1234. function showError(msg) {
  1235. const el = document.getElementById('errorBar');
  1236. if (!el) { console.error('errorBar not found:', msg); return; }
  1237. el.textContent = msg;
  1238. el.classList.add('show');
  1239. }
  1240. function hideError() {
  1241. const el = document.getElementById('errorBar');
  1242. if (el) el.classList.remove('show');
  1243. }
  1244. async function postJSON(url, data) {
  1245. const resp = await fetch(url, {
  1246. method: 'POST',
  1247. headers: { 'Content-Type': 'application/json' },
  1248. body: JSON.stringify(data)
  1249. });
  1250. return resp.json();
  1251. }
  1252. async function parseCloudCall(funcId, params) {
  1253. const url = PARSE_BASE + '/' + funcId;
  1254. const body = Object.assign({ _ApplicationId: APP_ID }, params);
  1255. const resp = await fetch(url, {
  1256. method: 'POST',
  1257. headers: {
  1258. 'Content-Type': 'application/json',
  1259. 'X-Parse-Application-Id': APP_ID
  1260. },
  1261. body: JSON.stringify(body)
  1262. });
  1263. if (!resp.ok) {
  1264. console.warn('Cloud function ' + funcId + ' returned ' + resp.status);
  1265. return null;
  1266. }
  1267. return resp.json();
  1268. }
  1269. </script>
  1270. </body>
  1271. </html>