pbl.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. // 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("/updateView", (req, res) => {
  190. // console.log('获取',req.body);
  191. postmysql3(req, res, "update_view");
  192. });
  193. //lqh获取活动acid
  194. router.post("/selectActivityID", (req, res) => {
  195. postmysql3(req, res, "select_activityID");
  196. });
  197. //查询当前用户发布的活动 xlh
  198. router.post("/selectMyPublish", (req, res) => {
  199. postmysql3(req, res, "select_mypublish");
  200. });
  201. //更改当前用户发布的活动 xlh
  202. router.post("/updateMyPublish", (req, res) => {
  203. postmysql3(req, res, "update_mypublish");
  204. });
  205. //删除当前用户发布的活动 xlh
  206. router.post("/deleteMyPublish", (req, res) => {
  207. postmysql3(req, res, "delete_mypublish");
  208. });
  209. //查询当前的活动是否是当前的用户发布的 xlh
  210. router.post("/selectPublisher", (req, res) => {
  211. postmysql3(req, res, "select_activity_publisher");
  212. });
  213. //报名申请加入 zwb
  214. router.post("/insertActivityEnroll", (req, res) => {
  215. // console.log(req.body);
  216. postmysql3(req, res, "insert_activity_enroll");
  217. res.send({
  218. msg: "上传成功",
  219. });
  220. });
  221. // 查询我的活动 zwb
  222. router.post("/selectActivityEnroll", (req, res) => {
  223. postmysql3(req, res, "select_activity_enroll");
  224. });
  225. //查询用户是否报名 zwb
  226. router.post("/selectActivityEnrollid", (req, res) => {
  227. postmysql3(req, res, "select_activity_enroll_ID");
  228. });
  229. //查询全部活动
  230. router.route("/selectAct").all((req, res, next) => {
  231. var json = queryString(req.url);
  232. getmysql(req, res, "selectAct");
  233. });
  234. queryString = function (url) {
  235. var a = url.split("?");
  236. var json = querystring.parse(a[1]);
  237. return json;
  238. };
  239. //post存儲過程處理
  240. postmysql = function (req, res, functionname) {
  241. //mode的處理
  242. if (req.body[0]) {
  243. p = Object.values(req.body[0]);
  244. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  245. //執行存儲過程
  246. mysql.usselect(p, function (ret) {
  247. res.end(JSON.stringify(ret));
  248. });
  249. }
  250. };
  251. //post存儲過程處理
  252. postmysql2 = function (req, res, functionname) {
  253. //mode的處理
  254. if (req.body) {
  255. p = Object.values(req.body)[0].split(",");
  256. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  257. //執行存儲過程
  258. mysql.usselect(p, function (ret) {
  259. res.end(JSON.stringify(ret));
  260. });
  261. }
  262. };
  263. //post存儲過程處理
  264. postmysql3 = function (req, res, functionname) {
  265. //mode的處理
  266. if (req.body) {
  267. p = Object.values(req.body);
  268. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  269. //執行存儲過程
  270. mysql.usselect(p, function (ret) {
  271. res.end(JSON.stringify(ret));
  272. });
  273. }
  274. };
  275. //get獲取數據庫信息
  276. getmysql = function (req, res, functionname, ...p) {
  277. p = p || [];
  278. p.unshift(_mysqlLabor[0], _mysqlLabor[1], functionname);
  279. //執行存儲過程
  280. mysql.usselect(p, function (ret) {
  281. res.end(JSON.stringify(ret));
  282. }); //
  283. };
  284. //post存储过程处理
  285. userpostmysql = function (req, res, functionname) {
  286. //mode的处理
  287. if (req.body.mode) {
  288. p = req.body.mode.split(",");
  289. p.unshift(_mysqluser[0], _mysqluser[1], functionname);
  290. //执行存储过程
  291. mysql.usselect(p, function (ret) {
  292. res.end(JSON.stringify(ret));
  293. });
  294. }
  295. };
  296. //get获取数据库信息
  297. usergetmysql = function (req, res, functionname, ...p) {
  298. p = p || [];
  299. p.unshift(_mysqluser[0], _mysqluser[1], functionname);
  300. //执行存储过程
  301. mysql.usselect(p, function (ret) {
  302. res.end(JSON.stringify(ret));
  303. }); //
  304. };
  305. module.exports = router;