pbl.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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. //lqh获取活动acid
  229. router.post("/selectActivityID", (req, res) => {
  230. postmysql3(req, res, "select_activityID");
  231. });
  232. //查询当前用户发布的活动 xlh
  233. router.post("/selectMyPublish", (req, res) => {
  234. postmysql3(req, res, "select_mypublish");
  235. });
  236. //更改当前用户发布的活动 xlh
  237. router.post("/updateMyPublish", (req, res) => {
  238. postmysql3(req, res, "update_mypublish");
  239. });
  240. //删除当前用户发布的活动 xlh
  241. router.post("/deleteMyPublish", (req, res) => {
  242. postmysql3(req, res, "delete_mypublish");
  243. });
  244. //查询当前的活动是否是当前的用户发布的 xlh
  245. router.post("/selectPublisher", (req, res) => {
  246. postmysql3(req, res, "select_activity_publisher");
  247. });
  248. //报名申请加入 zwb
  249. router.post("/insertActivityEnroll", (req, res) => {
  250. // console.log(req.body);
  251. postmysql3(req, res, "insert_activity_enroll");
  252. // res.send({
  253. // msg: "上传成功",
  254. // });
  255. });
  256. // 查询我的活动 zwb
  257. router.post("/selectActivityEnroll", (req, res) => {
  258. postmysql3(req, res, "select_activity_enroll");
  259. });
  260. //查询用户是否报名 zwb
  261. router.post("/selectActivityEnrollid", (req, res) => {
  262. postmysql3(req, res, "select_activity_enroll_ID");
  263. });
  264. //查询全部活动
  265. router.route("/selectAct").all((req, res, next) => {
  266. // var json = queryString(req.url);
  267. getmysql(req, res, "selectAct");
  268. });
  269. queryString = function (url) {
  270. var a = url.split("?");
  271. var json = querystring.parse(a[1]);
  272. return json;
  273. };
  274. //post存儲過程處理
  275. postmysql = function (req, res, functionname) {
  276. //mode的處理
  277. if (req.body[0]) {
  278. p = Object.values(req.body[0]);
  279. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  280. //執行存儲過程
  281. mysql.usselect(p, function (ret) {
  282. res.end(JSON.stringify(ret));
  283. });
  284. }
  285. };
  286. //post存儲過程處理
  287. postmysql2 = function (req, res, functionname) {
  288. //mode的處理
  289. if (req.body) {
  290. p = Object.values(req.body)[0].split(",");
  291. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  292. //執行存儲過程
  293. mysql.usselect(p, function (ret) {
  294. res.end(JSON.stringify(ret));
  295. });
  296. }
  297. };
  298. //post存儲過程處理
  299. postmysql3 = function (req, res, functionname) {
  300. //mode的處理
  301. if (req.body) {
  302. p = Object.values(req.body);
  303. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  304. //執行存儲過程
  305. mysql.usselect(p, function (ret) {
  306. res.end(JSON.stringify(ret));
  307. });
  308. }
  309. };
  310. //get獲取數據庫信息
  311. getmysql = function (req, res, functionname, ...p) {
  312. p = p || [];
  313. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  314. //執行存儲過程
  315. mysql.usselect(p, function (ret) {
  316. res.end(JSON.stringify(ret));
  317. }); //
  318. };
  319. //post存储过程处理
  320. userpostmysql = function (req, res, functionname) {
  321. //mode的处理
  322. if (req.body.mode) {
  323. p = req.body.mode.split(",");
  324. p.unshift(_mysqluser[0], _mysqluser[1], functionname);
  325. //执行存储过程
  326. mysql.usselect(p, function (ret) {
  327. res.end(JSON.stringify(ret));
  328. });
  329. }
  330. };
  331. //get获取数据库信息
  332. usergetmysql = function (req, res, functionname, ...p) {
  333. p = p || [];
  334. p.unshift(_mysqluser[0], _mysqluser[1], functionname);
  335. //执行存储过程
  336. mysql.usselect(p, function (ret) {
  337. res.end(JSON.stringify(ret));
  338. }); //
  339. };
  340. module.exports = router;