Skip to content

Commit

Permalink
feat: 增加多账号的代理 (#433)
Browse files Browse the repository at this point in the history
* feat=>增加多账号的代理

* feat=>增加多账号的代理

* fix=>变量声明
  • Loading branch information
amadeus5201 authored Jan 16, 2025
1 parent 717d8cf commit 1832f6d
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 12 deletions.
6 changes: 5 additions & 1 deletion env.example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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密码
}
],

Expand Down
35 changes: 28 additions & 7 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const utils = {
return _c(restNum - 1, argsList.concat(x));
};
}

return _c(func.length, []);
},
/**
Expand All @@ -121,7 +122,9 @@ const utils = {
let c = {
i: 0,
next: () => c.i++,
clear: () => { c.i = 0; },
clear: () => {
c.i = 0;
},
value: () => c.i
};
return c;
Expand All @@ -130,7 +133,7 @@ const utils = {
* 无限序列
* `[0..]`
*/
*infiniteNumber() {
* infiniteNumber() {
for (let index = 0; ; index++) {
yield index;
}
Expand Down Expand Up @@ -178,7 +181,7 @@ const utils = {
/**
* 是否有指定环境变量
* @param {string} env_name
* @returns
* @returns
*/
hasEnv(env_name) {
return process.env[env_name] ? true : false;
Expand Down Expand Up @@ -278,7 +281,7 @@ const utils = {
},
/**
* 验证码识别
* @param {string} url
* @param {string} url
* @returns {Promise<string>}
*/
ocr(url) {
Expand Down Expand Up @@ -340,7 +343,7 @@ const utils = {
/**
* 是否存在文件或目录
* @param {string} path
* @returns
* @returns
*/
hasFileOrDir(path) {
try {
Expand Down Expand Up @@ -414,7 +417,7 @@ const utils = {
/**
* 追加lotteryinfo
* @param {string} from
* @param {import("./core/searcher").LotteryInfo[]} lottery_info
* @param {import('./core/searcher').LotteryInfo[]} lottery_info
* @return {Promise<void>}
*/
async appendLotteryInfoFile(from, lottery_info) {
Expand All @@ -435,7 +438,7 @@ const utils = {
/**
* 读取lottery_info
* @param {string} filename
* @return {Promise<import("./core/searcher").LotteryInfo[]>}
* @return {Promise<import('./core/searcher').LotteryInfo[]>}
*/
readLotteryInfoFile(filename) {
return new Promise((resolve) => {
Expand Down Expand Up @@ -471,6 +474,24 @@ const utils = {
}
});
});
},
getIpInfo() {
return new Promise((resolve) => {
send({
url: 'https://myip.qq.com/',
method: 'GET',
success: res => resolve(res.body),
failure: err => resolve(err)
});
});
},
printIpInfo(beforeProxy) {
const printMessage = beforeProxy ? '当前IP----->' : '代理后IP=======>';
utils.getIpInfo().then(res => {
console.log(printMessage + res);
}).catch((err) => {
console.error('获取' + printMessage + '地址失败', err);
});
}
};

Expand Down
37 changes: 33 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
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, printIpInfo
} = require('./lib/utils');
const { HttpsProxyAgent } = require('https-proxy-agent');
const request = require('https');
const metainfo = [
' _ _ _ _____ _ _ ',
' | | | | | | / ____| (_) | | ',
Expand Down Expand Up @@ -31,13 +41,27 @@ async function main() {
: JSON.parse(MULTIPLE_ACCOUNT_PARM);

process.env.ENABLE_MULTIPLE_ACCOUNT = '';
let localhost = request.globalAgent;

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) {
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);
printIpInfo(false);
}else {
//未设置还原
request.globalAgent = localhost;
}
const err_msg = await main();
if (err_msg) {
return err_msg;
Expand All @@ -48,8 +72,8 @@ async function main() {
await delay(3 * 1000);
}
}
request.globalAgent = localhost;
}

/**多账号状态还原 */
process.env.ENABLE_MULTIPLE_ACCOUNT = ENABLE_MULTIPLE_ACCOUNT;
} else if (COOKIE) {
Expand All @@ -65,7 +89,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':
Expand Down

0 comments on commit 1832f6d

Please sign in to comment.