GetLoginUrl.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const API = require("../../../lib/API")
  2. const axios = require('axios')
  3. const config = require('../../../config.json')
  4. const { BaseStdResponse } = require("../../../BaseStdResponse");
  5. class GetLoginUrl extends API {
  6. constructor() {
  7. super();
  8. this.setPath('/UniLogin/GetLoginUrl')
  9. this.setMethod('GET')
  10. }
  11. async onRequest(req, res) {
  12. let { type } = req.query
  13. const uniConfig = config.unilogin
  14. let url = `${uniConfig.url}/connect.php?act=login&appid=${uniConfig.appid}&appkey=${uniConfig.appkey}&type=${type || 'qq'}&redirect_uri=${uniConfig.return_url}`
  15. try {
  16. const r = await axios.get(url, {
  17. proxy: false
  18. })
  19. if (!r || r.data?.code !== 0 || !r.data?.url) {
  20. this.logger.error(`获取聚合登录链接失败!${r.data?.msg || 'api接口错误'}`)
  21. return res.json({
  22. ...BaseStdResponse.ERR,
  23. msg: '获取聚合登录链接失败!'
  24. })
  25. }
  26. res.json({
  27. ...BaseStdResponse.OK,
  28. data: r.data.url
  29. })
  30. } catch (error) {
  31. this.logger.error(`获取聚合登录链接失败!${error.message || 'api接口错误'}`)
  32. return res.json({
  33. ...BaseStdResponse.ERR,
  34. msg: '获取聚合登录链接失败!'
  35. })
  36. }
  37. }
  38. }
  39. module.exports.GetLoginUrl = GetLoginUrl;