Skip to content

Commit

Permalink
页面支持配置监听;一些小优化;
Browse files Browse the repository at this point in the history
  • Loading branch information
cxOrz committed Apr 2, 2023
1 parent 52ce44c commit 4d9a119
Show file tree
Hide file tree
Showing 21 changed files with 693 additions and 239 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ pnpm start

除了简单的 `pnpm start` 来手动签到,也可以部署到服务器使用网页版本,别忘了这也是个 Web 项目。

- 前端界面,查看 [前端](/apps/web) 的说明
- 后端服务,查看 [服务端](/apps/server) 的说明
- 前端界面,查看 [前端](/apps/web) 的详细说明
- 后端服务,查看 [服务端](/apps/server) 的详细说明

### 一键运行

Expand All @@ -121,7 +121,7 @@ docker run -d -p 80:80 -p 5000:5000 chaoxing-sign-cli
演示地址:https://prod.d6afmntd8nh5y.amplifyapp.com (海外服务器较慢,功能阉割仅供演示UI)

![](https://cxorz.blob.core.windows.net/static-files/ui-start.png)
![](https://cxorz.blob.core.windows.net/static-files/ui-qrcode-sign.png)
![](https://cxorz.blob.core.windows.net/static-files/ui-config.webp)

## 贡献须知

Expand Down
26 changes: 0 additions & 26 deletions apps/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,6 @@ pnpm start

【注意】对 src 目录下任何文件做出修改后,需重新构建才可生效!

## 接口服务

运行 `pnpm serve` 将启动接口服务,接下来描述每个接口的参数以及调用方式:

<details>
<summary>展开接口详情</summary>

|路径|请求方式|参数|内容类型|返回内容|
|-|-|-|-|-|
|/|GET|||\< String \>|
|/login|POST|phone, password|JSON|\< String \>|
|/activity|POST|uf, _d, vc3, uid|JSON|JSON|
|/uvtoken|POST|uf, _d, vc3, uid|JSON|\< String \>|
|/qrcode|POST|uf, _d, vc3, name, activeId, uid, fid, enc|JSON|待填|
|/location|POST|uf, _d, vc3, name, activeId, uid, fid, address, lat, lon|JSON|待填|
|/general|POST|uf, _d, vc3, name, activeId, uid, fid|JSON|待填|
|/photo|POST|uf, _d, vc3, name, activeId, uid, fid, objectId|JSON|待填|
|/upload|POST|uf, _d, vc3, uid, file, ?_token|multipart/form-data|待填|
|/qrocr|POST|file|multipart/form-data|\< String \>|
|/monitor/status|POST|phone|JSON|JSON|
|/monitor/start|POST|phone, uf, _d, vc3, uid, lv, fid|JSON|JSON|
|/monitor/stop|POST|phone|JSON|JSON|

</details>

## 最佳实践

部署在服务器,步骤如下:
Expand All @@ -56,7 +31,6 @@ pnpm start

还有一些事情必需知道:

- 如果要通过UI点击按钮启动监听功能,则要在运行接口服务之前,先运行多次 `pnpm monitor` 来配置每一个使用监听的用户的信息(一个用户一份配置,不配置无法使用UI启动监听),看到 "监听中",即可终止程序,该用户信息已经写入本地。配置完成后,就可以运行 `pnpm serve` 来启动接口了。
- 如果使用腾讯文字识别来解析二维码,请在 `src/env.json` 文件中配置 secretId 和 secretKey,然后重新构建代码。

<details>
Expand Down
5 changes: 2 additions & 3 deletions apps/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "server",
"version": "4.2.5",
"version": "4.3.5",
"description": "超星学习通签到项目",
"scripts": {
"build": "tsc && node ./src/scripts/cplibs.js",
Expand All @@ -14,7 +14,7 @@
},
"dependencies": {
"@koa/router": "^12.0.0",
"crypto-js": "^4.1.1",
"crypto-js": "workspace:*",
"form-data": "^4.0.0",
"jsdom": "^20.0.0",
"koa": "^2.13.4",
Expand All @@ -28,7 +28,6 @@
"ws": "^8.8.1"
},
"devDependencies": {
"@types/crypto-js": "^4.1.1",
"@types/jsdom": "^20.0.0",
"@types/koa": "^2.13.5",
"@types/koa-bodyparser": "^4.3.7",
Expand Down
1 change: 0 additions & 1 deletion apps/server/src/env.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"env": {
"dev": false,
"SERVERLESS": false
},
"tencent": {
Expand Down
32 changes: 19 additions & 13 deletions apps/server/src/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ async function configure(phone: string) {
monitor.lon = response.lon;
monitor.lat = response.lat;
monitor.address = response.address;
mailing.enabled = response.mail;
mailing.host = response.host;
mailing.ssl = response.ssl;
mailing.port = response.port;
Expand Down Expand Up @@ -334,15 +335,20 @@ async function handleMsg(this: CQ, data: string) {
// 开始运行
(async () => {
let params: any = {};
// 若凭证由命令参数传来,直接赋值;否则,直接用户名密码登录获取凭证
let config: any = {};
// 若凭证由命令参数传来,直接解析赋值;否则,直接用户名密码登录获取凭证
if (process.argv[2] === '--auth') {
params.uf = process.argv[3];
params._d = process.argv[4];
params.vc3 = process.argv[5];
params._uid = process.argv[6];
params.lv = process.argv[7];
params.fid = process.argv[8];
params.phone = process.argv[9];
const auth_config = JSON.parse(Buffer.from(process.argv[4], 'base64').toString('utf8'));
params.phone = auth_config.credentials.phone;
params.uf = auth_config.credentials.uf;
params._d = auth_config.credentials._d;
params.vc3 = auth_config.credentials.vc3;
params._uid = auth_config.credentials.uid;
params.lv = auth_config.credentials.lv;
params.fid = auth_config.credentials.fid;
config.monitor = { ...auth_config.config.monitor };
config.mailing = { ...auth_config.config.mailing };
config.cqserver = { ...auth_config.config.cqserver };
} else {
// 打印本地用户列表,并返回用户数量
const userItem = (
Expand All @@ -366,10 +372,10 @@ async function handleMsg(this: CQ, data: string) {
params = user.params;
params.phone = user.phone;
}
// 手动配置签到信息
config = await configure(params.phone);
}

// 配置签到信息
const config = await configure(params.phone);
// 获取IM参数
const IM_Params = await getIMParams(params as UserCookieType);
if (IM_Params === 'AuthFailed') {
Expand Down Expand Up @@ -426,7 +432,7 @@ async function handleMsg(this: CQ, data: string) {
chatId: message?.to,
});
// 邮件推送签到结果
if (config.mailing?.to) {
if (config.mailing?.enabled) {
sendEmail({
aid: IM_CourseInfo.aid,
uid: params._uid,
Expand All @@ -436,7 +442,7 @@ async function handleMsg(this: CQ, data: string) {
});
}
// CQ 推送签到结果
if (config.cqserver.cq_enabled) {
if (config.cqserver?.cq_enabled) {
cq.send(`${result} - ${IM_Params.myName}`, config.cqserver.target_id);
}

Expand All @@ -448,5 +454,5 @@ async function handleMsg(this: CQ, data: string) {
},
});

console.log(blue(`[监听中] ${config.cqserver.cq_enabled ? 'CQ服务器已连接' : ''} ${config.mailing?.to ? '邮件推送已开启' : ''}...`));
console.log(blue(`[监听中] ${config.cqserver.cq_enabled ? 'CQ服务器已连接' : ''} ${config.mailing?.enabled ? '邮件推送已开启' : ''}...`));
})();
27 changes: 15 additions & 12 deletions apps/server/src/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ router.post('/monitor/status', (ctx) => {
}
});

router.post('/monitor/stop', (ctx) => {
const { phone } = ctx.request.body as any;
router.post('/monitor/stop/:phone', (ctx) => {
const phone = ctx.params.phone;
const process_monitor = processMap.get(phone);
if (process_monitor !== undefined) {
process_monitor.kill('SIGKILL');
Expand All @@ -260,22 +260,25 @@ router.post('/monitor/stop', (ctx) => {
ctx.body = '{"code":201,"msg":"Suspended"}';
});

router.post('/monitor/start', async (ctx) => {
const { phone, uf, _d, vc3, uid, lv, fid } = ctx.request.body as any;
if (processMap.get(phone) !== undefined) {
// base64字串需包含 credentials, monitor, mailing, cqserver 内容
router.post('/monitor/start/:phone', async (ctx) => {
if (processMap.get(ctx.params.phone) !== undefined) {
ctx.body = '{"code":200,"msg":"Already started"}';
return;
}
const process_monitor = fork(ENVJSON.env.dev ? 'monitor.ts' : 'monitor.js', ['--auth', uf, _d, vc3, uid, lv, fid, phone], {
cwd: __dirname,
detached: false,
stdio: [null, null, null, 'ipc'],
});
const process_monitor = fork(process.argv[1].endsWith('ts') ? 'monitor.ts' : 'monitor.js',
['--auth', ctx.params.phone, ctx.request.rawBody],
{
cwd: __dirname,
detached: false,
stdio: [null, null, null, 'ipc'],
}
);
const response = await new Promise((resolve) => {
process_monitor.on('message', (msg) => {
switch (msg) {
case 'success': {
processMap.set(phone, process_monitor);
processMap.set(ctx.params.phone, process_monitor);
resolve('{"code":200,"msg":"Started Successfully"}');
break;
}
Expand All @@ -293,7 +296,7 @@ router.post('/monitor/start', async (ctx) => {
ctx.body = response;
});

app.use(bodyparser());
app.use(bodyparser({ enableTypes: ['json', 'form', 'text'] }));
app.use(async (ctx, next) => {
ctx.set('Access-Control-Allow-Origin', '*');
ctx.set('Access-Control-Allow-Headers', 'Content-Type');
Expand Down
3 changes: 3 additions & 0 deletions apps/web/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports = {
root: true,
extends: ['custom'],
rules: {
'react/prop-types': 0
}
};
20 changes: 11 additions & 9 deletions apps/web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@

`src/config/api.ts` :该文件中配置 `baseUrl` 变量为接口地址,默认 `http://localhost:5000` 。若接口部署在服务器,不要忘记将接口地址改为服务器IP或绑定的域名。

`src/pages/DashBoard/Helper.ts` :若使用腾讯云的通用文字识别服务,二维码识别成功率极高,支持PNG、JPG、JPEG、PDF等格式,图片大小不能超过7M。查看此源码文件中的 parseEnc 函数,可注释掉默认函数,使用推荐函数,同时需要在CLI项目中的 `env.json` 中配置 `secretId``secretKey`
`src/pages/DashBoard/Helper.ts` :若使用腾讯云的通用文字识别服务,二维码识别成功率极高,支持PNG、JPG、JPEG、PDF等格式,图片大小不能超过7M。查看此源码文件中的 parseEnc 函数,可注释掉默认函数,使用推荐函数,同时需要在 `apps/server` 项目中的 `env.json` 中配置 `secretId``secretKey`

## 最佳实践
## 使用

使用 [腾讯云开发-静态网站托管](https://console.cloud.tencent.com/tcb/hosting),将构建的网页部署进去。
### 添加用户
在首页,点击 + 号按钮,输入手机号和密码即可登录,登陆成功后你的卡片将会出现在首页。

步骤:
1. 确认已进行过必要的配置,例如接口地址、文字识别服务。
2. 在 web 目录下运行 `pnpm build`,将构建网页并输出到 web/dist 目录下。
3. 将 dist 目录内的所有内容(不包括dist文件夹),在静态网站托管页面上传。
4. 通过云开发的默认域名即可访问。
### 移除用户
右键你想要移除的用户卡片,点击移除。

![](https://cxorz.blob.core.windows.net/static-files/tcb-hosting.png)
### 手动签到
点击用户卡片,然后点击开始,根据提示签到即可。

### 配置监听
右键你想要配置的用户卡片,点击监听配置,在弹出的窗口中填写签到信息、邮件信息配置、QQ机器人配置,确认即可保存。保存后,即可点击卡片上的监听,运行监听模式。
5 changes: 3 additions & 2 deletions apps/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web",
"version": "2.5.8",
"version": "2.7.0",
"private": true,
"type": "module",
"scripts": {
Expand All @@ -18,7 +18,8 @@
"axios": "^0.26.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "6.3.0"
"react-router-dom": "6.3.0",
"crypto-js": "workspace:*"
},
"devDependencies": {
"@types/react": "^18.0.15",
Expand Down
Loading

0 comments on commit 4d9a119

Please sign in to comment.