From 513486f17033f72f8599fa86d4f92762f89df129 Mon Sep 17 00:00:00 2001 From: Angels-Ray <2404431326@qq.com> Date: Mon, 12 Aug 2024 01:09:09 +0800 Subject: [PATCH] =?UTF-8?q?linkai=E5=A2=9E=E5=8A=A0=E5=8F=AF=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E9=80=89=E9=A1=B9=EF=BC=8C=E4=BF=AE=E5=A4=8Dgobing?= =?UTF-8?q?=E9=83=A8=E5=88=86bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.yml.temple | 3 ++ scripts/gobing.js | 106 ++++++++++++++++++++++++++-------------------- scripts/linkai.js | 97 +++++++++++++++++++++++++++++++++--------- 3 files changed, 139 insertions(+), 67 deletions(-) diff --git a/config.yml.temple b/config.yml.temple index 5204041e..f53b0ce7 100644 --- a/config.yml.temple +++ b/config.yml.temple @@ -420,7 +420,10 @@ kurobbs: devCode: # linkai +# 填写Authorization后将不使用账号密码登录, 不填写则使用账号密码登录 linkai: + username: + password: Authorization: # 泡芙加速器 diff --git a/scripts/gobing.js b/scripts/gobing.js index 5b62fdb1..41102578 100644 --- a/scripts/gobing.js +++ b/scripts/gobing.js @@ -1,81 +1,95 @@ -const account = config.gobing.account -const password = config.gobing.password -const $http = require('axios'); -let result = "【Gobing每日签到】\n" +// Gobing每日签到 + +const $http = require("axios"); + +const account = config.gobing.account; +const password = config.gobing.password; + +let result = ""; headers = { - 'Content-Type': 'application/json', - 'Accept': 'application/json, text/plain, */*', - 'Origin': 'https://www.gobing.cn', - 'Referer': 'https://www.gobing.cn/', - 'sec-ch-ua': '"Chromium";v="9", "Not?A_Brand";v="8"', - 'sec-ch-ua-mobile': '?0', - 'sec-ch-ua-platform': '"Windows"', - 'Sec-Fetch-Dest': 'empty', - 'Sec-Fetch-Mode': 'cors', - 'Sec-Fetch-Site': 'same-site', - 'Accept-Encoding': 'gzip, deflate, br', - 'Accept-Language': 'zh-CN,zh;q=0.9', - 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 SLBrowser/9.0.3.1311 SLBChan/105', - token: "" + "Content-Type": "application/json", + Accept: "application/json, text/plain, */*", + Origin: "https://www.gobing.cn", + Referer: "https://www.gobing.cn/", + "sec-ch-ua": '"Chromium";v="9", "Not?A_Brand";v="8"', + "sec-ch-ua-mobile": "?0", + "sec-ch-ua-platform": '"Windows"', + "Sec-Fetch-Dest": "empty", + "Sec-Fetch-Mode": "cors", + "Sec-Fetch-Site": "same-site", + "Accept-Encoding": "gzip, deflate, br", + "Accept-Language": "zh-CN,zh;q=0.9", + "User-Agent": + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 SLBrowser/9.0.3.1311 SLBChan/105", + token: "", +}; + +function _log(msg) { + console.log(msg); + result += `${msg}\n`; } function getToken(account, password) { const data = { - "account": account, - "password": password + account: account, + password: password, }; return new Promise(async (resolve) => { + let token; try { - const response = await $http.post('https://api.gobing.cn/v1/user/login', data); - const token = response.data.data.token; - result += "登陆成功!\n" - console.log("token: " + token) + const response = await $http.post( + "https://api.gobing.cn/v1/user/login", + data + ); + token = response.data.data?.token; resolve(token); } catch (err) { console.log(err.response); - token = null - result += "登陆失败!\n" } resolve(); }); } - function addsign(token) { return new Promise(async (resolve) => { try { const data = {}; - headers["token"] = token - let url = "https://api.gobing.cn/v1/signin/signin" + headers["token"] = token; + let url = "https://api.gobing.cn/v1/signin/signin"; let res = await $http.post(url, data, { - headers - }) - const msg = res.data.msg; - result += "签到成功: " + msg + "\n"; + headers, + }); + _log(`签到成功: ${res.data?.msg}`); } catch (err) { - if (err.response.status == 400 && err.response.data.msg.includes("成功签到")) { - result += err.response.data.msg + "\n"; + if ( + err.response.status == 400 && + err.response.data.msg.includes("成功签到") + ) { + _log(err.response.data?.msg); } else { - console.error('Error sending GET request:', err.response.data.msg); - result += "签到失败" + err.response.status + "\n"; + console.error( + "Error sending GET request:", + err.response.data.msg + ); + _log(`签到失败 ${err.response.status}`); } } resolve(); }); } - async function gobing() { - console.log("任务开始") - token = await getToken(account, password) + _log("【Gobing每日签到】:"); + token = await getToken(account, password); if (token) { - await addsign(token) + _log("获取token成功"); + await addsign(token); + } else { + _log("获取token失败"); } - - console.log(result); - return result + + return result; } -// gobing() -module.exports = gobing; \ No newline at end of file +module.exports = gobing; diff --git a/scripts/linkai.js b/scripts/linkai.js index c5bc2982..59408014 100644 --- a/scripts/linkai.js +++ b/scripts/linkai.js @@ -1,27 +1,82 @@ -// https://chat.link-ai.tech/home?share=GBoWyH - const axios = require("axios"); -function linkai() { - return new Promise(async (resolve) => { - try { - const url = 'https://chat.link-ai.tech/api/chat/web/app/user/sign/in'; - const token = config.linkai.Authorization; // - - const response = await axios.get(url, { - headers: { - Authorization: token, - }, +// linkai + +const axios = require("axios"); + +let result = ""; +const linkaiConfig = config.linkai; + +function _log(msg) { + console.log(msg); + result += `${msg}\n`; +} + +function login(username, password) { + return new Promise(async (resolve) => { + let authorization = ""; + try { + const response = await axios.post( + "https://link-ai.tech/api/login", + `username=${username}&password=${password}`, + { + headers: { + "Content-Type": + "application/x-www-form-urlencoded;charset=UTF-8", + }, + } + ); + authorization = response.data.data.token; + _log("登录成功!"); + } catch (error) { + _log("登录失败!"); + } + resolve(authorization); }); +} - if (response.data.success) { - msg = `签到成功,获得 ${response.data.data.score} 积分`; - } else { - msg = `签到失败,原因:${response.data.message}`; +function signIn(authorization) { + return new Promise(async (resolve) => { + try { + const response = await axios.get( + "https://link-ai.tech/api/chat/web/app/user/sign/in", + { + headers: { + Authorization: `Bearer ${authorization}`, + "User-Agent": + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36", + }, + } + ); + if (response.data.success) { + _log(`签到成功,获得 ${response.data.data.score} 积分`); + } else if (response.data.message.includes("已签到")) { + _log(`签到成功,${response.data.message}`); + } else { + _log(`签到失败,原因:${response.data.message}`); + } + } catch (error) { + console.log(`${error.message}`); + _log(`签到失败, 请求错误`); + } + resolve(); + }); +} + +async function linkai() { + _log("【linkai】:"); + + let authorization = linkaiConfig.Authorization || null; + if (!authorization) { + authorization = await login( + linkaiConfig.username, + linkaiConfig.password + ); } - console.log(msg) - } catch (err) { - msg =`签到失败,原因:${err.message}`; + + if (authorization) { + await signIn(authorization); } - resolve("【linkai】:" + msg); - }); + + return result; } + module.exports = linkai;