pbl.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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("https://api.weixin.qq.com/sns/jscode2session", {
  60. params: {
  61. appid: wx.appid,
  62. secret: wx.secret,
  63. js_code: req.query.codes,
  64. grant_type: "authorization_code",
  65. },
  66. });
  67. // console.log(response.data);
  68. res.send(response.data.openid);
  69. // QMysql(req, res, "update_NewStatusById");
  70. });
  71. //yym注册接口
  72. router.post("/login", (req, res) => {
  73. // return console.log(req.body);
  74. // let { openid } = req.body;
  75. postmysql3(req, res, "insert_user");
  76. // let token = jwt.sign({
  77. // openid,
  78. // },
  79. // "secret", {
  80. // expiresIn: "10s",
  81. // }
  82. // );
  83. // res.send({
  84. // code: 200,
  85. // msg: "登录成功",
  86. // token,
  87. // });
  88. });
  89. //yym查询用户(查询是否注册过)
  90. router.post("/selectUser", (req, res) => {
  91. // console.log(req.body);
  92. // let { openid } = req.body;
  93. postmysql3(req, res, "Select_user");
  94. // console.log(res.end);
  95. });
  96. // yym更新头像昵称
  97. router.post("/updateUser", (req, res) => {
  98. // console.log(req.body);
  99. postmysql3(req, res, "update_User");
  100. });
  101. //yym上传活动
  102. router.post("/insertActive", (req, res) => {
  103. // console.log(req.body);
  104. postmysql3(req, res, "insert_activity");
  105. // res.send({
  106. // code: 200,
  107. // msg: "上传成功",
  108. // });
  109. });
  110. //yym 获取活动
  111. router.post("/selectActivity", (req, res) => {
  112. // console.log(req.body);
  113. postmysql3(req, res, "select_activity");
  114. });
  115. //yym 获取用户收藏信息
  116. router.post("/selectColl", (req, res) => {
  117. // console.log(req.body);
  118. postmysql3(req, res, "select_coll");
  119. });
  120. //yym 更新用户收藏信息
  121. router.post("/updateColl", (req, res) => {
  122. // console.log('更新用户收藏信息',req.body);
  123. postmysql3(req, res, "update_coll");
  124. });
  125. //获取用户订阅信息 xlh
  126. router.post("/selectSub", (req, res) => {
  127. postmysql3(req, res, "select_sub");
  128. });
  129. //更新用户订阅信息 xlh
  130. router.post("/updateSub", (req, res) => {
  131. postmysql3(req, res, "update_sub");
  132. });
  133. //yym 获取用户收藏数据(数组查询) 废弃
  134. router.post("/selectCollList", (req, res) => {
  135. // console.log('获取',req.body);
  136. postmysql3(req, res, "select_collList");
  137. });
  138. //yym 获取用户订阅数据(数组查询) 废弃
  139. router.post("/selectSubList", (req, res) => {
  140. // console.log('获取',req.body);
  141. postmysql3(req, res, "select_subList");
  142. });
  143. //yym 获取用户信息
  144. router.post("/selectUserInfo", (req, res) => {
  145. // console.log('获取',req.body);
  146. postmysql3(req, res, "select_UserInfo");
  147. });
  148. //yym 更新用户信息
  149. router.post("/updateUserInfo", (req, res) => {
  150. console.log('获取用户信息',req.body);
  151. postmysql3(req, res, "update_userInfo");
  152. });
  153. //yym 用户报名收藏等操作 0收藏 1订阅 2报名
  154. router.post("/insertOperator", (req, res) => {
  155. // console.log('获取',req.body);
  156. postmysql3(req, res, "insert_operator");
  157. });
  158. //yym 查询用户全部报名收藏 0收藏 1订阅 2报名
  159. router.post("/selectOperator", (req, res) => {
  160. // console.log('获取',req.body);
  161. postmysql3(req, res, "select_operator");
  162. });
  163. //yym 查询用户 单个 报名收藏
  164. router.post("/selectOneOperator", (req, res) => {
  165. // console.log('获取',req.body);
  166. postmysql3(req, res, "select_oneOperator");
  167. });
  168. //yym 删除用户收藏或订阅
  169. router.post("/deleteOperator", (req, res) => {
  170. // console.log('获取',req.body);
  171. postmysql3(req, res, "delete_Operator");
  172. });
  173. //yym 我的发布页面获取要修改的活动数据
  174. router.post("/selectAmendAct", (req, res) => {
  175. // console.log('获取',req.body);
  176. postmysql3(req, res, "select_amendAct");
  177. });
  178. //yym 获取活动详情页面是否收藏订阅报名
  179. router.post("/selectSignup", (req, res) => {
  180. // console.log('获取',req.body);
  181. postmysql3(req, res, "select_signup");
  182. });
  183. //yym 报名活动
  184. router.post("/insertSignup", (req, res) => {
  185. // console.log('获取',req.body);
  186. postmysql3(req, res, "insert_Signup");
  187. });
  188. //yym 做最后判断防止同一时间进入报名页面都报名成功
  189. router.post("/selectIntercept", (req, res) => {
  190. // console.log('获取',req.body);
  191. postmysql3(req, res, "select_intercept");
  192. });
  193. //yym 获取活动报名人
  194. router.post("/selectApplyUser", (req, res) => {
  195. // console.log('获取',req.body);
  196. postmysql3(req, res, "select_applyUser");
  197. });
  198. //yym 添加活动通知
  199. router.post("/insertMessage", (req, res) => {
  200. // console.log('获取',req.body);
  201. postmysql3(req, res, "insert_message");
  202. });
  203. //yym 信息列表查询信息
  204. router.post("/selectMessage", (req, res) => {
  205. // console.log('获取',req.body);
  206. postmysql3(req, res, "select_message");
  207. });
  208. //yym 查询所有未读信息
  209. router.post("/selectAllMessage", (req, res) => {
  210. // console.log('获取',req.body);
  211. postmysql3(req, res, "select_allMessage");
  212. });
  213. //yym 信息页面分组查询未读信息
  214. router.post("/selectGroupMessage", (req, res) => {
  215. // console.log('获取',req.body);
  216. postmysql3(req, res, "select_groupMessage");
  217. });
  218. //yym 更新未读信息
  219. router.post("/updateIsRead", (req, res) => {
  220. console.log('获取',req.body);
  221. postmysql3(req, res, "update_isRead");
  222. });
  223. //yym 我的页面,我的收藏活动列表
  224. router.post("/selectCollAcList", (req, res) => {
  225. console.log('获取',req.body);
  226. postmysql3(req, res, "select_collAcList");
  227. });
  228. //yym 我的页面,我的收藏课程列表
  229. router.post("/selectCollClassList", (req, res) => {
  230. console.log('获取',req.body);
  231. postmysql3(req, res, "select_collClassList");
  232. });
  233. //yym 获取资源库
  234. router.post("/selectResource", (req, res) => {
  235. console.log('获取',req.body);
  236. postmysql3(req, res, "select_resource");
  237. });
  238. //yym 获取精品慕课
  239. router.post("/selectJTeach", (req, res) => {
  240. console.log('获取',req.body);
  241. postmysql3(req, res, "select_jTeach");
  242. });
  243. //yym 获取课程
  244. router.post("/selectOperatorTech", (req, res) => {
  245. console.log('获取',req.body);
  246. postmysql3(req, res, "select_operatorTech");
  247. });
  248. //yym 获取我的消息,未读红点所填数据
  249. router.post("/selectUnreadMsg", (req, res) => {
  250. console.log('获取',req.body);
  251. postmysql3(req, res, "select_unreadMsg");
  252. });
  253. //yym 单个点击信息变已读
  254. router.post("/updateOneIsRead", (req, res) => {
  255. console.log('获取',req.body);
  256. postmysql3(req, res, "update_oneIsRead");
  257. });
  258. //lqh获取活动acid
  259. router.post("/selectActivityID", (req, res) => {
  260. postmysql3(req, res, "select_activityID");
  261. });
  262. //查询当前用户发布的活动 xlh
  263. router.post("/selectMyPublish", (req, res) => {
  264. postmysql3(req, res, "select_mypublish");
  265. });
  266. //更改当前用户发布的活动 xlh
  267. router.post("/updateMyPublish", (req, res) => {
  268. postmysql3(req, res, "update_mypublish");
  269. });
  270. //删除当前用户发布的活动 xlh
  271. router.post("/deleteMyPublish", (req, res) => {
  272. postmysql3(req, res, "delete_mypublish");
  273. });
  274. //查询当前的活动是否是当前的用户发布的 xlh
  275. router.post("/selectPublisher", (req, res) => {
  276. postmysql3(req, res, "select_activity_publisher");
  277. });
  278. //报名申请加入 zwb
  279. router.post("/insertActivityEnroll", (req, res) => {
  280. // console.log(req.body);
  281. postmysql3(req, res, "insert_activity_enroll");
  282. // res.send({
  283. // msg: "上传成功",
  284. // });
  285. });
  286. // 查询我的活动 zwb
  287. router.post("/selectActivityEnroll", (req, res) => {
  288. postmysql3(req, res, "select_activity_enroll");
  289. });
  290. //查询用户是否报名 zwb
  291. router.post("/selectActivityEnrollid", (req, res) => {
  292. postmysql3(req, res, "select_activity_enroll_ID");
  293. });
  294. //查询全部活动
  295. router.route("/selectAct").all((req, res, next) => {
  296. // var json = queryString(req.url);
  297. getmysql(req, res, "selectAct");
  298. });
  299. queryString = function (url) {
  300. var a = url.split("?");
  301. var json = querystring.parse(a[1]);
  302. return json;
  303. };
  304. //post存儲過程處理
  305. postmysql = function (req, res, functionname) {
  306. //mode的處理
  307. if (req.body[0]) {
  308. p = Object.values(req.body[0]);
  309. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  310. //執行存儲過程
  311. mysql.usselect(p, function (ret) {
  312. res.end(JSON.stringify(ret));
  313. });
  314. }
  315. };
  316. //post存儲過程處理
  317. postmysql2 = function (req, res, functionname) {
  318. //mode的處理
  319. if (req.body) {
  320. p = Object.values(req.body)[0].split(",");
  321. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  322. //執行存儲過程
  323. mysql.usselect(p, function (ret) {
  324. res.end(JSON.stringify(ret));
  325. });
  326. }
  327. };
  328. //post存儲過程處理
  329. postmysql3 = function (req, res, functionname) {
  330. //mode的處理
  331. if (req.body) {
  332. p = Object.values(req.body);
  333. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  334. //執行存儲過程
  335. mysql.usselect(p, function (ret) {
  336. res.end(JSON.stringify(ret));
  337. });
  338. }
  339. };
  340. //get獲取數據庫信息
  341. getmysql = function (req, res, functionname, ...p) {
  342. p = p || [];
  343. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  344. //執行存儲過程
  345. mysql.usselect(p, function (ret) {
  346. res.end(JSON.stringify(ret));
  347. }); //
  348. };
  349. //post存储过程处理
  350. userpostmysql = function (req, res, functionname) {
  351. //mode的处理
  352. if (req.body.mode) {
  353. p = req.body.mode.split(",");
  354. p.unshift(_mysqluser[0], _mysqluser[1], functionname);
  355. //执行存储过程
  356. mysql.usselect(p, function (ret) {
  357. res.end(JSON.stringify(ret));
  358. });
  359. }
  360. };
  361. //get获取数据库信息
  362. usergetmysql = function (req, res, functionname, ...p) {
  363. p = p || [];
  364. p.unshift(_mysqluser[0], _mysqluser[1], functionname);
  365. //执行存储过程
  366. mysql.usselect(p, function (ret) {
  367. res.end(JSON.stringify(ret));
  368. }); //
  369. };
  370. module.exports = router;