You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.8 KiB
61 lines
1.8 KiB
import axios from 'axios' |
|
import FormData from 'form-data'; |
|
import redis from "../infrastructure/redisSetup.js"; |
|
|
|
export default class RollCall { |
|
async login({ nationalId , password }) { |
|
let bodyFormData = new FormData(); |
|
|
|
bodyFormData.append('dir', ''); |
|
bodyFormData.append('kindlogin', ''); |
|
bodyFormData.append('uname', nationalId); |
|
bodyFormData.append('passcode', password); |
|
|
|
const result = await axios({ |
|
method: 'POST', |
|
url: 'https://tap.sanaoffice.ir/load/login', |
|
data: bodyFormData, |
|
headers: { 'Content-Type': `multipart/form-data; boundary=${bodyFormData._boundary}` }, |
|
validateStatus: null, |
|
}) |
|
|
|
await redis.set(`sanaOffice_${nationalId}`, JSON.stringify(result.headers['set-cookie'])) |
|
|
|
return result.error ? |
|
{ |
|
error: result.error, |
|
statusCode: result.status, |
|
message: result.error?.message |
|
|| |
|
"خطا در لاگین" |
|
} : { message: "success" }; |
|
} |
|
|
|
async operation({nationalId, enter}) { |
|
let cookies = await redis.get(`sanaOffice_${nationalId}`); |
|
if (!cookies) return {statusCode:403,message:"کاربر لاگین نیست"} |
|
|
|
const lat = +(35.701766 + Math.random() * 0.00001).toPrecision(8) |
|
const lang = +(51.392069 + Math.random() * 0.00001).toPrecision(8) |
|
|
|
const result = await axios({ |
|
method: 'GET', |
|
url: `https://tap.sanaoffice.ir/load/tap?kind=${encodeURIComponent(enter ? 'ورود' : 'خروج')}&lat=${lat}&lang=${lang}`, |
|
headers: { |
|
cookie: JSON.parse(cookies) |
|
}, |
|
validateStatus: null, |
|
}); |
|
|
|
console.log(result) |
|
|
|
return result.error ? |
|
{ |
|
error: result.error, |
|
statusCode: result.status, |
|
message: result.error?.message |
|
|| |
|
"خطا در ورود" |
|
} : { message: "success" }; |
|
} |
|
} |