feat=>增加多账号的代理

This commit is contained in:
amadeus5201 2025-01-11 14:51:28 +08:00
parent 717d8cf281
commit fa91a2126d
3 changed files with 69 additions and 7 deletions

View File

@ -64,7 +64,11 @@ module.exports = Object.freeze({
NUMBER: 1,
CLEAR: true,
WAIT: 60 * 1000,
ACCOUNT_UA: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'
ACCOUNT_UA: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
PROXY_HOST:'',//代理ip
PROXY_PORT:'',//代理ip端口
PROXY_USER:'',//代理ip账号
PROXY_PASS:'',//代理ip密码
}
],

View File

@ -80,6 +80,16 @@ class Line {
}
}
}
function getIp({ url }) {
return new Promise((resolve) => {
send({
url,
method: 'GET',
success: res => resolve(res.body),
failure: err => resolve(err)
});
});
}
/**
* GET请求
@ -132,6 +142,11 @@ function post({ url, config, contents, query }) {
* 网络请求
*/
const bili_client = {
async getIpInfo() {
return await getIp({
url: 'https://myip.qq.com/'
});
},
/**
* 判断是否成功登录
* @returns {Promise<Object?>}
@ -186,7 +201,11 @@ const bili_client = {
const items = res.data.items;
if (items.length !== 0) {
items.forEach(i => {
const { at_time, item, user } = i, { nickname: up_uname } = user, { business, uri: url, source_content } = item;
const { at_time, item, user } = i, { nickname: up_uname } = user, {
business,
uri: url,
source_content
} = item;
atInfo.push({
at_time,
up_uname,
@ -583,7 +602,7 @@ const bili_client = {
* @param {number} uid
* @returns {Promise<string>}
*/
(uid) => get({
(uid) => get({
url: API.WEB_INTERFACE_CARD,
query: {
mid: uid,
@ -598,7 +617,7 @@ const bili_client = {
* @param {number} uid
* @returns {Promise<string>}
*/
(uid) => get({
(uid) => get({
url: API.RELATION_STAT,
query: {
vmid: uid
@ -609,7 +628,7 @@ const bili_client = {
* @param {number} uid
* @returns {Promise<string>}
*/
(uid) => get({
(uid) => get({
url: 'https://tenapi.cn/bilibilifo/',
query: {
uid

43
main.js
View File

@ -1,5 +1,17 @@
const { version: ve, env_file, config_file, log, hasEnv, delay, hasFileOrDir, clearLotteryInfo } = require('./lib/utils');
const {
version: ve,
env_file,
config_file,
log,
hasEnv,
delay,
hasFileOrDir,
clearLotteryInfo
} = require('./lib/utils');
const { getIpInfo } = require("./lib/net/bili");
const { HttpsProxyAgent } = require("https-proxy-agent");
const request = require("https");
const metainfo = [
' _ _ _ _____ _ _ ',
' | | | | | | / ____| (_) | | ',
@ -23,6 +35,15 @@ let ck_flag = 0;
/**
* @returns {Promise<string>} 错误信息
*/
async function printIpInfo(beforeProxy) {
const printMessage = beforeProxy ? '当前IP----->' : '代理后IP=======>';
await getIpInfo().then(res => {
console.log(printMessage + res);
}).catch((err) => {
console.error('获取' + printMessage + '地址失败', err);
});
}
async function main() {
const { COOKIE, NUMBER, CLEAR, ENABLE_MULTIPLE_ACCOUNT, MULTIPLE_ACCOUNT_PARM } = process.env;
if (ENABLE_MULTIPLE_ACCOUNT) {
@ -32,12 +53,24 @@ async function main() {
process.env.ENABLE_MULTIPLE_ACCOUNT = '';
const request = require('https');
for (const acco of muti_acco) {
process.env.COOKIE = acco.COOKIE;
process.env.NUMBER = acco.NUMBER;
process.env.CLEAR = acco.CLEAR;
process.env.NOTE = acco.NOTE;
process.env.ACCOUNT_UA = acco.ACCOUNT_UA;
if (acco.PROXY_HOST) {
await printIpInfo(true);
//http://ip:port
//http://user:pwd@ip:port'
const proxyUrl = acco.PROXY_USER
? 'http://' + acco.PROXY_USER + ':' + acco.PROXY_PASS + '@' + acco.PROXY_HOST + ':' + acco.PROXY_PORT
: 'http://' + acco.PROXY_HOST + ':' + acco.PROXY_PORT;
request.globalAgent = new HttpsProxyAgent(proxyUrl);
await printIpInfo(false);
}
const err_msg = await main();
if (err_msg) {
return err_msg;
@ -50,6 +83,7 @@ async function main() {
}
}
/**多账号状态还原 */
process.env.ENABLE_MULTIPLE_ACCOUNT = ENABLE_MULTIPLE_ACCOUNT;
} else if (COOKIE) {
@ -65,7 +99,12 @@ async function main() {
const mode = process.env.lottery_mode;
const help_msg = '用法: lottery [OPTIONS]\n\nOPTIONS:\n\tstart 启动抽奖\n\tcheck 中奖检查\n\tacount 查看帐号信息\n\tclear 清理动态和关注\n\tlogin 扫码登录更新CK\n\tupdate 检查更新\n\thelp 帮助信息';
if (await checkCookie(NUMBER)) {
const { lottery_loop_wait, check_loop_wait, clear_loop_wait, save_lottery_info_to_file } = require('./lib/data/config');
const {
lottery_loop_wait,
check_loop_wait,
clear_loop_wait,
save_lottery_info_to_file
} = require('./lib/data/config');
ck_flag = 1;
switch (mode) {
case 'start':