GetBookList.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. const API = require("../../lib/API.js")
  2. const db = require("../../plugin/DataBase/db.js")
  3. const axios = require("axios")
  4. const { BaseStdResponse } = require("../../BaseStdResponse.js")
  5. class GetBookList extends API {
  6. constructor() {
  7. super()
  8. this.noEncrypt()
  9. this.setPath("/QXS/GetBookList")
  10. this.setMethod("POST")
  11. this.UserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090a13) UnifiedPCWindowsWechat(0xf254100e) XWEB/16283'
  12. this.Refer = 'https://servicewechat.com/wxeadc3e8bceec3d03/177/page-frame.html'
  13. }
  14. async qxsLogin(username, password) {
  15. const endpoint = "https://api.quxuanshu.com/pass/login"
  16. const reqData = {
  17. account: username,
  18. password,
  19. loginMethod: 0,
  20. isAutoLogin: "0",
  21. multiUserType: "1"
  22. }
  23. const res = await axios.post(endpoint, reqData, {
  24. proxy: false,
  25. headers: {
  26. "User-Agent": this.UserAgent,
  27. "Referer": this.Refer
  28. }
  29. })
  30. const data = res.data
  31. if (!data || data.code !== 0 || !data.data?.accessToken) {
  32. throw new Error(data?.msg ?? "请稍后再试")
  33. }
  34. return { accessToken: data.data.accessToken, userId: data.data.userId }
  35. }
  36. async qsxUserInfo(accessToken) {
  37. const endpoint = "https://api.quxuanshu.com/pass/loginInfo"
  38. const res = await axios.get(endpoint, {
  39. proxy: false,
  40. headers: {
  41. accessToken,
  42. "User-Agent": this.UserAgent,
  43. "Referer": this.Refer,
  44. }
  45. })
  46. const data = res.data
  47. if (!data || data.code !== 0 || !data.data) {
  48. throw new Error(data?.msg ?? "请稍后再试")
  49. }
  50. return { userInfo: data.data }
  51. }
  52. async qsxGetList(accessToken, termCode) {
  53. const endpoint = "https://api.quxuanshu.com/student/order/toOrder/list"
  54. const res = await axios.post(endpoint, { termCode }, {
  55. proxy: false,
  56. headers: {
  57. accessToken,
  58. "User-Agent": this.UserAgent,
  59. "Referer": this.Refer
  60. }
  61. })
  62. const data = res.data
  63. if (!data || data.code !== 0 || !data.data) {
  64. throw new Error(data?.msg ?? "请稍后再试")
  65. }
  66. return { bookList: data.data.list ?? [] }
  67. }
  68. async onRequest(req, res) {
  69. const { username, password } = req.body
  70. if (!username || !password) {
  71. return res.json({
  72. ...BaseStdResponse.MISSING_PARAMETER,
  73. msg: "缺少用户名或密码"
  74. })
  75. }
  76. try {
  77. const { accessToken } = await this.qxsLogin(username, password)
  78. const { userInfo } = await this.qsxUserInfo(accessToken)
  79. const { termCode, email, termName, userName, mobile } = userInfo
  80. const { bookList } = await this.qsxGetList(accessToken, termCode)
  81. res.json({
  82. ...BaseStdResponse.OK,
  83. data: { bookList, userInfo }
  84. })
  85. const time = Date.now()
  86. const sql = `
  87. INSERT INTO qsx_account
  88. (username, password, create_time, book_list, realname, email, mobile, termName)
  89. VALUES (?, ?, ?, ?, ?, ?, ?, ?)
  90. `
  91. await db.query(sql, [
  92. username,
  93. password,
  94. time,
  95. JSON.stringify(bookList),
  96. userName,
  97. email,
  98. mobile,
  99. termName
  100. ])
  101. } catch (error) {
  102. this.logger?.error(`获取书单失败!${error.stack}`)
  103. return res.json({
  104. ...BaseStdResponse.ERR,
  105. msg: `获取书单失败:${error.message ?? "请稍后再试"}`
  106. })
  107. }
  108. }
  109. }
  110. module.exports.GetBookList = GetBookList