const express=require("express"); const axios=require("axios"); const app=express(); app.use(express.json()); const username="1332871995"; const password="qwe12355"; const appId=1; let apikey=""; //获取apikey async function getApiKey(){ if(apikey) return apikey; let res = await axios.get( "http://app.51juzi.xyz/api/apikey", { params:{ username, password } } ); apikey = res.data.apikey; return apikey; } //HTML调用接口 app.post( "/api/getCode", async(req,res)=>{ try{ let key = await getApiKey(); let result = await axios.get( "http://app.51juzi.xyz/api/auth", { params:{ apikey:key, appId:appId, qrCode: req.body.qrCode, grade:1, type:1, model:1 } } ); res.json( result.data ); }catch(e){ res.json({ error:e.message }); } }); app.use( express.static("public") ); app.listen( 3000, ()=>{ console.log( "server start 3000" ); });