代码拉取完成,页面将自动刷新
const express = require('express')
var request = require('request');
var fs = require('fs');
var path = require('path');
var bodyParser = require('body-parser');
var multer = require('multer');
var config = require('./api/config');
const email = require('./api/email.js')
const app = express();
app.use(express.static('dist'))
app.use(bodyParser.json());//数据JSON类型
app.use(bodyParser.urlencoded({ extended: false }));
app.all('*', function (req, res, next) {
if (req.path !== '/' && !req.path.includes('.')) {
res.header('Access-Control-Allow-Credentials', true)
// 这里获取 origin 请求头 而不是用 *
res.header('Access-Control-Allow-Origin', req.headers['origin'] || '*')
res.header("Access-Control-Allow-Headers", "x-access-token,x-access-type, Origin, X-Requested-With, Content-Type, Accept");
res.header('Access-Control-Allow-Methods', 'PUT,POST,GET,DELETE,OPTIONS')
res.header('Content-Type', 'application/json;charset=utf-8')
}
next()
});
app.get('/sendemail', function (req, res) {
var qq = req.query.qq;
email.send({ 'address': qq, type: true });
const response = {
message: 'Email send successfully',
filename: qq
};
res.end(JSON.stringify(response));
})
app.post('/sendmsg', function (req, res) {
var qq = req.body.qq;
var version = req.body.version;
var orderid = req.body.orderid;
var type = req.body.type;
var tenant = req.body.tenant || 0;
var tenantObj = config[tenant];
const url = 'https://oapi.dingtalk.com/robot/send?access_token=' + tenantObj.access_token
request({
url: url,
method: 'post',
json: true,
body: {
"msgtype": "markdown",
"markdown": {
title: version + '有新的订单哦',
"text": '### ' + orderid + ' \n' +
"- 用户QQ:" + qq + ' \n' +
"- 套餐类型:" + version + ' \n' +
"- 支付方式:" + type + ' \n' +
"- [订单链接](" + tenantObj.payList + ")"
},
"at": {
"isAtAll": true
}
}
}, async function (error, response, ) {
if (!error && response.statusCode == 200) {
const response = {
message: 'Email send successfully',
};
res.end(JSON.stringify(response));
}
});
})
app.post('/upload', multer({ dest: './file/' }).any(), function (req, res) {
const path = "./file/"
var des_file = path + req.files[0].originalname + '.jpg';
var qq = req.body.qq;
fs.readFile(req.files[0].path, function (err, data) {
fs.writeFile(des_file, data, function (err) {
if (!err) {
const response = {
message: 'File uploaded successfully',
filename: req.files[0].originalname
};
email.send({ 'address': qq, 'name': req.files[0].originalname });
res.end(JSON.stringify(response));
}
});
});
})
// 访问单页
app.get('/**', function (req, res) {
var html = fs.readFileSync(path.resolve(__dirname, './dist/index.html'), 'utf-8');
res.writeHead(200, {
'Content-Type': 'text/html'
});
res.write(html);
res.end();
});
app.listen(10001, () => console.log('Example app listening on port 10001!'))
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。