Skip to content

Commit

Permalink
项目改用ESM模块化;实现IM协议自动监测签到;使用prompts改写交互部分;
Browse files Browse the repository at this point in the history
  • Loading branch information
cxOrz committed Jul 16, 2022
1 parent 39ea91c commit 8b1c765
Show file tree
Hide file tree
Showing 17 changed files with 472 additions and 175 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

基于 Nodejs 实现的一个签到命令行工具。

**功能**: 普通签到、拍照签到、手势签到、位置签到、签到码签到、二维码签到(10秒变换不影响),多用户凭据储存。
**功能**: 普通签到、拍照签到、手势签到、位置签到、签到码签到、二维码签到(10秒变换不影响),多用户凭据储存,IM 协议自动签到

**为确保你的代码最新与仓库保持同步,将在每次签到结束强制拉取代码更新**,如需关闭更新,请查看[issue2](https://github.com/cxOrz/chaoxing-sign-cli/issues/2#issuecomment-962781427),手动终止检查更新可在每次检查时连按 `Ctrl`+`C` 确认终止,更多功能正在开发 ...

Expand All @@ -25,15 +25,20 @@
git clone https://github.com/cxOrz/chaoxing-sign-cli.git
```

进入项目文件夹
进入项目文件夹,安装依赖

```bash
cd chaoxing-sign-cli
cd chaoxing-sign-cli && npm install
```

## 运行 ⚙
### 命令解释
- `npm start`:运行程序,若有签到则进行手动签到,若无则退出程序;
- `npm run serve`:启动接口服务;
- `npm run monitor`:监听模式,检测到签到将自动签上,无需人工干预;

执行以下命令即可

一般情况下执行以下命令即可满足基础使用

```bash
npm start
Expand Down
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
{
"name": "chaoxing-sign-cli",
"version": "2.4.5",
"version": "3.4.5",
"description": "超星学习通签到命令行工具",
"main": "index.js",
"scripts": {
"start": "(node ./src/index.js && echo \"正在检查更新,若等待时间过长请挂代理...(连按 Ctrl+C 终止)\" && git pull) || (echo \"正在检查更新,若等待时间过长请挂代理...(连按 Ctrl+C 终止)\" && git pull)",
"serve": "node ./src/serve.js"
"start": "(node --no-warnings ./src/index.js && echo \"正在检查更新,若等待时间过长请挂代理...(连按 Ctrl+C 终止)\" && git pull) || (echo \"正在检查更新,若等待时间过长请挂代理...(连按 Ctrl+C 终止)\" && git pull)",
"serve": "node --no-warnings ./src/serve.js",
"monitor": "node --no-warnings ./src/monitor.js"
},
"repository": "https://github.com/cxOrz/chaoxing-sign-cli.git",
"author": "mcx",
"type": "module",
"license": "MIT",
"dependencies": {
"@koa/router": "^10.1.1",
"crypto-js": "^4.1.1",
"form-data": "^4.0.0",
"koa": "^2.13.4",
"koa-bodyparser": "^4.3.0",
"kolorist": "^1.5.1",
"multiparty": "^4.2.3",
"prompts": "^2.4.2",
"serverless-http": "^3.0.1",
"tencentcloud-sdk-nodejs": "^4.0.327"
"tencentcloud-sdk-nodejs": "^4.0.327",
"ws": "^8.8.0"
}
}
}
100 changes: 51 additions & 49 deletions src/configs/api.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,52 @@
module.exports = {
LOGIN_PAGE: {
URL: 'http://passport2.chaoxing.com/mlogin?fid=&newversion=true&refer=http%3A%2F%2Fi.chaoxing.com',
METHOD: 'GET'
},
LOGIN: {
URL: 'http://passport2.chaoxing.com/fanyalogin',
METHOD: 'POST',
},
PRESIGN: {
URL: 'https://mobilelearn.chaoxing.com/newsign/preSign',
METHOD: 'GET'
},
PPTSIGN: {
URL: 'https://mobilelearn.chaoxing.com/pptSign/stuSignajax',
METHOD: 'GET'
},
COURSELIST: {
URL: 'http://mooc1-1.chaoxing.com/visit/courselistdata',
METHOD: 'POST'
},
BACKCLAZZDATA: {
URL: 'http://mooc1-api.chaoxing.com/mycourse/backclazzdata',
METHOD: 'GET'
},
ACTIVELIST: {
URL: 'https://mobilelearn.chaoxing.com/v2/apis/active/student/activelist',
METHOD: 'GET'
},
ACCOUNTMANAGE: {
URL: 'http://passport2.chaoxing.com/mooc/accountManage',
METHOD: 'GET'
},
PANCHAOXING: {
URL: 'https://pan-yz.chaoxing.com',
METHOD: 'GET'
},
PANLIST: {
URL: 'https://pan-yz.chaoxing.com/opt/listres',
METHOD: 'POST'
},
PANTOKEN: {
URL: 'https://pan-yz.chaoxing.com/api/token/uservalid',
METHOD: 'GET'
},
PANUPLOAD: {
URL: 'https://pan-yz.chaoxing.com/upload',
METHOD: 'POST'
}
export const LOGIN_PAGE = {
URL: 'http://passport2.chaoxing.com/mlogin?fid=&newversion=true&refer=http%3A%2F%2Fi.chaoxing.com',
METHOD: 'GET'
}
export const LOGIN = {
URL: 'http://passport2.chaoxing.com/fanyalogin',
METHOD: 'POST',
}
export const PRESIGN = {
URL: 'https://mobilelearn.chaoxing.com/newsign/preSign',
METHOD: 'GET'
}
export const PPTSIGN = {
URL: 'https://mobilelearn.chaoxing.com/pptSign/stuSignajax',
METHOD: 'GET'
}
export const COURSELIST = {
URL: 'http://mooc1-1.chaoxing.com/visit/courselistdata',
METHOD: 'POST'
}
export const BACKCLAZZDATA = {
URL: 'http://mooc1-api.chaoxing.com/mycourse/backclazzdata',
METHOD: 'GET'
}
export const ACTIVELIST = {
URL: 'https://mobilelearn.chaoxing.com/v2/apis/active/student/activelist',
METHOD: 'GET'
}
export const ACCOUNTMANAGE = {
URL: 'http://passport2.chaoxing.com/mooc/accountManage',
METHOD: 'GET'
}
export const PANCHAOXING = {
URL: 'https://pan-yz.chaoxing.com',
METHOD: 'GET'
}
export const PANLIST = {
URL: 'https://pan-yz.chaoxing.com/opt/listres',
METHOD: 'POST'
}
export const PANTOKEN = {
URL: 'https://pan-yz.chaoxing.com/api/token/uservalid',
METHOD: 'GET'
}
export const PANUPLOAD = {
URL: 'https://pan-yz.chaoxing.com/upload',
METHOD: 'POST'
}
export const WEBIM = {
URL: 'https://im.chaoxing.com/webim/me',
METHOD: 'GET'
}
6 changes: 3 additions & 3 deletions src/functions/QRCode.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const https = require('https')
const { PPTSIGN } = require('../configs/api')
import https from 'https';
import { PPTSIGN } from '../configs/api.js';

exports.QRCodeSign = async (enc, name, fid, uid, aid, uf, _d, vc3) => {
export const QRCodeSign = async (enc, name, fid, uid, aid, uf, _d, vc3) => {
return new Promise((resolve) => {
let data = ''
https.get(PPTSIGN.URL + `?enc=${enc}&name=${encodeURI(name)}&activeId=${aid}&uid=${uid}&clientip=&useragent=&latitude=-1&longitude=-1&fid=${fid}&appType=15`, {
Expand Down
23 changes: 12 additions & 11 deletions src/functions/activity.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const https = require('https')
const { ACTIVELIST, PRESIGN } = require("../configs/api")
import https from 'https';
import { ACTIVELIST, PRESIGN } from "../configs/api.js";

/**
* 返回一个签到信息对象 {aid, name, courseId, classId, otherId}
Expand All @@ -9,13 +9,13 @@ const { ACTIVELIST, PRESIGN } = require("../configs/api")
* @param {string} UID
* @param {string} vc3
*/
exports.getSignActivity = (courses, uf, _d, UID, vc3) => {
export const getSignActivity = (courses, uf, _d, UID, vc3) => {
console.log('正在查询有效签到活动,等待时间视网络情况而定...')
let i = 0, tasks = []
return new Promise(async (resolve) => {
if (courses.length === 1) {
try {
resolve(await aPromise(courses[0], uf, _d, UID, vc3))
resolve(await aPromise(courses[0], uf, _d, UID, vc3));
} catch (err) {
i++
}
Expand All @@ -29,7 +29,7 @@ exports.getSignActivity = (courses, uf, _d, UID, vc3) => {
if (i % 5 === 0 || i === courses.length - 1) {
try {
// 任务数组中任意一个成功,则resolve;否则,抛出异常
const result = await this.promiseAny(tasks)
const result = await promiseAny(tasks)
resolve(result)
return
} catch (error) { }
Expand All @@ -52,7 +52,7 @@ exports.getSignActivity = (courses, uf, _d, UID, vc3) => {
* @param {Promise<any>[]} tasks 接收一个 Promise 任务数组
* @returns 任务数组中有一个成功则resolve其值;若全部失败,则reject一个异常。
*/
exports.promiseAny = (tasks) => {
export const promiseAny = (tasks) => {
// 记录失败次数
let length = tasks.length
return new Promise((resolve, reject) => {
Expand All @@ -77,10 +77,11 @@ exports.promiseAny = (tasks) => {
}

/**
* 返回一个活动请求 Promise 对象,
* @returns Promise\<Activity\>
* @param {{courseId, classId}} course
*
* @returns 返回一个活动请求 Promise 对象
*/
function aPromise(course, uf, _d, UID, vc3) {
export function aPromise(course, uf, _d, UID, vc3) {
return new Promise((resolve, reject) => {
let data = ''
https.get(ACTIVELIST.URL + `?fid=0&courseId=${course.courseId}&classId=${course.classId}&_=${new Date().getTime()}`, {
Expand Down Expand Up @@ -117,15 +118,15 @@ function aPromise(course, uf, _d, UID, vc3) {
}

// 预检请求
exports.preSign = async (uf, _d, vc3, activeId, classId, courseId, uid) => {
export const preSign = async (uf, _d, vc3, activeId, classId, courseId, uid) => {
let data = ''
return new Promise((resolve) => {
https.get(PRESIGN.URL + `?courseId=${courseId}&classId=${classId}&activePrimaryId=${activeId}&general=1&sys=1&ls=1&appType=15&&tid=&uid=${uid}&ut=s`, {
headers: {
'Cookie': `uf=${uf}; _d=${_d}; UID=${uid}; vc3=${vc3};`
}
}, (res) => {
res.on('data', (chunk) => { data += chunk })
res.on('data', chunk => data += chunk);
res.on('end', () => {
console.log(`[预签]已请求`)
resolve()
Expand Down
6 changes: 3 additions & 3 deletions src/functions/general.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const https = require('https')
const { PPTSIGN } = require('../configs/api')
import https from 'https';
import { PPTSIGN } from '../configs/api.js';

exports.GeneralSign = async (uf, _d, vc3, name, activeId, uid, fid) => {
export const GeneralSign = async (uf, _d, vc3, name, activeId, uid, fid) => {
let data = ''
return new Promise((resolve) => {
https.get(PPTSIGN.URL + `?activeId=${activeId}&uid=${uid}&clientip=&latitude=-1&longitude=-1&appType=15&fid=${fid}&name=${name}`, {
Expand Down
6 changes: 3 additions & 3 deletions src/functions/location.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const https = require('https')
const { PPTSIGN } = require('../configs/api')
import https from 'https';
import { PPTSIGN } from '../configs/api.js';

exports.LocationSign = async (uf, _d, vc3, name, address, activeId, uid, lat, lon, fid) => {
export const LocationSign = async (uf, _d, vc3, name, address, activeId, uid, lat, lon, fid) => {
let data = ''
return new Promise((resolve) => {
https.get(PPTSIGN.URL + `?name=${name}&address=${address}&activeId=${activeId}&uid=${uid}&clientip=&latitude=${lat}&longitude=${lon}&fid=${fid}&appType=15&ifTiJiao=1`, {
Expand Down
22 changes: 13 additions & 9 deletions src/functions/photo.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
const https = require('https')
const fs = require('fs')
const path = require('path')
const { PPTSIGN, PANCHAOXING, PANLIST, PANUPLOAD } = require('../configs/api')
const { env: { SERVERLESS } } = require('../env.json')
import https from 'https';
import fs from 'fs';
import path from 'path';
import { PPTSIGN, PANCHAOXING, PANLIST, PANUPLOAD } from '../configs/api.js';
import ENVJSON from '../env.json' assert {type: "json"};
import { fileURLToPath } from 'url';
const { SERVERLESS } = ENVJSON.env.SERVERLESS;
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

exports.PhotoSign = async (uf, _d, vc3, name, activeId, uid, fid, objectId) => {
export const PhotoSign = async (uf, _d, vc3, name, activeId, uid, fid, objectId) => {
let data = ''
return new Promise((resolve) => {
https.get(PPTSIGN.URL + `?activeId=${activeId}&uid=${uid}&clientip=&useragent=&latitude=-1&longitude=-1&appType=15&fid=${fid}&objectId=${objectId}&name=${name}`, {
Expand All @@ -28,7 +32,7 @@ exports.PhotoSign = async (uf, _d, vc3, name, activeId, uid, fid, objectId) => {
}

// 在Termux或其他终端中使用,从云盘获取图片
exports.getObjectIdFromcxPan = (uf, _d, vc3, uid) => {
export const getObjectIdFromcxPan = (uf, _d, vc3, uid) => {
let data = ''
return new Promise((resolve) => {
https.get(PANCHAOXING.URL, {
Expand Down Expand Up @@ -75,8 +79,8 @@ exports.getObjectIdFromcxPan = (uf, _d, vc3, uid) => {
}

// 直接上传图片获得objectId,在UI项目里使用
exports.uploadPhoto = (uf, _d, _uid, vc3, token, buffer) => {
const FormData = require('form-data')
export const uploadPhoto = async (uf, _d, _uid, vc3, token, buffer) => {
const FormData = (await import('form-data')).default
let form = new FormData()
let data = '', tempFilePath

Expand Down
12 changes: 6 additions & 6 deletions src/functions/tencent/QrCodeOCR.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const tencentcloud = require("tencentcloud-sdk-nodejs")
const { tencent: { secretId, secretKey } } = require('../../env.json')
const OcrClient = tencentcloud.ocr.v20181119.Client
import tencentcloud from "tencentcloud-sdk-nodejs";
import ENVJSON from '../../env.json' assert {type: 'json'};
const OcrClient = tencentcloud.ocr.v20181119.Client;

exports.QrCodeScan = (base64str) => {
export const QrCodeScan = (base64str) => {
return new Promise((res, rej) => {
const client = new OcrClient({
credential: {
secretId: secretId,
secretKey: secretKey
secretId: ENVJSON.tencent.secretId,
secretKey: ENVJSON.tencent.secretKey
},
region: "ap-shanghai",
profile: {
Expand Down
Loading

0 comments on commit 8b1c765

Please sign in to comment.