pbl.js 7.1 KB

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