| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- const API = require("../../../lib/API")
- const axios = require('axios')
- const config = require('../../../config.json')
- const { BaseStdResponse } = require("../../../BaseStdResponse");
- class GetLoginUrl extends API {
- constructor() {
- super();
- this.setPath('/UniLogin/GetLoginUrl')
- this.setMethod('GET')
- }
- async onRequest(req, res) {
- let { type } = req.query
- const uniConfig = config.unilogin
- let url = `${uniConfig.url}/connect.php?act=login&appid=${uniConfig.appid}&appkey=${uniConfig.appkey}&type=${type || 'qq'}&redirect_uri=${encodeURIComponent(uniConfig.return_url)}`
- try {
- const r = await axios.get(url, {
- proxy: false
- })
- if (!r || r.data?.code !== 0 || !r.data?.url) {
- this.logger.error(`获取聚合登录链接失败!${r.data?.msg || 'api接口错误'}`)
- return res.json({
- ...BaseStdResponse.ERR,
- msg: '获取聚合登录链接失败!'
- })
- }
- res.json({
- ...BaseStdResponse.OK,
- data: r.data.url
- })
- } catch (error) {
- this.logger.error(`获取聚合登录链接失败!${error.message || 'api接口错误'}`)
- return res.json({
- ...BaseStdResponse.ERR,
- msg: '获取聚合登录链接失败!'
- })
- }
- }
- }
- module.exports.GetLoginUrl = GetLoginUrl;
|