pbl.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. // ROUTES FOR OUR API
  2. // =============================================================================
  3. var express = require("express");
  4. var request = require("request");
  5. var bcrypt = require("bcryptjs");
  6. let axios = require("axios");
  7. var router = express.Router(); // get an instance of the express Router
  8. const querystring = require("querystring");
  9. var mysql = require("./mysql");
  10. // const _mysqlLabor = ["123.58.32.151", "sc_app"]; //edu數據庫信息
  11. // const _mysqluser = ["123.58.32.151", "cocorobouser"]; //用户数据库信息
  12. const _mysqlLabor = ["172.16.12.5", "sc_app"]; // 提交的使用用这两个edu數據庫信息
  13. const _mysqluser = ["172.16.12.5", "cocorobouser"]; //edu數據庫信息
  14. var crypto = require("crypto");
  15. var https = require("https");
  16. let jwt = require("jsonwebtoken");
  17. let multer = require("multer");
  18. const wx = {
  19. appid: "wx1260af162664fd04", // 填写用户自己的appid
  20. secret: "9d399b3aa0a9e8bce68d20e7734b73e0", // 填写用户自己的密钥
  21. // appid: "wxcf19f82bc4ca3229", // 填写用户自己的appid
  22. // secret: "148b350f8bbd2daed7c2f75a8b4411aa", // 填写用户自己的密钥
  23. };
  24. //統壹處理區域
  25. router.use(async function (req, res, next) {
  26. await asynnext(req, res, next);
  27. //// make sure we go to the next routes and don't stop here
  28. //res.end("");
  29. });
  30. /**
  31. * @des 參數解釋同上
  32. */
  33. function asynnext(req, res, next) {
  34. //異步處理
  35. return new Promise(async (resolve, reject) => {
  36. next();
  37. //resolve(true);aa
  38. });
  39. }
  40. /*測試*/
  41. router.route("/a").all((req, res, next) => {
  42. res.send({
  43. msg: "成功",
  44. });
  45. return console.log(req.query);
  46. QMysql(req, res, "insert_user");
  47. var json = queryString(req.url);
  48. getmysql(req, res, "a", json["ph"], json["pa"]);
  49. });
  50. router.route("/b").all((req, res, next) => {
  51. var json = queryString(req.url);
  52. getmysql(req, res, "b", json["ph"], json["pa"]);
  53. });
  54. // yym获取微信openID
  55. router.get("/weChatCode", async (req, res) => {
  56. console.log(req.query);
  57. let response = await axios.get("https://api.weixin.qq.com/sns/jscode2session", {
  58. params: {
  59. appid: wx.appid,
  60. secret: wx.secret,
  61. js_code: req.query.codes,
  62. grant_type: "authorization_code",
  63. },
  64. });
  65. res.send(response.data.openid);
  66. // QMysql(req, res, "update_NewStatusById");
  67. });
  68. //yym登录接口
  69. router.post("/login", (req, res) => {
  70. // console.log(req.body);
  71. let { openid } = req.body;
  72. postmysql3(req, res, "insert_user");
  73. let token = jwt.sign({
  74. openid,
  75. },
  76. "secret", {
  77. expiresIn: "10s",
  78. }
  79. );
  80. res.send({
  81. code: 200,
  82. msg: "登录成功",
  83. token,
  84. });
  85. });
  86. //yym查询是否注册过
  87. router.post("/selectUser", (req, res) => {
  88. console.log(req.body);
  89. // let { openid } = req.body;
  90. postmysql3(req, res, "Select_user");
  91. // console.log(res.end);
  92. });
  93. // yym更新头像昵称
  94. router.post("/updateUser", (req, res) => {
  95. // console.log(req.body);
  96. postmysql3(req, res, "update_User");
  97. });
  98. //yym上传活动
  99. router.post("/insertActive", (req, res) => {
  100. // console.log(req.body);
  101. postmysql3(req, res, "insert_activity");
  102. res.send({
  103. code: 200,
  104. msg: "上传成功",
  105. });
  106. });
  107. //yym 获取活动
  108. router.post("/selectActivity", (req, res) => {
  109. // console.log(req.body);
  110. postmysql3(req, res, "select_activity");
  111. });
  112. //yym 获取用户收藏信息
  113. router.post("/selectColl", (req, res) => {
  114. console.log(req.body);
  115. postmysql3(req, res, "select_coll");
  116. });
  117. //yym 更新用户收藏信息
  118. router.post("/updateColl", (req, res) => {
  119. // console.log('更新用户收藏信息',req.body);
  120. postmysql3(req, res, "update_coll");
  121. });
  122. //获取用户订阅信息 xlh
  123. router.post("/selectSub", (req, res) => {
  124. postmysql3(req, res, "select_sub");
  125. });
  126. //更新用户订阅信息 xlh
  127. router.post("/updateSub", (req, res) => {
  128. postmysql3(req, res, "update_sub");
  129. });
  130. //yym 获取用户收藏数据(数组查询)
  131. router.post("/selectCollList", (req, res) => {
  132. console.log('获取',req.body);
  133. postmysql3(req, res, "select_collList");
  134. });
  135. //lqh获取活动acid
  136. router.post("/selectActivityID", (req, res) => {
  137. postmysql3(req, res, "select_activityID");
  138. });
  139. //查询当前用户发布的活动 xlh
  140. router.post("/selectMyPublish", (req, res) => {
  141. postmysql3(req, res, "select_mypublish");
  142. });
  143. //更改当前用户发布的活动 xlh
  144. router.post("/updateMyPublish", (req, res) => {
  145. postmysql3(req, res, "update_mypublish");
  146. });
  147. //删除当前用户发布的活动 xlh
  148. router.post("/deleteMyPublish", (req, res) => {
  149. postmysql3(req, res, "delete_mypublish");
  150. });
  151. //查询当前的活动是否是当前的用户发布的 xlh
  152. router.post("/selectPublisher", (req, res) => {
  153. postmysql3(req, res, "select_activity_publisher");
  154. });
  155. //报名申请加入 zwb
  156. router.post("/insertActivityEnroll", (req, res) => {
  157. // console.log(req.body);
  158. postmysql3(req, res, "insert_activity_enroll");
  159. res.send({
  160. msg: "上传成功",
  161. });
  162. });
  163. // 查询我的活动 zwb
  164. router.post("/selectActivityEnroll", (req, res) => {
  165. postmysql3(req, res, "select_activity_enroll");
  166. });
  167. //查询用户是否报名 zwb
  168. router.post("/selectActivityEnrollid", (req, res) => {
  169. postmysql3(req, res, "select_activity_enroll_ID");
  170. });
  171. //查询全部活动
  172. router.route("/selectAct").all((req, res, next) => {
  173. var json = queryString(req.url);
  174. getmysql(req, res, "selectAct");
  175. });
  176. queryString = function (url) {
  177. var a = url.split("?");
  178. var json = querystring.parse(a[1]);
  179. return json;
  180. };
  181. //post存儲過程處理
  182. postmysql = function (req, res, functionname) {
  183. //mode的處理
  184. if (req.body[0]) {
  185. p = Object.values(req.body[0]);
  186. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  187. //執行存儲過程
  188. mysql.usselect(p, function (ret) {
  189. res.end(JSON.stringify(ret));
  190. });
  191. }
  192. };
  193. //post存儲過程處理
  194. postmysql2 = function (req, res, functionname) {
  195. //mode的處理
  196. if (req.body) {
  197. p = Object.values(req.body)[0].split(",");
  198. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  199. //執行存儲過程
  200. mysql.usselect(p, function (ret) {
  201. res.end(JSON.stringify(ret));
  202. });
  203. }
  204. };
  205. //post存儲過程處理
  206. postmysql3 = function (req, res, functionname) {
  207. //mode的處理
  208. if (req.body) {
  209. p = Object.values(req.body);
  210. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  211. //執行存儲過程
  212. mysql.usselect(p, function (ret) {
  213. res.end(JSON.stringify(ret));
  214. });
  215. }
  216. };
  217. //get獲取數據庫信息
  218. getmysql = function (req, res, functionname, ...p) {
  219. p = p || [];
  220. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  221. //執行存儲過程
  222. mysql.usselect(p, function (ret) {
  223. res.end(JSON.stringify(ret));
  224. }); //
  225. };
  226. //post存储过程处理
  227. userpostmysql = function (req, res, functionname) {
  228. //mode的处理
  229. if (req.body.mode) {
  230. p = req.body.mode.split(",");
  231. p.unshift(_mysqluser[0], _mysqluser[1], functionname);
  232. //执行存储过程
  233. mysql.usselect(p, function (ret) {
  234. res.end(JSON.stringify(ret));
  235. });
  236. }
  237. };
  238. //get获取数据库信息
  239. usergetmysql = function (req, res, functionname, ...p) {
  240. p = p || [];
  241. p.unshift(_mysqluser[0], _mysqluser[1], functionname);
  242. //执行存储过程
  243. mysql.usselect(p, function (ret) {
  244. res.end(JSON.stringify(ret));
  245. }); //
  246. };
  247. module.exports = router;