123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- // ROUTES FOR OUR API
- // =============================================================================
- var express = require("express");
- var request = require("request");
- var bcrypt = require("bcryptjs");
- let axios = require("axios");
- var router = express.Router(); // get an instance of the express Router
- const querystring = require("querystring");
- var mysql = require("./mysql");
- // const _mysqlLabor = ["123.58.32.151", "sc_app"]; //edu數據庫信息
- // const _mysqluser = ["123.58.32.151", "cocorobouser"]; //用户数据库信息
- const _mysqlLabor = ["172.16.12.5", "sc_app"]; // 提交的使用用这两个edu數據庫信息
- const _mysqluser = ["172.16.12.5", "cocorobouser"]; //edu數據庫信息
- var crypto = require("crypto");
- var https = require("https");
- let jwt = require("jsonwebtoken");
- let multer = require("multer");
- const wx = {
- appid: "wx1260af162664fd04", // 填写用户自己的appid
- secret: "9d399b3aa0a9e8bce68d20e7734b73e0", // 填写用户自己的密钥
- // appid: "wxcf19f82bc4ca3229", // 填写用户自己的appid
- // secret: "148b350f8bbd2daed7c2f75a8b4411aa", // 填写用户自己的密钥
- };
- //統壹處理區域
- 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
- });
- }
- /*測試*/
- 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"]);
- });
- router.route("/b").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "b", json["ph"], json["pa"]);
- });
- // yym获取微信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");
- });
- //yym登录接口
- 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,
- });
- });
- //yym查询是否注册过
- router.post("/selectUser", (req, res) => {
- console.log(req.body);
- // let { openid } = req.body;
- postmysql3(req, res, "Select_user");
- // console.log(res.end);
- });
- // yym更新头像昵称
- router.post("/updateUser", (req, res) => {
- // console.log(req.body);
- postmysql3(req, res, "update_User");
- });
- //yym上传活动
- router.post("/insertActive", (req, res) => {
- // console.log(req.body);
- postmysql3(req, res, "insert_activity");
- res.send({
- code: 200,
- msg: "上传成功",
- });
- });
- //yym 获取活动
- router.post("/selectActivity", (req, res) => {
- // console.log(req.body);
- postmysql3(req, res, "select_activity");
- });
- //yym 获取用户收藏信息
- router.post("/selectColl", (req, res) => {
- // console.log(req.body);
- postmysql3(req, res, "select_coll");
- });
- //yym 更新用户收藏信息
- router.post("/updateColl", (req, res) => {
- // console.log('更新用户收藏信息',req.body);
- postmysql3(req, res, "update_coll");
- });
- //获取用户订阅信息 xlh
- router.post("/selectSub", (req, res) => {
- postmysql3(req, res, "select_sub");
- });
- //更新用户订阅信息 xlh
- router.post("/updateSub", (req, res) => {
- postmysql3(req, res, "update_sub");
- });
- //lqh获取活动acid
- router.post("/selectActivityID", (req, res) => {
- postmysql3(req, res, "select_activityID");
- });
- //查询当前用户发布的活动 xlh
- router.post("/selectMyPublish", (req, res) => {
- postmysql3(req, res, "select_mypublish");
- });
- //更改当前用户发布的活动 xlh
- router.post("/updateMyPublish", (req, res) => {
- postmysql3(req, res, "update_mypublish");
- });
- //删除当前用户发布的活动 xlh
- router.post("/deleteMyPublish", (req, res) => {
- postmysql3(req, res, "delete_mypublish");
- });
- //查询当前的活动是否是当前的用户发布的 xlh
- router.post("/selectPublisher", (req, res) => {
- postmysql3(req, res, "select_activity_publisher");
- });
- //报名申请加入 zwb
- router.post("/insertActivityEnroll", (req, res) => {
- // console.log(req.body);
- postmysql3(req, res, "insert_activity_enroll");
- res.send({
- msg: "上传成功",
- });
- });
- // 查询我的活动 zwb
- router.post("/selectActivityEnroll", (req, res) => {
- postmysql3(req, res, "select_activity_enroll");
- });
- //查询用户是否报名 zwb
- router.post("/selectActivityEnrollid", (req, res) => {
- postmysql3(req, res, "select_activity_enroll_ID");
- });
- //查询全部活动
- router.route("/selectAct").all((req, res, next) => {
- var json = queryString(req.url);
- getmysql(req, res, "selectAct");
- });
- 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));
- });
- }
- };
- //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));
- });
- }
- };
- //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));
- });
- }
- };
- //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));
- }); //
- };
- //post存储过程处理
- userpostmysql = function (req, res, functionname) {
- //mode的处理
- if (req.body.mode) {
- p = req.body.mode.split(",");
- p.unshift(_mysqluser[0], _mysqluser[1], functionname);
- //执行存储过程
- mysql.usselect(p, function (ret) {
- res.end(JSON.stringify(ret));
- });
- }
- };
- //get获取数据库信息
- usergetmysql = function (req, res, functionname, ...p) {
- p = p || [];
- p.unshift(_mysqluser[0], _mysqluser[1], functionname);
- //执行存储过程
- mysql.usselect(p, function (ret) {
- res.end(JSON.stringify(ret));
- }); //
- };
- module.exports = router;
|