Skip to content

Commit 427a529

Browse files
author
develop202
committed
添加自动更新
1 parent a9a4401 commit 427a529

5 files changed

Lines changed: 103 additions & 61 deletions

File tree

.github/workflows/qrcodeLogin.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
name: qrcodeLogin
22
on:
33
workflow_dispatch:
4-
# push:
5-
# schedule:
6-
# - cron: 1 16 * * *
4+
inputs:
5+
number:
6+
description: "需要登录几个账号?"
7+
required: true
8+
default: 1
79
jobs:
810
run:
911
runs-on: ubuntu-latest
10-
timeout-minutes: 3
1112
steps:
1213
- name: 检出仓库
1314
uses: actions/checkout@v3
@@ -17,6 +18,17 @@ jobs:
1718
node-version: 18
1819
cache: 'npm'
1920
cache-dependency-path: ./api/package-lock.json
21+
- name: 🔧 安装GitHub CLI,并使用PAT登录
22+
if: ${{ secrets.PAT != '' }}
23+
run: |
24+
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
25+
sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
26+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
27+
sudo apt update
28+
sudo apt install gh -y
29+
gh --version
30+
echo "${{ secrets.PAT }}" | gh auth login --with-token
31+
gh auth status
2032
- name: Cache node_modules in api directory
2133
id: cache-npm
2234
uses: actions/cache@v3
@@ -30,3 +42,7 @@ jobs:
3042
if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }}
3143
- name: 二维码登录
3244
run: npm run qrcodeLogin
45+
env:
46+
NUMBER: ${{ github.event.inputs.number }}
47+
PAT: ${{ secrets.PAT }}
48+
GITHUB_REPOSITORY: ${{ github.repository }}

