Created
November 19, 2019 07:37
-
-
Save yknext/2f41609f0abf3ccb2e610077497e7706 to your computer and use it in GitHub Desktop.
天猫精灵测试
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//天猫精灵自定义技能,树莓派 | |
var express = require('express') | |
var bodyParser = require('body-parser') | |
var NodeRSA = require('node-rsa') | |
var fs = require('fs') | |
var publicKey = new NodeRSA(fs.readFileSync(__dirname+'/public_key.pem').toString('ascii')); | |
var privateKey = new NodeRSA(fs.readFileSync(__dirname+'/private_key.pem').toString('ascii')); | |
publicKey.setOptions({encryptionScheme: 'pkcs1'}) | |
privateKey.setOptions({encryptionScheme: 'pkcs1'}) | |
function encryptData(data){ | |
return publicKey.encrypt(data, 'base64') | |
} | |
function decryptData(encodeData){ | |
return privateKey.decrypt(encodeData, 'utf8'); | |
} | |
var app = express() | |
// create application/json parser | |
var jsonParser = bodyParser.json() | |
// create application/x-www-form-urlencoded parser | |
var urlencodedParser = bodyParser.urlencoded({ extended: false }) | |
app.get('/aligenie_ac/',function(req,res){ | |
res.send('Hello man'); | |
}); | |
// POST /login gets urlencoded bodies | |
app.post('/login', urlencodedParser, function (req, res) { | |
res.send('welcome, ' + req.body.username) | |
}) | |
// POST /api/users gets JSON bodies | |
app.post('/aligenie_ac/bot.json', jsonParser, function (req, res) { | |
console.log(req.body); | |
var request = req.body; | |
var enc = false; | |
try{ | |
if(req.body.securityQuery){ | |
request = JSON.parse(decryptData(req.body.securityQuery)); | |
enc = true; | |
} | |
} | |
catch(e){ | |
console.log(e); | |
} | |
console.log(request); | |
var result = {}; | |
result.returnCode = '0'; | |
var returnValue = {}; | |
returnValue.reply = '执行成功'; | |
returnValue.resultType = 'RESULT'; | |
returnValue.executeCode = 'SUCCESS'; | |
result.returnValue = returnValue; | |
res.send(JSON.stringify(result)); | |
}) | |
app.listen(2009); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment