Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
fix: delete loose calculation of coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
beetcb committed Dec 21, 2020
1 parent 924cc9d commit 0c2dcb8
Showing 1 changed file with 29 additions and 37 deletions.
66 changes: 29 additions & 37 deletions campusphere/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class campusphereApp {
detail: `${school.origin}/wec-counselor-sign-apps/stu/sign/detailSignTaskInst`,
sign: `${school.origin}/wec-counselor-sign-apps/stu/sign/completeSignIn`,
home: `${school.origin}/wec-counselor-sign-apps/stu/mobile`,
addr: school.addr,
}
}
}
Expand Down Expand Up @@ -82,13 +83,11 @@ exports.signApp = class signApp extends (
signedStuInfo,
} = signDetails.datas

// format coordinates length
;[longitude, latitude] = this.randomLocale(signPlaceSelected[0]).map(e =>
Number(e.toFixed(6))
)
const placeList = signPlaceSelected

;[longitude, latitude] = this.locale(placeList[0])

const extraFieldItems = this.fillExtra(extraField)
const { address } = signPlaceSelected[0]

const form = {
signInstanceWid,
Expand All @@ -97,38 +96,31 @@ exports.signApp = class signApp extends (
isMalposition,
abnormalReason: '',
signPhotoUrl: '',
position: address,
position: signApi.addr,
isNeedExtra,
extraFieldItems,
}
log.object(form)
// headers['Cpdaily-Extension'] = this.extention(form)

// res = await fetch(signApi.sign, {
// headers,
// method: 'POST',
// body: JSON.stringify(form),
// })
// res = await res.json()
// log.warning(
// `${this.user.alias || this.user.username} 的签到结果: ${res.message}`
// )
headers['Cpdaily-Extension'] = this.extention(form)

res = await fetch(signApi.sign, {
headers,
method: 'POST',
body: JSON.stringify(form),
})
res = await res.json()
log.warning(
`${this.user.alias || this.user.username} 的签到结果: ${res.message}`
)
}

// construct random coordinates
randomLocale({ longitude, latitude, radius }) {
const [perMeterLat, perMeterLon] = [
360 / (Math.cos(latitude) * 40076000),
0.000008983,
]
const { PI, cos, sin } = Math
const [randomLon, randomLat] = [
cos(Math.random() * PI),
sin(Math.random() * PI),
]
longitude -= radius * perMeterLon * randomLon
latitude -= radius * perMeterLat * randomLat
return [longitude, latitude]
// construct coordinates & format coordinates length
locale({ longitude, latitude }) {
return [longitude.slice(0, 10), latitude.slice(0, 9)].map(e => {
if (e[e.length - 1] === '0') {
e = e.replace(/\d{1}$/, '1')
}
return Number(e)
})
}

// select right item with content&wid
Expand All @@ -140,22 +132,22 @@ exports.signApp = class signApp extends (
return !i.isAbnormal
})[0]
return {
extraFieldItemValue: normal.content,
extraFieldItemWid: chosenWid,
extraFieldItemValue: normal.content,
}
})
}

// construct and encrypte Cpdaily_Extension for header
extention(form) {
const Cpdaily_Extension = {
lon: form.longitude,
model: 'One Plus 7 Pro',
appVersion: '8.0.8',
lon: form.longitude.toString(),
model: 'OPPO R11 Plus',
appVersion: '8.1.14',
systemVersion: '4.4.4',
userId: this.user.username,
systemName: 'android',
lat: form.latitude,
lat: form.latitude.toString(),
deviceId: v1(),
}
return this.encrypt(Cpdaily_Extension)
Expand Down

0 comments on commit 0c2dcb8

Please sign in to comment.