pbl.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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 = ["127.0.0.1", "sc_app"]; //袁一鸣
  13. // const _mysqlLabor = ["10.3.13.84", "sc_app"]; //袁一鸣
  14. const _mysqlLabor = ["172.16.12.5", "sc_app"]; // 提交的使用用这两个edu數據庫信息
  15. // const _mysqluser = ["172.16.12.5", "cocorobouser"]; //edu數據庫信息
  16. var crypto = require("crypto");
  17. var https = require("https");
  18. let jwt = require("jsonwebtoken");
  19. let multer = require("multer");
  20. const wx = {
  21. appid: "wx1260af162664fd04", // 填写用户自己的appid
  22. secret: "9d399b3aa0a9e8bce68d20e7734b73e0", // 填写用户自己的密钥
  23. // appid: "wxcf19f82bc4ca3229", // lqh
  24. // secret: "148b350f8bbd2daed7c2f75a8b4411aa", // 填写用户自己的密钥
  25. };
  26. //統壹處理區域
  27. router.use(async function (req, res, next) {
  28. await asynnext(req, res, next);
  29. //// make sure we go to the next routes and don't stop here
  30. //res.end("");
  31. });
  32. /**
  33. * @des 參數解釋同上
  34. */
  35. function asynnext(req, res, next) {
  36. //異步處理
  37. return new Promise(async (resolve, reject) => {
  38. next();
  39. //resolve(true);aa
  40. });
  41. }
  42. /*測試*/
  43. router.route("/a").all((req, res, next) => {
  44. res.send({
  45. msg: "成功",
  46. });
  47. return console.log(req.query);
  48. QMysql(req, res, "insert_user");
  49. var json = queryString(req.url);
  50. getmysql(req, res, "a", json["ph"], json["pa"]);
  51. });
  52. router.route("/b").all((req, res, next) => {
  53. var json = queryString(req.url);
  54. getmysql(req, res, "b", json["ph"], json["pa"]);
  55. });
  56. // yym获取微信openID
  57. router.get("/weChatCode", async (req, res) => {
  58. console.log(req.query);
  59. let response = await axios.get(
  60. "https://api.weixin.qq.com/sns/jscode2session",
  61. {
  62. params: {
  63. appid: wx.appid,
  64. secret: wx.secret,
  65. js_code: req.query.codes,
  66. grant_type: "authorization_code",
  67. },
  68. }
  69. );
  70. // console.log(response.data);
  71. res.send(response.data.openid);
  72. // QMysql(req, res, "update_NewStatusById");
  73. });
  74. //yym注册接口
  75. router.post("/login", (req, res) => {
  76. postmysql3(req, res, "insert_user");
  77. });
  78. //yym查询用户(查询是否注册过)
  79. router.post("/selectUser", (req, res) => {
  80. // console.log(req.body);
  81. // let { openid } = req.body;
  82. postmysql3(req, res, "Select_user");
  83. // console.log(res.end);
  84. });
  85. // yym更新头像昵称
  86. router.post("/updateUser", (req, res) => {
  87. // console.log(req.body);
  88. postmysql3(req, res, "update_User");
  89. });
  90. //yym上传活动
  91. router.post("/insertActive", (req, res) => {
  92. // console.log(req.body);
  93. postmysql3(req, res, "insert_activity");
  94. // res.send({
  95. // code: 200,
  96. // msg: "上传成功",
  97. // });
  98. });
  99. //yym 获取活动
  100. router.post("/selectActivity", (req, res) => {
  101. // console.log(req.body);
  102. postmysql3(req, res, "select_activity");
  103. });
  104. //yym 获取用户收藏信息
  105. router.post("/selectColl", (req, res) => {
  106. // console.log(req.body);
  107. postmysql3(req, res, "select_coll");
  108. });
  109. //yym 更新用户收藏信息
  110. router.post("/updateColl", (req, res) => {
  111. // console.log('更新用户收藏信息',req.body);
  112. postmysql3(req, res, "update_coll");
  113. });
  114. //获取用户订阅信息 xlh
  115. router.post("/selectSub", (req, res) => {
  116. postmysql3(req, res, "select_sub");
  117. });
  118. //更新用户订阅信息 xlh
  119. router.post("/updateSub", (req, res) => {
  120. postmysql3(req, res, "update_sub");
  121. });
  122. //yym 获取用户收藏数据(数组查询) 废弃
  123. router.post("/selectCollList", (req, res) => {
  124. // console.log('获取',req.body);
  125. postmysql3(req, res, "select_collList");
  126. });
  127. //yym 获取用户订阅数据(数组查询) 废弃
  128. router.post("/selectSubList", (req, res) => {
  129. // console.log('获取',req.body);
  130. postmysql3(req, res, "select_subList");
  131. });
  132. //yym 获取用户信息
  133. router.post("/selectUserInfo", (req, res) => {
  134. // console.log('获取',req.body);
  135. postmysql3(req, res, "select_UserInfo");
  136. });
  137. //yym 更新用户信息
  138. router.post("/updateUserInfo", (req, res) => {
  139. // console.log("获取用户信息", req.body);
  140. postmysql3(req, res, "update_userInfo");
  141. });
  142. //yym 用户报名收藏等操作 0收藏 1订阅 2报名
  143. router.post("/insertOperator", (req, res) => {
  144. // console.log('获取',req.body);
  145. postmysql3(req, res, "insert_operator");
  146. });
  147. //yym 查询用户全部报名收藏 0收藏 1订阅 2报名
  148. router.post("/selectOperator", (req, res) => {
  149. // console.log('获取',req.body);
  150. postmysql3(req, res, "select_operator");
  151. });
  152. //yym 查询用户 单个 报名收藏
  153. router.post("/selectOneOperator", (req, res) => {
  154. // console.log('获取',req.body);
  155. postmysql3(req, res, "select_oneOperator");
  156. });
  157. //yym 删除用户收藏或订阅
  158. router.post("/deleteOperator", (req, res) => {
  159. // console.log('获取',req.body);
  160. postmysql3(req, res, "delete_Operator");
  161. });
  162. //yym 我的发布页面获取要修改的活动数据
  163. router.post("/selectAmendAct", (req, res) => {
  164. // console.log('获取',req.body);
  165. postmysql3(req, res, "select_amendAct");
  166. });
  167. //yym 获取活动详情页面是否收藏订阅报名
  168. router.post("/selectSignup", (req, res) => {
  169. // console.log('获取',req.body);
  170. postmysql3(req, res, "select_signup");
  171. });
  172. //yym 报名活动
  173. router.post("/insertSignup", (req, res) => {
  174. // console.log('获取',req.body);
  175. postmysql3(req, res, "insert_Signup");
  176. });
  177. //yym 做最后判断防止同一时间进入报名页面都报名成功
  178. router.post("/selectIntercept", (req, res) => {
  179. // console.log('获取',req.body);
  180. postmysql3(req, res, "select_intercept");
  181. });
  182. //yym 获取活动报名人
  183. router.post("/selectApplyUser", (req, res) => {
  184. // console.log('获取',req.body);
  185. postmysql3(req, res, "select_applyUser");
  186. });
  187. //yym 添加活动通知
  188. router.post("/insertMessage", (req, res) => {
  189. // console.log('获取',req.body);
  190. postmysql3(req, res, "insert_message");
  191. });
  192. //yym 信息列表查询信息
  193. router.post("/selectMessage", (req, res) => {
  194. // console.log('获取',req.body);
  195. postmysql3(req, res, "select_message");
  196. });
  197. //yym 查询所有未读信息
  198. router.post("/selectAllMessage", (req, res) => {
  199. // console.log('获取',req.body);
  200. postmysql3(req, res, "select_allMessage");
  201. });
  202. //yym 信息页面分组查询未读信息
  203. router.post("/selectGroupMessage", (req, res) => {
  204. // console.log('获取',req.body);
  205. postmysql3(req, res, "select_groupMessage");
  206. });
  207. //yym 更新未读信息
  208. router.post("/updateIsRead", (req, res) => {
  209. // console.log("获取", req.body);
  210. postmysql3(req, res, "update_isRead");
  211. });
  212. //yym 我的页面,我的收藏活动列表
  213. router.post("/selectCollAcList", (req, res) => {
  214. // console.log("获取", req.body);
  215. postmysql3(req, res, "select_collAcList");
  216. });
  217. //yym 我的页面,我的收藏课程列表
  218. router.post("/selectCollClassList", (req, res) => {
  219. // console.log("获取", req.body);
  220. postmysql3(req, res, "select_collClassList");
  221. });
  222. //yym 获取资源库
  223. router.post("/selectResource", (req, res) => {
  224. // console.log("获取", req.body);
  225. postmysql3(req, res, "select_resource");
  226. });
  227. //yym 获取精品慕课
  228. router.post("/selectJTeach", (req, res) => {
  229. // console.log("获取", req.body);
  230. postmysql3(req, res, "select_jTeach");
  231. });
  232. //yym 获取课程
  233. router.post("/selectOperatorTech", (req, res) => {
  234. // console.log("获取", req.body);
  235. postmysql3(req, res, "select_operatorTech");
  236. });
  237. //yym 获取我的消息,未读红点所填数据
  238. router.post("/selectUnreadMsg", (req, res) => {
  239. // console.log("获取", req.body);
  240. postmysql3(req, res, "select_unreadMsg");
  241. });
  242. //yym 单个点击信息变已读
  243. router.post("/updateOneIsRead", (req, res) => {
  244. // console.log("获取", req.body);
  245. postmysql3(req, res, "update_oneIsRead");
  246. });
  247. //yym 我的活动-获取已报名数据
  248. router.post("/selectRegistered", (req, res) => {
  249. // console.log("获取", req.body);
  250. postmysql3(req, res, "selectRegistered");
  251. });
  252. // yym 活动搜索框
  253. router.get("/selectActSearch", (req, res) => {
  254. // console.log("获取", req.body);
  255. var json = req.query
  256. getmysql(req, res, "selectActSearch",json['openid'],json['txt'],json['ty']);
  257. });
  258. // yym 搜索所有学校
  259. router.get("/selectColleges", (req, res) => {
  260. // console.log("获取", req.body);
  261. var json = req.query
  262. getmysql(req, res, "selectColleges");
  263. });
  264. // 搜索对应学校的专业
  265. router.get("/selectMajors", (req, res) => {
  266. // console.log("获取", req.body);
  267. var json = req.query
  268. getmysql(req, res, "selectMajors",json['mid']);
  269. });
  270. // 模糊搜索学校
  271. router.get("/selectLikeColleges", (req, res) => {
  272. // console.log("获取", req.body);
  273. var json = req.query
  274. getmysql(req, res, "selectLikeColleges",json['txt']);
  275. });
  276. // 模糊搜索专业
  277. router.get("/selectLikeMajors", (req, res) => {
  278. // console.log("获取", req.body);
  279. var json = req.query
  280. getmysql(req, res, "selectLikeMajors",json['mid'],json['txt']);
  281. });
  282. // yym 课程搜索框
  283. router.get("/selectSearchdata", (req, res) => {
  284. var json = req.query
  285. getmysql(req, res, "selectSearchdata",json['openid'],json['txt'],json['ty']);
  286. });
  287. // yym 根据学号/工号自动获取信息
  288. router.get("/selectStudentNumber", (req, res) => {
  289. var json = req.query
  290. getmysql(req, res, "selectStudentNumber",json['txt']);
  291. });
  292. //yym 取消报名
  293. router.post("/deleteApply", (req, res) => {
  294. // console.log("获取", req.body);
  295. postmysql3(req, res, "deleteApply");
  296. });
  297. //yym 发布资源库数据
  298. router.post("/insertResource", (req, res) => {
  299. // console.log("获取", req.body);
  300. postmysql3(req, res, "insertResource");
  301. });
  302. //yym 更新用户查看课程views
  303. router.post("/updateUserViews", (req, res) => {
  304. postmysql3(req, res, "updateUserViews");
  305. });
  306. //yym 查询用户活跃排行
  307. router.get("/selectUserActivity", (req, res) => {
  308. var json = req.query
  309. getmysql(req, res, "selectUserActivity",json['oid']);
  310. });
  311. //yym 获取广告
  312. router.get("/selectAdvertisement", (req, res) => {
  313. var json = req.query
  314. getmysql(req, res, "selectAdvertisement",json['typ']);
  315. });
  316. //lqh获取活动acid
  317. router.post("/selectActivityID", (req, res) => {
  318. postmysql3(req, res, "select_activityID");
  319. });
  320. //查询当前用户发布的活动 xlh
  321. router.post("/selectMyPublish", (req, res) => {
  322. postmysql3(req, res, "select_mypublish");
  323. });
  324. //删除当前用户发布的活动 xlh
  325. router.post("/deleteMyPublish", (req, res) => {
  326. postmysql3(req, res, "delete_mypublish");
  327. });
  328. //查询当前的活动是否是当前的用户发布的 xlh
  329. router.post("/selectPublisher", (req, res) => {
  330. postmysql3(req, res, "select_activity_publisher");
  331. });
  332. //报名申请加入 zwb
  333. router.post("/insertActivityEnroll", (req, res) => {
  334. // console.log(req.body);
  335. postmysql3(req, res, "insert_activity_enroll");
  336. // res.send({
  337. // msg: "上传成功",
  338. // });
  339. });
  340. // 查询我的活动 zwb
  341. router.post("/selectActivityEnroll", (req, res) => {
  342. postmysql3(req, res, "select_activity_enroll");
  343. });
  344. //查询用户是否报名 zwb
  345. router.post("/selectActivityEnrollid", (req, res) => {
  346. postmysql3(req, res, "select_activity_enroll_ID");
  347. });
  348. //查询全部活动
  349. router.route("/selectAct").all((req, res, next) => {
  350. // var json = queryString(req.url);
  351. getmysql(req, res, "selectAct");
  352. });
  353. queryString = function (url) {
  354. var a = url.split("?");
  355. var json = querystring.parse(a[1]);
  356. return json;
  357. };
  358. //post存儲過程處理
  359. postmysql = function (req, res, functionname) {
  360. //mode的處理
  361. if (req.body[0]) {
  362. p = Object.values(req.body[0]);
  363. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  364. //執行存儲過程
  365. mysql.usselect(p, function (ret) {
  366. res.end(JSON.stringify(ret));
  367. });
  368. }
  369. };
  370. //post存儲過程處理
  371. postmysql2 = function (req, res, functionname) {
  372. //mode的處理
  373. if (req.body) {
  374. p = Object.values(req.body)[0].split(",");
  375. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  376. //執行存儲過程
  377. mysql.usselect(p, function (ret) {
  378. res.end(JSON.stringify(ret));
  379. });
  380. }
  381. };
  382. //post存儲過程處理
  383. postmysql3 = function (req, res, functionname) {
  384. //mode的處理
  385. if (req.body) {
  386. p = Object.values(req.body);
  387. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  388. //執行存儲過程
  389. mysql.usselect(p, function (ret) {
  390. res.end(JSON.stringify(ret));
  391. });
  392. }
  393. };
  394. //get獲取數據庫信息
  395. getmysql = function (req, res, functionname, ...p) {
  396. p = p || [];
  397. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  398. //執行存儲過程
  399. mysql.usselect(p, function (ret) {
  400. res.end(JSON.stringify(ret));
  401. }); //
  402. };
  403. //post存储过程处理
  404. userpostmysql = function (req, res, functionname) {
  405. //mode的处理
  406. if (req.body.mode) {
  407. p = req.body.mode.split(",");
  408. p.unshift(_mysqluser[0], _mysqluser[1], functionname);
  409. //执行存储过程
  410. mysql.usselect(p, function (ret) {
  411. res.end(JSON.stringify(ret));
  412. });
  413. }
  414. };
  415. //get获取数据库信息
  416. usergetmysql = function (req, res, functionname, ...p) {
  417. p = p || [];
  418. p.unshift(_mysqluser[0], _mysqluser[1], functionname);
  419. //执行存储过程
  420. mysql.usselect(p, function (ret) {
  421. res.end(JSON.stringify(ret));
  422. }); //
  423. };
  424. module.exports = router;