mirror of
https://github.com/shanmiteko/LotteryAutoScript.git
synced 2026-06-04 21:01:17 +08:00
feat: 扫码登录获取移动端的CK更新账号,带sid可减小掉号频率
This commit is contained in:
parent
ddcfceecef
commit
288851b491
@ -122,6 +122,7 @@ buvid3亦可不填 使用随机生成值
|
|||||||
acount 查看帐号信息
|
acount 查看帐号信息
|
||||||
clear 清理动态和关注
|
clear 清理动态和关注
|
||||||
update 检查更新
|
update 检查更新
|
||||||
|
login 扫码登录自动更新CK
|
||||||
help 帮助信息
|
help 帮助信息
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
const { login } = require('./login');
|
||||||
const { isMe } = require('./check');
|
const { isMe } = require('./check');
|
||||||
const { clear } = require('./clear');
|
const { clear } = require('./clear');
|
||||||
const { start } = require('./lottery');
|
const { start } = require('./lottery');
|
||||||
@ -24,4 +25,4 @@ async function checkCookie(num) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = { start, isMe, clear, checkCookie, account }
|
module.exports = { login, start, isMe, clear, checkCookie, account }
|
||||||
65
lib/login.js
Normal file
65
lib/login.js
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
const { readFileSync, writeFileSync } = require('fs');
|
||||||
|
const { log } = require("./utils");
|
||||||
|
const path = require('path');
|
||||||
|
const env_path = path.join(path.resolve(__dirname, '..'), "env.js")
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 扫码登陆
|
||||||
|
* @param {string} num
|
||||||
|
*/
|
||||||
|
async function login(num) {
|
||||||
|
try {
|
||||||
|
const { pcLogin } = await require('@catlair/blogin');
|
||||||
|
const loginInfo = await pcLogin();
|
||||||
|
if (!loginInfo) {
|
||||||
|
log.error("登录状态","失败/取消");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log.info("登录状态","登录成功");
|
||||||
|
JSON.stringify(loginInfo, null, 2);
|
||||||
|
const uid = `${loginInfo.mid}`;
|
||||||
|
const cookie = `${loginInfo.cookie}`;
|
||||||
|
log.info("账号UID", uid);
|
||||||
|
log.info("cookie", cookie);
|
||||||
|
if (replaceCookie(env_path, uid, cookie)) {
|
||||||
|
log.info("说明",`账号${num}已进行cookie自动更新,如未能生效请手动复制在env.js内替换。路径:${env_path}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (error?.message?.includes('Cannot find module')) {
|
||||||
|
log.error('请先运行 yarn add @catlair/blogin');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 正则检索uid更新cookie
|
||||||
|
* @param {string} filePath
|
||||||
|
* @param {string} uid
|
||||||
|
* @param {string} oldCK
|
||||||
|
*/
|
||||||
|
async function replaceCookie(filePath,uid,oldCK) {
|
||||||
|
try {
|
||||||
|
const content = readFileSync(filePath, 'utf-8');
|
||||||
|
const DedeUserID = `DedeUserID=${uid}`;
|
||||||
|
const reg = new RegExp(`['"]?COOKIE['"]?:\\s?['"](.*${DedeUserID}.*)['"]`, 'g');
|
||||||
|
const newCK = content.replaceAll(reg, substring => {
|
||||||
|
let quote = substring.at(0) || '';
|
||||||
|
/['"]/.test(quote) || (quote = '');
|
||||||
|
const quote2 = oldCK.includes("'")
|
||||||
|
? '"'
|
||||||
|
: substring.match(/^['"]?COOKIE['"]?:\s?(['"])/)?.[1] || '"';
|
||||||
|
return `${quote}COOKIE${quote}: ${quote2}${oldCK}${quote2}`;
|
||||||
|
});
|
||||||
|
if (content === newCK) return false;
|
||||||
|
writeFileSync(filePath, newCK);
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
log.error("替换错误",error);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { login }
|
||||||
8
main.js
8
main.js
@ -1,4 +1,5 @@
|
|||||||
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 {lottery_loop_wait} = require("./lib/data/config");
|
||||||
|
|
||||||
const metainfo = [
|
const metainfo = [
|
||||||
` _ _ _ _____ _ _ `,
|
` _ _ _ _____ _ _ `,
|
||||||
@ -49,7 +50,7 @@ async function main() {
|
|||||||
await global_var.init(COOKIE, NUMBER);
|
await global_var.init(COOKIE, NUMBER);
|
||||||
|
|
||||||
/**引入基础功能 */
|
/**引入基础功能 */
|
||||||
const { start, isMe, clear, account, checkCookie } = require("./lib/index");
|
const { start, isMe, clear, account, checkCookie, login } = require("./lib/index");
|
||||||
|
|
||||||
log.info('main', '当前为第' + NUMBER + '个账号');
|
log.info('main', '当前为第' + NUMBER + '个账号');
|
||||||
log._cache.length = 0
|
log._cache.length = 0
|
||||||
@ -79,6 +80,11 @@ async function main() {
|
|||||||
await clear();
|
await clear();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'login':
|
||||||
|
log.info('登陆', '开始扫码');
|
||||||
|
loop_wait = lottery_loop_wait;
|
||||||
|
await login(NUMBER);
|
||||||
|
break;
|
||||||
case 'help':
|
case 'help':
|
||||||
return help_msg
|
return help_msg
|
||||||
case 'account':
|
case 'account':
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
"description": "自动参与B站动态抽奖",
|
"description": "自动参与B站动态抽奖",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"login": "node main.js login",
|
||||||
"start": "node main.js start",
|
"start": "node main.js start",
|
||||||
"test": "node test/index.js",
|
"test": "node test/index.js",
|
||||||
"clear": "node main.js clear",
|
"clear": "node main.js clear",
|
||||||
@ -46,6 +47,7 @@
|
|||||||
"chalk": "^4.1.2",
|
"chalk": "^4.1.2",
|
||||||
"http-proxy-agent": "^7.0.0",
|
"http-proxy-agent": "^7.0.0",
|
||||||
"https-proxy-agent": "^7.0.0",
|
"https-proxy-agent": "^7.0.0",
|
||||||
"nodemailer": "^6.7.0"
|
"nodemailer": "^6.7.0",
|
||||||
|
"@catlair/blogin": "^0.0.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ for file in "$TARGET_DIR/"*; do
|
|||||||
cp $TEMPLATE_CONFIG_FILE "$TMPDIR.d/$CONFIG_FILE"
|
cp $TEMPLATE_CONFIG_FILE "$TMPDIR.d/$CONFIG_FILE"
|
||||||
cp $TEMPLATE_ENV_FILE "$TMPDIR.d/$ENV_FILE"
|
cp $TEMPLATE_ENV_FILE "$TMPDIR.d/$ENV_FILE"
|
||||||
if [ "$(echo $file | grep '.exe')" ]; then
|
if [ "$(echo $file | grep '.exe')" ]; then
|
||||||
BATS=("start" "check" "clear" "account" "update")
|
BATS=("start" "check" "clear" "account" "update" "login")
|
||||||
for item in "${BATS[@]}"; do
|
for item in "${BATS[@]}"; do
|
||||||
create_win_bat "${item}" >"$TMPDIR.d/$item.bat"
|
create_win_bat "${item}" >"$TMPDIR.d/$item.bat"
|
||||||
done
|
done
|
||||||
|
|||||||
@ -188,3 +188,25 @@ docker image rm -f shanmite/lottery_auto_docker
|
|||||||
echo "see you next time!"
|
echo "see you next time!"
|
||||||
EOF
|
EOF
|
||||||
chmod +x remove_all.sh
|
chmod +x remove_all.sh
|
||||||
|
|
||||||
|
echo "create login.sh"
|
||||||
|
cat >login.sh <<EOF
|
||||||
|
#!$(which env) bash
|
||||||
|
NAME=shanmite-lottery-login
|
||||||
|
if [[ -z "\$(docker ps -a | grep \$NAME)" ]]; then
|
||||||
|
docker run \\
|
||||||
|
-v $PWD/$ENV_FILE:/lottery/$ENV_FILE \\
|
||||||
|
-v $PWD/$CONFIG_FILE:/lottery/$CONFIG_FILE \\
|
||||||
|
--network host \\
|
||||||
|
--name \$NAME \\
|
||||||
|
$DOCKER_REPO \\
|
||||||
|
login
|
||||||
|
else
|
||||||
|
echo "container \$NAME already existed"
|
||||||
|
echo "history logs -> docker logs \$NAME"
|
||||||
|
echo "close this -> docker stop \$NAME"
|
||||||
|
echo "login \$NAME"
|
||||||
|
docker login \$NAME
|
||||||
|
fi
|
||||||
|
EOF
|
||||||
|
chmod +x login.sh
|
||||||
@ -40,6 +40,7 @@ create start
|
|||||||
create check
|
create check
|
||||||
create clear
|
create clear
|
||||||
create account
|
create account
|
||||||
|
create login
|
||||||
|
|
||||||
cd $NAME
|
cd $NAME
|
||||||
npm i
|
npm i
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user