|
@@ -17,108 +17,107 @@ var crypto = require("crypto");
|
|
|
var https = require("https");
|
|
|
let jwt = require("jsonwebtoken");
|
|
|
|
|
|
-let multer=require("multer");
|
|
|
+let multer = require("multer");
|
|
|
|
|
|
const wx = {
|
|
|
- appid: "wx1260af162664fd04", // 填写用户自己的appid
|
|
|
- secret: "9d399b3aa0a9e8bce68d20e7734b73e0", // 填写用户自己的密钥
|
|
|
+ appid: "wx1260af162664fd04", // 填写用户自己的appid
|
|
|
+ secret: "9d399b3aa0a9e8bce68d20e7734b73e0", // 填写用户自己的密钥
|
|
|
};
|
|
|
//統壹處理區域
|
|
|
-router.use(async function (req, res, next) {
|
|
|
- await asynnext(req, res, next);
|
|
|
- //// make sure we go to the next routes and don't stop here
|
|
|
- //res.end("");
|
|
|
+router.use(async function(req, res, next) {
|
|
|
+ await asynnext(req, res, next);
|
|
|
+ //// make sure we go to the next routes and don't stop here
|
|
|
+ //res.end("");
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* @des 參數解釋同上
|
|
|
*/
|
|
|
function asynnext(req, res, next) {
|
|
|
- //異步處理
|
|
|
- return new Promise(async (resolve, reject) => {
|
|
|
- next();
|
|
|
- //resolve(true);aa
|
|
|
- });
|
|
|
+ //異步處理
|
|
|
+ return new Promise(async(resolve, reject) => {
|
|
|
+ next();
|
|
|
+ //resolve(true);aa
|
|
|
+ });
|
|
|
}
|
|
|
/*測試*/
|
|
|
router.route("/a").all((req, res, next) => {
|
|
|
- res.send(
|
|
|
- {
|
|
|
- msg: "成功",
|
|
|
- }
|
|
|
- );
|
|
|
- return console.log(req.query);
|
|
|
- QMysql(req, res, "insert_user");
|
|
|
- var json = queryString(req.url);
|
|
|
- getmysql(req, res, "a", json["ph"], json["pa"]);
|
|
|
+ res.send({
|
|
|
+ msg: "成功",
|
|
|
+ });
|
|
|
+ return console.log(req.query);
|
|
|
+ QMysql(req, res, "insert_user");
|
|
|
+ var json = queryString(req.url);
|
|
|
+ getmysql(req, res, "a", json["ph"], json["pa"]);
|
|
|
});
|
|
|
router.route("/b").all((req, res, next) => {
|
|
|
- var json = queryString(req.url);
|
|
|
- getmysql(req, res, "b", json["ph"], json["pa"]);
|
|
|
+ var json = queryString(req.url);
|
|
|
+ getmysql(req, res, "b", json["ph"], json["pa"]);
|
|
|
});
|
|
|
|
|
|
// 获取微信openID
|
|
|
-router.get("/weChatCode",async (req, res) => {
|
|
|
- console.log(req.query);
|
|
|
- let response = await axios.get("https://api.weixin.qq.com/sns/jscode2session", {
|
|
|
- params: {
|
|
|
- appid: wx.appid,
|
|
|
- secret: wx.secret,
|
|
|
- js_code: req.query.codes,
|
|
|
- grant_type: "authorization_code",
|
|
|
- },
|
|
|
- });
|
|
|
- res.send(response.data.openid);
|
|
|
- // QMysql(req, res, "update_NewStatusById");
|
|
|
+router.get("/weChatCode", async(req, res) => {
|
|
|
+ console.log(req.query);
|
|
|
+ let response = await axios.get("https://api.weixin.qq.com/sns/jscode2session", {
|
|
|
+ params: {
|
|
|
+ appid: wx.appid,
|
|
|
+ secret: wx.secret,
|
|
|
+ js_code: req.query.codes,
|
|
|
+ grant_type: "authorization_code",
|
|
|
+ },
|
|
|
+ });
|
|
|
+ res.send(response.data.openid);
|
|
|
+ // QMysql(req, res, "update_NewStatusById");
|
|
|
});
|
|
|
|
|
|
//登录接口
|
|
|
router.post("/login", (req, res) => {
|
|
|
- console.log(req.body);
|
|
|
- let {openid}=req.body;
|
|
|
- postmysql3(req, res, "insert_user");
|
|
|
- let token = jwt.sign(
|
|
|
- {
|
|
|
- openid,
|
|
|
- },
|
|
|
- "secret",
|
|
|
- {
|
|
|
- expiresIn: "10s",
|
|
|
- }
|
|
|
- );
|
|
|
- res.send(
|
|
|
- {
|
|
|
- code: 200,
|
|
|
- msg: "登录成功",
|
|
|
- token,
|
|
|
- }
|
|
|
- );
|
|
|
+ console.log(req.body);
|
|
|
+ let { openid } = req.body;
|
|
|
+ postmysql3(req, res, "insert_user");
|
|
|
+ let token = jwt.sign({
|
|
|
+ openid,
|
|
|
+ },
|
|
|
+ "secret", {
|
|
|
+ expiresIn: "10s",
|
|
|
+ }
|
|
|
+ );
|
|
|
+ res.send({
|
|
|
+ code: 200,
|
|
|
+ msg: "登录成功",
|
|
|
+ token,
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
//查询是否注册过
|
|
|
router.post("/selectUser", (req, res) => {
|
|
|
- console.log(req.body);
|
|
|
- let {openid}=req.body;
|
|
|
- postmysql3(req, res, "Select_user");
|
|
|
+ console.log(req.body);
|
|
|
+ let { openid } = req.body;
|
|
|
+ postmysql3(req, res, "Select_user");
|
|
|
});
|
|
|
|
|
|
//上传活动
|
|
|
router.post("/insertActive", (req, res) => {
|
|
|
- console.log(req.body);
|
|
|
- postmysql3(req, res, "insert_activity");
|
|
|
+ console.log(req.body);
|
|
|
+ postmysql3(req, res, "insert_activity");
|
|
|
|
|
|
- res.send({
|
|
|
- code: 200,
|
|
|
- msg: "上传成功",
|
|
|
- });
|
|
|
+ res.send({
|
|
|
+ code: 200,
|
|
|
+ msg: "上传成功",
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
//获取活动
|
|
|
router.post("/selectActivity", (req, res) => {
|
|
|
- console.log(req.body);
|
|
|
- postmysql3(req, res, "select_activity");
|
|
|
+ console.log(req.body);
|
|
|
+ postmysql3(req, res, "select_activity");
|
|
|
});
|
|
|
|
|
|
+//查询全部活动
|
|
|
+router.route("/selectAct").all((req, res, next) => {
|
|
|
+ var json = queryString(req.url);
|
|
|
+ getmysql(req, res, "selectAct");
|
|
|
+});
|
|
|
|
|
|
|
|
|
|
|
@@ -126,91 +125,91 @@ router.post("/selectActivity", (req, res) => {
|
|
|
|
|
|
|
|
|
|
|
|
-queryString = function (url) {
|
|
|
- var a = url.split("?");
|
|
|
- var json = querystring.parse(a[1]);
|
|
|
- return json;
|
|
|
+queryString = function(url) {
|
|
|
+ var a = url.split("?");
|
|
|
+ var json = querystring.parse(a[1]);
|
|
|
+ return json;
|
|
|
};
|
|
|
|
|
|
//post存儲過程處理
|
|
|
-postmysql = function (req, res, functionname) {
|
|
|
- //mode的處理
|
|
|
- if (req.body[0]) {
|
|
|
- p = Object.values(req.body[0]);
|
|
|
- p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
|
|
|
- //執行存儲過程
|
|
|
- mysql.usselect(p, function (ret) {
|
|
|
- res.end(JSON.stringify(ret));
|
|
|
- });
|
|
|
- }
|
|
|
+postmysql = function(req, res, functionname) {
|
|
|
+ //mode的處理
|
|
|
+ if (req.body[0]) {
|
|
|
+ p = Object.values(req.body[0]);
|
|
|
+ p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
|
|
|
+ //執行存儲過程
|
|
|
+ mysql.usselect(p, function(ret) {
|
|
|
+ res.end(JSON.stringify(ret));
|
|
|
+ });
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
//post存儲過程處理
|
|
|
-postmysql2 = function (req, res, functionname) {
|
|
|
- //mode的處理
|
|
|
- if (req.body) {
|
|
|
- p = Object.values(req.body)[0].split(",");
|
|
|
- p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
|
|
|
- //執行存儲過程
|
|
|
- mysql.usselect(p, function (ret) {
|
|
|
- res.end(JSON.stringify(ret));
|
|
|
- });
|
|
|
- }
|
|
|
+postmysql2 = function(req, res, functionname) {
|
|
|
+ //mode的處理
|
|
|
+ if (req.body) {
|
|
|
+ p = Object.values(req.body)[0].split(",");
|
|
|
+ p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
|
|
|
+ //執行存儲過程
|
|
|
+ mysql.usselect(p, function(ret) {
|
|
|
+ res.end(JSON.stringify(ret));
|
|
|
+ });
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
//post存儲過程處理
|
|
|
-postmysql3 = function (req, res, functionname) {
|
|
|
- //mode的處理
|
|
|
- if (req.body) {
|
|
|
- p = Object.values(req.body);
|
|
|
- p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
|
|
|
- //執行存儲過程
|
|
|
- mysql.usselect(p, function (ret) {
|
|
|
- res.end(JSON.stringify(ret));
|
|
|
- });
|
|
|
- }
|
|
|
+postmysql3 = function(req, res, functionname) {
|
|
|
+ //mode的處理
|
|
|
+ if (req.body) {
|
|
|
+ p = Object.values(req.body);
|
|
|
+ p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
|
|
|
+ //執行存儲過程
|
|
|
+ mysql.usselect(p, function(ret) {
|
|
|
+ res.end(JSON.stringify(ret));
|
|
|
+ });
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
//get獲取數據庫信息
|
|
|
-getmysql = function (req, res, functionname, ...p) {
|
|
|
- p = p || [];
|
|
|
- p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
|
|
|
- //執行存儲過程
|
|
|
- mysql.usselect(p, function (ret) {
|
|
|
- res.end(JSON.stringify(ret));
|
|
|
- }); //
|
|
|
+getmysql = function(req, res, functionname, ...p) {
|
|
|
+ p = p || [];
|
|
|
+ p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
|
|
|
+ //執行存儲過程
|
|
|
+ mysql.usselect(p, function(ret) {
|
|
|
+ res.end(JSON.stringify(ret));
|
|
|
+ }); //
|
|
|
};
|
|
|
|
|
|
//post存储过程处理
|
|
|
|
|
|
-userpostmysql = function (req, res, functionname) {
|
|
|
- //mode的处理
|
|
|
+userpostmysql = function(req, res, functionname) {
|
|
|
+ //mode的处理
|
|
|
|
|
|
- if (req.body.mode) {
|
|
|
- p = req.body.mode.split(",");
|
|
|
+ if (req.body.mode) {
|
|
|
+ p = req.body.mode.split(",");
|
|
|
|
|
|
- p.unshift(_mysqluser[0], _mysqluser[1], functionname);
|
|
|
+ p.unshift(_mysqluser[0], _mysqluser[1], functionname);
|
|
|
|
|
|
- //执行存储过程
|
|
|
+ //执行存储过程
|
|
|
|
|
|
- mysql.usselect(p, function (ret) {
|
|
|
- res.end(JSON.stringify(ret));
|
|
|
- });
|
|
|
- }
|
|
|
+ mysql.usselect(p, function(ret) {
|
|
|
+ res.end(JSON.stringify(ret));
|
|
|
+ });
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
//get获取数据库信息
|
|
|
|
|
|
-usergetmysql = function (req, res, functionname, ...p) {
|
|
|
- p = p || [];
|
|
|
+usergetmysql = function(req, res, functionname, ...p) {
|
|
|
+ p = p || [];
|
|
|
|
|
|
- p.unshift(_mysqluser[0], _mysqluser[1], functionname);
|
|
|
+ p.unshift(_mysqluser[0], _mysqluser[1], functionname);
|
|
|
|
|
|
- //执行存储过程
|
|
|
+ //执行存储过程
|
|
|
|
|
|
- mysql.usselect(p, function (ret) {
|
|
|
- res.end(JSON.stringify(ret));
|
|
|
- }); //
|
|
|
+ mysql.usselect(p, function(ret) {
|
|
|
+ res.end(JSON.stringify(ret));
|
|
|
+ }); //
|
|
|
};
|
|
|
|
|
|
-module.exports = router;
|
|
|
+module.exports = router;
|