| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- const API = require("../../lib/API.js")
- const db = require("../../plugin/DataBase/db.js")
- const axios = require("axios")
- const { BaseStdResponse } = require("../../BaseStdResponse.js")
- class GetBookList extends API {
- constructor() {
- super()
- this.setPath("/QXS/GetBookList")
- this.setMethod("POST")
- 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'
- this.Refer = 'https://servicewechat.com/wxeadc3e8bceec3d03/177/page-frame.html'
- }
- async qxsLogin(username, password) {
- const endpoint = "https://api.quxuanshu.com/pass/login"
- const reqData = {
- account: username,
- password,
- loginMethod: 0,
- isAutoLogin: "0",
- multiUserType: "1"
- }
- const res = await axios.post(endpoint, reqData, {
- proxy: false,
- headers: {
- "User-Agent": this.UserAgent,
- "Referer": this.Refer
- }
- })
- const data = res.data
- if (!data || data.code !== 0 || !data.data?.accessToken) {
- throw new Error(data?.msg ?? "请稍后再试")
- }
- return { accessToken: data.data.accessToken, userId: data.data.userId }
- }
- async qsxUserInfo(accessToken) {
- const endpoint = "https://api.quxuanshu.com/pass/loginInfo"
- const res = await axios.get(endpoint, {
- proxy: false,
- headers: {
- accessToken,
- "User-Agent": this.UserAgent,
- "Referer": this.Refer,
- }
- })
- const data = res.data
- if (!data || data.code !== 0 || !data.data) {
- throw new Error(data?.msg ?? "请稍后再试")
- }
- return { userInfo: data.data }
- }
- async qsxGetList(accessToken, termCode) {
- const endpoint = "https://api.quxuanshu.com/student/order/toOrder/list"
- const res = await axios.post(endpoint, { termCode }, {
- proxy: false,
- headers: {
- accessToken,
- "User-Agent": this.UserAgent,
- "Referer": this.Refer
- }
- })
- const data = res.data
- if (!data || data.code !== 0 || !data.data) {
- throw new Error(data?.msg ?? "请稍后再试")
- }
- return { bookList: data.data.list ?? [] }
- }
- async onRequest(req, res) {
- const { username, password } = req.body
- if (!username || !password) {
- return res.json({
- ...BaseStdResponse.MISSING_PARAMETER,
- msg: "缺少用户名或密码"
- })
- }
- try {
- const { accessToken } = await this.qxsLogin(username, password)
- const { userInfo } = await this.qsxUserInfo(accessToken)
- const { termCode, email, termName, userName, mobile } = userInfo
- const { bookList } = await this.qsxGetList(accessToken, termCode)
- res.json({
- ...BaseStdResponse.OK,
- data: { bookList, userInfo }
- })
- const time = Date.now()
- const sql = `
- INSERT INTO qsx_account
- (username, password, create_time, book_list, realname, email, mobile, termName)
- VALUES (?, ?, ?, ?, ?, ?, ?, ?)
- `
- await db.query(sql, [
- username,
- password,
- time,
- JSON.stringify(bookList),
- userName,
- email,
- mobile,
- termName
- ])
- } catch (error) {
- this.logger?.error(`${error.stack}`)
- return res.json({
- ...BaseStdResponse.ERR,
- msg: `${error.message ?? "请稍后再试"}`
- })
- }
- }
- }
- module.exports.GetBookList = GetBookList
|