Skip to content

Commit

Permalink
Merge pull request #1 from CrazyHer/dev
Browse files Browse the repository at this point in the history
Publish 1.0.0
  • Loading branch information
CrazyHer committed Jul 10, 2022
2 parents 2923d08 + 9b07156 commit abfe065
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 5 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: NPM Package

on:
release:
types: [created]

jobs:
build-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://registry.npmjs.org/

- name: lint and build
run: |
npm install
npm run lint
npm run build
- name: publish to npm
run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
78 changes: 78 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# 山东大学 一键申请出校脚本 开润神器

![workflow](https://github.com/CrazyHer/run-away-from-sdu/actions/workflows/CI.yml/badge.svg)

本脚本旨在为沙袋师生提供更便捷和稳定的山东大学信息中心出校申请服务

( 说白了就是免去每次出校都要填写繁琐的表单,一键用上次提交出校申请的信息再帮你申一次

**仅备案制出校时可用** (其实审批制也可以,不过都审批制了也没必要

**济威青一校三地均可用** (理论上来说是这样的,不能用请提 issue

## 使用方法

### 1. CLI 命令行直接运行

安装 Nodejs 后,运行以下命令即可:

`npx run-away-from-sdu <userId> <password> <date> [endDate]`

参数说明:

userId 山大统一身份认证账号

password 山大统一身份认证密码

date 申请出校日期, 例: 2022-07-10

endDate 可选. 若填写, 则会批量申请至截止申请日期. 例: 2022-07-10

### 2. 作为 npm 包在 node 代码中引入

```ts
import submitGooutApplication, {
batchSubmitGooutApplication,
} from 'run-away-from-sdu';

const app = async () => {
console.log('提交单次出校申请: ');
await submitGooutApplication(
'学号',
'密码',
moment(date, 'YYYY-MM-DD').valueOf()
);
console.log('申请成功!');

console.log('批量提交指定日期范围内的出校申请: ');
await batchSubmitGooutApplication(
'学号',
'密码',
moment(startDate, 'YYYY-MM-DD').valueOf(),
moment(endDate, 'YYYY-MM-DD').valueOf(),
// 每提交一天的申请后的回调函数,如果传入的是Async异步函数则会等待该函数执行完毕再提交下一天的申请
(dateTimeStp, success, error) =>
success
? console.log(`${moment(dateTimeStp).format('YYYY-MM-DD')} 申请成功`)
: console.error(
`${moment(dateTimeStp).format('YYYY-MM-DD')} 申请失败`,
error
)
);
console.log('批量申请完毕');
};
```

### 3. 使用小程序的每日定时申请服务

![Crazyherlab](https://oss.herui.club/crazyherlab.jpg)

## 原理&大致流程

~~示意图以后再补~~

先用账号和密码去登录山大统一身份认证平台,跳转到山大信息化公共服务平台拿到对应的登录态 Cookie。

然后从服务中心获取并处理得到最新的出入校园申请的表单模板,对模板稍加修改并替换日期后得到本次请求的表单数据。

用这份表单数据向信息办的接口提交出校申请即可。
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "run-away-from-sdu",
"version": "1.0.0-beta1",
"version": "1.0.0",
"description": "山大? 快润! 山东大学一键申请出校脚本",
"main": "dist/index.js",
"bin": "dist/bin/run-away-from-sdu.js",
"files": [
"dist"
],
"scripts": {
"test": "eslint src",
"lint": "eslint src",
"build": "tsc"
},
"repository": {
Expand Down
6 changes: 3 additions & 3 deletions src/bin/run-away-from-sdu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ async function app() {
await batchSubmitGooutApplication(
userId,
password,
moment(date, 'YYYY-MM-DD').unix(),
moment(endDate, 'YYYY-MM-DD').unix(),
moment(date, 'YYYY-MM-DD').valueOf(),
moment(endDate, 'YYYY-MM-DD').valueOf(),
(dateTimeStp, success, error) =>
success
? console.log(
Expand All @@ -46,7 +46,7 @@ async function app() {
await submitGooutApplication(
userId,
password,
moment(date, 'YYYY-MM-DD').unix()
moment(date, 'YYYY-MM-DD').valueOf()
);
console.log(`${date} 申请成功`);
}
Expand Down
7 changes: 7 additions & 0 deletions src/lib/gooutServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export const getCustomizedFormData = async (
const dw = /"unit_name":"(.+?)"/.exec(res)?.[1] || ''; // 单位
const xm = /"user_name":"(.+?)"/.exec(res)?.[1] || ''; // 姓名
const xh = /"StudentIdNo":"(.+?)"/.exec(res)?.[1] || ''; // 学号
const crxq = /"CRXQ":"(.+?)"/.exec(res)?.[1] || ''; // 出入校区

res = res
.replace(
Expand Down Expand Up @@ -169,6 +170,10 @@ export const getCustomizedFormData = async (
/"name":"SFLX","source":"process","type":"string","value":""/g,
`"name":"SFLX","source":"process","type":"string","value":"${sflx}","_t": 1,"_o": { "value": "" }` // 补全学生类型
)
.replace(
/"name":"CRXQ","source":"process","type":"string","value":""/g,
`"name":"CRXQ","source":"process","type":"string","value":"${crxq}","_t": 1,"_o": { "value": "" }` // 补全出入校区
)
.replace(
/"name":"WCSY","source":"process","type":"string","value":""/g,
`"name":"WCSY","source":"process","type":"string","value":"${wcsy}","_t": 1,"_o": { "value": "" }` // 补全外出类型
Expand Down Expand Up @@ -258,6 +263,8 @@ export const applyGoOut = async (
headers: {
'content-type': 'text/plain;charset=UTF-8',
Cookie,
Referer:
'https://scenter.sdu.edu.cn/tp_fp/formParser?status=select&formid=d05bb8b4-4a36-4e13-8d73-f681e03e&service_id=87dc6da9-9ad8-4458-9654-90823be0d5f6&process=c5c3de57-4044-43e9-bc25-f88206c0c74d&seqId=&seqPid=&privilegeId=2476634395f5754441ad9f3090319790',
},
data,
}
Expand Down

0 comments on commit abfe065

Please sign in to comment.