mirror of
https://github.com/shanmiteko/LotteryAutoScript.git
synced 2026-06-04 21:01:17 +08:00
docs: 扫码登陆使用说明
This commit is contained in:
parent
c238c27d7d
commit
83e19d44e3
10
README.md
10
README.md
@ -3,6 +3,8 @@
|
|||||||
- [AutoScript](#autoscript)
|
- [AutoScript](#autoscript)
|
||||||
- [操作步骤](#操作步骤)
|
- [操作步骤](#操作步骤)
|
||||||
- [获取COOKIE](#获取cookie)
|
- [获取COOKIE](#获取cookie)
|
||||||
|
- [扫码登陆](#扫码登陆)
|
||||||
|
- [手动获取](#手动获取)
|
||||||
- [本地运行](#本地运行)
|
- [本地运行](#本地运行)
|
||||||
- [可执行文件](#可执行文件)
|
- [可执行文件](#可执行文件)
|
||||||
- [以源码方式运行](#以源码方式运行)
|
- [以源码方式运行](#以源码方式运行)
|
||||||
@ -54,6 +56,14 @@
|
|||||||
|
|
||||||
### 获取COOKIE
|
### 获取COOKIE
|
||||||
|
|
||||||
|
#### 扫码登陆
|
||||||
|
|
||||||
|
在`env.js`文件填`COOKIE`的对应位置写入`"DedeUserID=你的UID"`即可使用`lottery login`扫码自动获取Cookie
|
||||||
|
|
||||||
|
`COOKIE`中包含`DedeUserID=你的UID`的都会被自动替换
|
||||||
|
|
||||||
|
#### 手动获取
|
||||||
|
|
||||||
进入[B站主页](https://www.bilibili.com/)获取Cookie用于登录
|
进入[B站主页](https://www.bilibili.com/)获取Cookie用于登录
|
||||||
|
|
||||||
Chrome浏览器:
|
Chrome浏览器:
|
||||||
|
|||||||
43
lib/login.js
43
lib/login.js
@ -1,44 +1,39 @@
|
|||||||
const { readFileSync, writeFileSync } = require('fs');
|
const { readFileSync, writeFileSync } = require('fs');
|
||||||
const { log, env_file} = require("./utils");
|
const { log, env_file } = require("./utils");
|
||||||
const env_path = env_file
|
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* 扫码登陆
|
* 扫码登陆
|
||||||
* @param {string} num
|
* @param {string} num
|
||||||
*/
|
*/
|
||||||
async function login(num) {
|
async function login(num) {
|
||||||
try {
|
try {
|
||||||
const { pcLogin } = await require('@catlair/blogin');
|
const { pcLogin } = require('@catlair/blogin');
|
||||||
const loginInfo = await pcLogin();
|
const loginInfo = await pcLogin();
|
||||||
if (!loginInfo) {
|
if (!loginInfo) {
|
||||||
log.error("登录状态","失败/取消");
|
log.error("扫码登陆", "失败/取消");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
log.info("登录状态","登录成功");
|
log.info("扫码登陆", "登录成功");
|
||||||
JSON.stringify(loginInfo, null, 2);
|
JSON.stringify(loginInfo, null, 2);
|
||||||
const uid = `${loginInfo.mid}`;
|
const uid = `${loginInfo.mid}`;
|
||||||
const cookie = `${loginInfo.cookie}`;
|
const cookie = `${loginInfo.cookie}`;
|
||||||
log.info("账号UID", uid);
|
log.info("账号UID", uid);
|
||||||
log.info("cookie", cookie);
|
log.info("Cookie", cookie);
|
||||||
if (await replaceCookie(env_path, uid, cookie)) {
|
if (replaceCookie(env_file, uid, cookie)) {
|
||||||
log.info("说明",`账号${num}已进行cookie自动更新,如未能生效请手动复制在env.js内替换。路径:${env_path}`);
|
log.info("扫码登陆", `账号${num}已进行cookie自动更新,如未能生效请手动复制在env.js内替换。路径:${env_file}`);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error?.message?.includes('Cannot find module')) {
|
|
||||||
log.error('请先运行 npm add @catlair/blogin');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
log.error(error);
|
log.error(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* 正则检索uid更新cookie
|
* 正则检索uid更新cookie
|
||||||
* @param {string} filePath
|
* @param {string} filePath
|
||||||
* @param {string} uid
|
* @param {string} uid
|
||||||
* @param {string} oldCK
|
* @param {string} oldCK
|
||||||
*/
|
*/
|
||||||
async function replaceCookie(filePath,uid,oldCK) {
|
function replaceCookie(filePath, uid, oldCK) {
|
||||||
try {
|
try {
|
||||||
const content = readFileSync(filePath, 'utf-8');
|
const content = readFileSync(filePath, 'utf-8');
|
||||||
const DedeUserID = `DedeUserID=${uid}`;
|
const DedeUserID = `DedeUserID=${uid}`;
|
||||||
@ -55,7 +50,7 @@ async function replaceCookie(filePath,uid,oldCK) {
|
|||||||
writeFileSync(filePath, newCK);
|
writeFileSync(filePath, newCK);
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error("替换错误",error);
|
log.error("扫码登陆", error);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user