README.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ GitHub Actions 实现 `酷狗概念VIP` 自动签到
66
提供二维码登录(推荐)和手机号登录(一个手机号绑定多个账号无法登录,见 [多账号登录问题](https://github.com/MakcRe/KuGouMusicApi/issues/51))
77

88
感谢 [@itfw](https://github.com/itfw) 提供二维码显示问题的解决方案
9+
感谢 [@klaas8](https://github.com/klaas8) 提供自动写入secret的方法
910

1011
> [!warning]
1112
> 注意事项
@@ -31,14 +32,28 @@ GitHub Actions 实现 `酷狗概念VIP` 自动签到
3132
1. 登录
3233

3334
2.1 二维码(推荐)
35+
自动写入secret(可选)
36+
- **创建令牌**
37+
复制下方官网链接,在浏览器中打开
3438

35-
运行 Actions `QRcodeLogin` 并进入(若不显示,可以刷新页面),点击run -> 展开二维码登录, 根据提示操作即可。复制 `token``userid`
39+
```
40+
https://github.com/settings/tokens/new
41+
```
3642
37-
2.2 手机号
43+
- **登录 GitHub 官网**
44+
若登陆后未跳转至token生成页,请再次粘贴链接进行访问
45+
- **在设置页面配置权限**
46+
**Note 备注**:随意填写
47+
**Expiration (有效期)**:建议选择 "No expiration" 永不过期或自定义时间
48+
**Select scopes (权限)**:所有勾选框都打勾
49+
- 滑动到底部,点击绿色的 Generate token 保存按钮
50+
- 复制生成的字符串 (ghp\_开头),回到本仓库添加到`Secret` 变量名 `PAT` value `复制的令牌`
51+
52+
填入登录账号数量,运行 Actions `qrcodeLogin` 并进入(若不显示,可以刷新页面),点击run -> 展开二维码登录, 根据提示操作即可。
3853
39-
添加手机号到 Secret `PHONE`,运行 Actions `sent` 获取验证码,把验证码添加到 Secret `CODE`;运行Actions `phoneLogin`,复制 `token``userid`
54+
2.2 手机号
4055
41-
1.`userid``token` 添加到 Secret `USERINFO` 格式如下, 注意删掉换行
56+
添加手机号到 Secret `PHONE`,运行 Actions `sent` 获取验证码,把验证码添加到 Secret `CODE`;运行Actions `phoneLogin`,复制 `token` 和 `userid` 添加到 Secret `USERINFO`格式如下, 注意删去换行,否则会多出一些字符,但是不影响签到
4257
4358
> ```json
4459
> [

main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async function main() {
3333
// 开始听歌
3434
printYellow(`开始每日听歌领取VIP...`)
3535
// 听歌获取vip
36-
let listen = await send(`/youth/listen/song?timestrap=${Date.now()}`, "GET", headers)
36+
const listen = await send(`/youth/listen/song?timestrap=${Date.now()}`, "GET", headers)
3737

3838
if (listen.status === 1) {
3939
printGreen("每日听歌领取成功")

phoneLogin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ async function login() {
77

88
// 不使用二维码登录并且没有手机号或验证码
99
if (!phone || !code) {
10-
throw new Error("参数错误!请检查")
10+
throw new Error("未配置")
1111
}
1212
// 启动服务
1313
const api = startService()

qrcodeLogin.js

Lines changed: 62 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,79 @@
1+
import { execSync } from "child_process";
12
import { close_api, delay, send, startService } from "./utils/utils.js";
23

34
async function qrcode() {
45

56
// 启动服务
6-
let api = startService()
7+
const api = startService()
78
await delay(2000)
89
let qrcode = ""
10+
const userinfo = []
11+
const args = process.argv.slice(2);
12+
const number = parseInt(process.env.NUMBER || args[0] || "1")
13+
const pat = process.env.PAT
914
try {
10-
// 二维码
11-
let result = await send(`/login/qr/key`, "GET", {})
12-
if (result.status === 1) {
13-
console.log("下面是二维码链接,请复制到浏览器打开扫描并确定登录")
14-
qrcode = result.data.qrcode
15-
// console.log(result.data.qrcode)
16-
// console.log(result.data.qrcode_img)
17-
const img_base64 = result.data.qrcode_img;
18-
const chunkSize = 1000;
19-
for (let i = 0; i < img_base64.length; i += chunkSize) {
20-
console.log(img_base64.slice(i, i + chunkSize));
15+
for (let i = 0; i < number; i++) {
16+
// 二维码
17+
const result = await send(`/login/qr/key?timestrap=${Date.now()}`, "GET", {})
18+
if (result.status === 1) {
19+
qrcode = result.data.qrcode
20+
const img_base64 = result.data.qrcode_img;
21+
const chunkSize = 1000;
22+
console.log("二维码链接如下, 请在浏览器打开使用APP扫描并确认登录")
23+
for (let i = 0; i < img_base64.length; i += chunkSize) {
24+
console.log(img_base64.slice(i, i + chunkSize));
25+
}
26+
} else {
27+
console.log("响应内容")
28+
console.dir(result, { depth: null })
29+
throw new Error("请求出错")
2130
}
22-
} else {
23-
console.log("响应内容")
24-
console.dir(result, { depth: null })
25-
throw new Error("请求失败!请检查")
26-
}
31+
console.log("正在等待,请扫描二维码并确定登录")
32+
// 登录
33+
for (let i = 0; i < 25; i++) {
34+
const timestrap = Date.now();
35+
const res = await send(`/login/qr/check?key=${qrcode}&timestrap=${timestrap}`, "GET", {})
36+
const status = res?.data?.status
37+
switch (status) {
38+
case 0:
39+
console.log("二维码已过期")
40+
break
2741

28-
console.log()
29-
console.log("正在等待,请扫描二维码并确定登录")
30-
if (qrcode == "") {
31-
throw new Error("二维码异常")
32-
}
33-
// 登录
34-
let logined = false
35-
for (let i = 0; i < 50; i++) {
36-
const timestrap = Date.now();
37-
const res = await send(`/login/qr/check?key=${qrcode}&timestrap=${timestrap}`, "GET", {})
38-
const status = res?.data?.status
39-
switch (status) {
40-
case 0:
41-
console.log("二维码已过期")
42-
break
42+
case 1:
43+
// console.log("未扫描二维码")
44+
break
4345

44-
case 1:
45-
// console.log("未扫描二维码")
46+
case 2:
47+
// console.log("二维码未确认,请点击确认登录")
48+
break
49+
case 4:
50+
console.log("登录成功!")
51+
userinfo.push({
52+
userid: res.data.userid,
53+
token: res.data.token
54+
})
55+
break;
56+
default:
57+
console.log("请求出错")
58+
console.dir(res, { depth: null })
59+
}
60+
if (status == 4 || status == 0) {
4661
break
47-
48-
case 2:
49-
// console.log("二维码未确认,请点击确认登录")
62+
}
63+
if (i == 24) {
64+
console.log("等待超时\n")
5065
break
51-
case 4:
52-
logined = true
53-
console.log("登录成功!")
54-
console.log("第一行是token,第二行是userid")
55-
console.log(res.data.token)
56-
console.log(res.data.userid)
57-
break;
58-
default:
59-
console.log("请求出错。")
60-
console.dir(res, { depth: null })
61-
}
62-
if (logined) {
63-
break
66+
}
67+
await delay(5000)
6468
}
65-
await delay(2000)
69+
}
70+
const userinfoJSON = JSON.stringify(userinfo)
71+
if (pat) {
72+
execSync(`gh secret set USERINFO -b"${userinfoJSON}" --repo ${process.env.GITHUB_REPOSITORY}`);
73+
console.log("secret <USERINFO> 更改成功")
74+
} else {
75+
console.log("登录信息如下,把它添加到secret USERINFO 即可")
76+
console.log(userinfoJSON)
6677
}
6778
} finally {
6879
close_api(api)

0 commit comments

Comments
 (0)