GetPowerData.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. const API = require("../../lib/API.js")
  2. const axios = require("axios")
  3. const { BaseStdResponse } = require("../../BaseStdResponse.js")
  4. // 获取楼栋
  5. class GetDyList extends API {
  6. constructor() {
  7. super()
  8. this.setPath("/Power/GetPowerData")
  9. this.setMethod("POST")
  10. }
  11. async onRequest(req, res) {
  12. try {
  13. const { type, pid } = req.body
  14. if ([type].some(value => value === '' || value === null || value === undefined))
  15. return res.json({
  16. ...BaseStdResponse.MISSING_PARAMETER
  17. })
  18. if (type !== 'buildlist')
  19. if ([pid].some(value => value === '' || value === null || value === undefined))
  20. return res.json({
  21. ...BaseStdResponse.MISSING_PARAMETER
  22. })
  23. const url = `https://hqpay.ctbu.edu.cn/weixin/ashx/frmuser.ashx?test=${type}${type !== 'buildlist' ? '&pid=' + pid : ''}`
  24. const response = await axios.get(url, {
  25. proxy: false
  26. })
  27. if (!response || !response.data)
  28. return res.json({
  29. ...BaseStdResponse.ERR,
  30. msg: "请稍后再试"
  31. })
  32. res.json({
  33. ...BaseStdResponse.OK,
  34. data: response.data ?? []
  35. })
  36. } catch (error) {
  37. this.logger?.error(`${error.stack}`)
  38. return res.json({
  39. ...BaseStdResponse.ERR,
  40. msg: `${error.message ?? "请稍后再试"}`
  41. })
  42. }
  43. }
  44. }
  45. module.exports.GetDyList = GetDyList