import {encode} from "js-base64";
import fetch from "node-fetch";
import axios from "axios";
import md5 from "js-md5";
import qs from "qs";
!(async () => {
let time = String(parseInt((new Date).getTime() / 1000 + ""));
console.log(time)
await axiosSportLogin(time, "12345678901", "12345678901", "99999")
await fetchSportLogin(time, "12345678901", "12345678901", "99999")
})().catch((e) => {
}).finally(() => {
})
async function axiosSportLogin(time, phone, password, step) {
const data = {
'time': time,
'phone': phone,
'password': password,
'step': step,
'key': md5(encode(`${phone}1${password}2${step}xjdsb${time}`))
};
const header = {
"accept": "application/json, text/javascript, */*; q=0.01",
"accept-language": "zh,en-US;q=0.9,en;q=0.8,zh-CN;q=0.7",
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-site",
"referrer": "https://xxx.xxx.xxx/",
"referrerPolicy": "strict-origin-when-cross-origin",
"mode": "cors",
"credentials": "omit"
}
return await axios.post("https://xxx.xxx.xxx/xxx/xx.php", qs.stringify(data), {headers: header}).then(function (response) {
console.log(response.data)
}).catch(function (error) {
console.log(JSON.stringify(error))
console.log('PI请求失败,请检查网路重试');
})
}
async function fetchSportLogin(time, phone, password, step) {
return await fetch("https://xxx.xxx.xxx/xxx/xx.php", {
"headers": {
"accept": "application/json, text/javascript, */*; q=0.01",
"accept-language": "zh,en-US;q=0.9,en;q=0.8,zh-CN;q=0.7",
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-site"
},
"referrer": "https://xxx.xxx.xxx/",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": "time=" + time + "&phone=" + phone + "&password=" + password + "&step=" + step + "&key=" + md5(encode(`${phone}1${password}2${step}xjdsb${time}`)),
"method": "POST",
"mode": "cors",
"credentials": "omit"
}).then(res => res.text()).then(res => console.log(JSON.parse(res)))
}