pbl.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. //yym 获取用户订阅数据(数组查询)
  136. router.post("/selectSubList", (req, res) => {
  137. console.log('获取',req.body);
  138. postmysql3(req, res, "select_subList");
  139. });
  140. //lqh获取活动acid
  141. router.post("/selectActivityID", (req, res) => {
  142. postmysql3(req, res, "select_activityID");
  143. });
  144. //查询当前用户发布的活动 xlh
  145. router.post("/selectMyPublish", (req, res) => {
  146. postmysql3(req, res, "select_mypublish");
  147. });
  148. //更改当前用户发布的活动 xlh
  149. router.post("/updateMyPublish", (req, res) => {
  150. postmysql3(req, res, "update_mypublish");
  151. });
  152. //删除当前用户发布的活动 xlh
  153. router.post("/deleteMyPublish", (req, res) => {
  154. postmysql3(req, res, "delete_mypublish");
  155. });
  156. //查询当前的活动是否是当前的用户发布的 xlh
  157. router.post("/selectPublisher", (req, res) => {
  158. postmysql3(req, res, "select_activity_publisher");
  159. });
  160. //报名申请加入 zwb
  161. router.post("/insertActivityEnroll", (req, res) => {
  162. // console.log(req.body);
  163. postmysql3(req, res, "insert_activity_enroll");
  164. res.send({
  165. msg: "上传成功",
  166. });
  167. });
  168. // 查询我的活动 zwb
  169. router.post("/selectActivityEnroll", (req, res) => {
  170. postmysql3(req, res, "select_activity_enroll");
  171. });
  172. //查询用户是否报名 zwb
  173. router.post("/selectActivityEnrollid", (req, res) => {
  174. postmysql3(req, res, "select_activity_enroll_ID");
  175. });
  176. //查询全部活动
  177. router.route("/selectAct").all((req, res, next) => {
  178. var json = queryString(req.url);
  179. getmysql(req, res, "selectAct");
  180. });
  181. queryString = function (url) {
  182. var a = url.split("?");
  183. var json = querystring.parse(a[1]);
  184. return json;
  185. };
  186. //post存儲過程處理
  187. postmysql = function (req, res, functionname) {
  188. //mode的處理
  189. if (req.body[0]) {
  190. p = Object.values(req.body[0]);
  191. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  192. //執行存儲過程
  193. mysql.usselect(p, function (ret) {
  194. res.end(JSON.stringify(ret));
  195. });
  196. }
  197. };
  198. //post存儲過程處理
  199. postmysql2 = function (req, res, functionname) {
  200. //mode的處理
  201. if (req.body) {
  202. p = Object.values(req.body)[0].split(",");
  203. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  204. //執行存儲過程
  205. mysql.usselect(p, function (ret) {
  206. res.end(JSON.stringify(ret));
  207. });
  208. }
  209. };
  210. //post存儲過程處理
  211. postmysql3 = function (req, res, functionname) {
  212. //mode的處理
  213. if (req.body) {
  214. p = Object.values(req.body);
  215. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  216. //執行存儲過程
  217. mysql.usselect(p, function (ret) {
  218. res.end(JSON.stringify(ret));
  219. });
  220. }
  221. };
  222. //get獲取數據庫信息
  223. getmysql = function (req, res, functionname, ...p) {
  224. p = p || [];
  225. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  226. //執行存儲過程
  227. mysql.usselect(p, function (ret) {
  228. res.end(JSON.stringify(ret));
  229. }); //
  230. };
  231. //post存储过程处理
  232. userpostmysql = function (req, res, functionname) {
  233. //mode的处理
  234. if (req.body.mode) {
  235. p = req.body.mode.split(",");
  236. p.unshift(_mysqluser[0], _mysqluser[1], functionname);
  237. //执行存储过程
  238. mysql.usselect(p, function (ret) {
  239. res.end(JSON.stringify(ret));
  240. });
  241. }
  242. };
  243. //get获取数据库信息
  244. usergetmysql = function (req, res, functionname, ...p) {
  245. p = p || [];
  246. p.unshift(_mysqluser[0], _mysqluser[1], functionname);
  247. //执行存储过程
  248. mysql.usselect(p, function (ret) {
  249. res.end(JSON.stringify(ret));
  250. }); //
  251. };
  252. module.exports = router;