Skip to content

Commit

Permalink
form_update
Browse files Browse the repository at this point in the history
  • Loading branch information
luckycat0426 committed Oct 27, 2021
1 parent bc2c605 commit 018c6ab
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 53 deletions.
58 changes: 29 additions & 29 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
# Cea Contribution Guide

## 1. Bootstrap repo

Cea 采用 monorepo 模式,我们首先需要安装和链接依赖,这些操作只需通过一个命令完成:

```bash
npm run bootstrap
```

## 2. Debug packages

本仓库内置 vscode 调试配置文件,推荐使用 vscode 进行调试

## 3. Build packages

编译所有 NPM 包:

```bash
npm run build
```

## 4. Build docs

重新生成文档:

```bash
npm run docs
```
# Cea Contribution Guide

## 1. Bootstrap repo

Cea 采用 monorepo 模式,我们首先需要安装和链接依赖,这些操作只需通过一个命令完成:

```bash
npm run bootstrap
```

## 2. Debug packages

本仓库内置 vscode 调试配置文件,推荐使用 vscode 进行调试

## 3. Build packages

编译所有 NPM 包:

```bash
npm run build
```

## 4. Build docs

重新生成文档:

```bash
npm run docs
```
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,8 @@
"typedoc-github-wiki-theme": "^0.3.0",
"typedoc-plugin-markdown": "^3.8.1",
"typescript": "^4.4.4"
},
"dependencies": {
"dprint": "^0.18.1"
}
}
2 changes: 2 additions & 0 deletions plugins/check-in/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
"dependencies": {
"cea-core": "2.0.1",
"node-fetch": "^2.6.5",
"ts-md5":"1.2.9",
"uuid": "^8.3.2"
},
"devDependencies": {
"@types/node": "^16.11.6",
"@types/node-fetch": "^2.5.12",
"@types/uuid": "^8.3.1"
}
Expand Down
77 changes: 63 additions & 14 deletions plugins/check-in/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CampusphereEndpoint } from 'cea-core'
import { LogInfoKeys } from './types.js'

import { Md5 } from 'ts-md5/dist/md5'
import { handleCookie, sstore } from 'cea-core'
import crypto from 'crypto'
import fetch from 'node-fetch'
Expand All @@ -17,12 +17,15 @@ import type {
AllSignTasks,
CpdailyExtension,
CpdailyExtensionEncrypted,
bodyStringEncrypted,
GlobalLogInfo,
LogInfo,
SignForm,
SignTask,
SignTaskDetail,
} from './types'
import { json } from 'stream/consumers'
import { version } from 'os'

export class CheckIn {
private headers: StringKV
Expand Down Expand Up @@ -93,33 +96,71 @@ export class CheckIn {

const placeList = signPlaceSelected[0]
const isSignAtHome = !Boolean(school.defaultAddr)
;[longitude, latitude, position] = isSignAtHome
? this.user.addr
: [placeList.longitude, placeList.latitude, school.defaultAddr]
;[longitude, latitude, position] = isSignAtHome
? this.user.addr
: [placeList.longitude, placeList.latitude, school.defaultAddr]

const extraFieldItems = this.fillExtra(extraField)

const form: SignForm = {
longitude: this.fixedFloatRight(longitude),
latitude: this.fixedFloatRight(latitude),
isMalposition: isSignAtHome ? 1 : 0,
uaIsCpadaily: true,
signPhotoUrl: '',
abnormalReason: '',
signVersion: 'first_v2',
signInstanceWid,
signPhotoUrl: '',
isNeedExtra,
extraFieldItems,
position,
uaIsCpadaily: true,
signInstanceWid,
extraFieldItems,
}
const bodyString = this.Aes_encrpt(JSON.stringify(form))
const signbody = {
appVersion: '9.0.12',
bodyString: bodyString,
deviceId: uuid.v1(),
lat: form.latitude.toString(),
lon: form.longitude.toString(),
model: 'Cock',
systemName: 'android',
systemVersion: 'Cock',
userId: this.user.username,
}
let body_to_string = ''
for (const key in signbody) {
body_to_string += '${key}=${signBody[key]}&'
}
body_to_string += "ytUQ7l2ZZu8mLvJZ"
const sign = Md5.hashStr(body_to_string)
/* 按照抓包顺序
const final_form = {
lon: signbody.lon,
version: 'first_v2',
calVersion: 'firstv',
deviceId: signbody.deviceId,
userId: signbody.userId,
systemName: signbody.systemName,
bodyString: bodyString,
lat: signbody.lat,
systemVersion: signbody.systemVersion,
appVersion: signbody.appVersion,
module:signbody.model,
sign: sign,
}
*/
const final_form = {
...signbody,
version: 'first_v2',
calVersion: 'firstv',
sign: sign,
}

headers['Cpdaily-Extension'] = this.extention(form)
res = await fetch(
`${school.campusphere}${CampusphereEndpoint.submitSign}`,
{
headers,
method: 'POST',
body: JSON.stringify(form),
body: JSON.stringify(final_form),
},
)
const result = (await res.json()) as any
Expand Down Expand Up @@ -190,6 +231,15 @@ export class CheckIn {
encrypted += cipher.final('base64')
return encrypted
}
private Aes_encrpt(ce: string): bodyStringEncrypted {
const algorithm = 'aes-cbc'
const key = 'ytUQ7l2ZZu8mLvJZ'
const iv = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7])
const cipher = crypto.createCipheriv(algorithm, key, iv)
let encrypted = cipher.update(JSON.stringify(ce), 'utf8', 'base64')
encrypted += cipher.final('base64')
return encrypted
}

private decrypt() {
const algorithm = 'des-cbc'
Expand Down Expand Up @@ -230,9 +280,8 @@ async function signIn(users: UsersConf): Promise<GlobalLogInfo> {
logs[i.alias] = result
} else {
logs[i.alias] = {
[LogInfoKeys.result as string]: `已完成:${
curTask.signedTasks[0].taskName
}`,
[LogInfoKeys.result as string]: `已完成:${curTask.signedTasks[0].taskName
}`,
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions plugins/check-in/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export type SignForm = {
abnormalReason: string
signPhotoUrl: string
position: string
signVersion: string
extraFieldItems: Array<{
extraFieldItemWid: string
extraFieldItemValue: string
Expand All @@ -51,16 +50,17 @@ export type SignForm = {

export type CpdailyExtension = {
[
K in
| 'lon'
| 'model'
| 'appVersion'
| 'systemVersion'
| 'userId'
| 'systemName'
| 'lat'
| 'deviceId'
K in
| 'lon'
| 'model'
| 'appVersion'
| 'systemVersion'
| 'userId'
| 'systemName'
| 'lat'
| 'deviceId'
]: string
}

export type CpdailyExtensionEncrypted = string
export type bodyStringEncrypted = string

0 comments on commit 018c6ab

Please sign in to comment.