nodeJS搭建HTTP服务器

npm i express

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const CryptoJS = require('./crypto.js')
const express = require('express')
const app = express()
const port = 3000
app.use(express.json())

function getToken(player) {
let key = CryptoJS.enc.Utf8.parse("fipFfVsZsTda94hJNKJfLoaqyqMZFFimwLt");
const {name, birthday, height, weight} = player;
let base64Name = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(name));
let encrypted = CryptoJS.DES.encrypt(
`${base64Name}${birthday}${height}${weight}`,
key,
{
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7,
}
);
return encrypted.toString();
}

app.post("/", (req, res) => {
const data = req.body
res.send(getToken(data))
}
)

app.listen(port, () => {
})
1
2
3
4
5
6
7
8
9
10
11
12
import requests

item = {
'name': '凯文-杜兰特',
'image': 'durant.png',
'birthday': '1988-09-29',
'height': '208cm',
'weight': '108.9KG'
}

response = requests.post('http://localhost:3000', json=item)
print(response.text)
赏个🍗吧
0%