Created
September 23, 2020 04:07
-
-
Save makeding/d18e231eb6d2189adac506c5f16fb577 to your computer and use it in GitHub Desktop.
中央民族大学 智慧门户 模拟登录
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const rq = require('request-promise') | |
const url = 'http://ca.muc.edu.cn/zfca/login?service=http%3A%2F%2Fmy.muc.edu.cn%2Fuser%2FsimpleSSOLogin' | |
const ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.30 Safari/537.36' | |
async function run(username,password){ | |
// 登录前要的两个数值 cookie lt | |
let {cookie,lt} = await new_pre_login_value() | |
let ticket_url,ticket,caUserName = false | |
let j = rq.jar() | |
await rq.post({ | |
url: url, | |
headers: { | |
'User-Agent': ua, | |
cookie: cookie, | |
Referer: url | |
}, | |
// 这里懒 直接用字符串拼接了 没啥问题的啦 | |
form: 'useValidateCode=0&isremenberme=1&openurl=http%3A%2F%2Fmy.muc.edu.cn&username=' + encodeURIComponent(username) + '&password=' + encodeURIComponent(password) + '&losetime=60<=' + encodeURIComponent(lt) +'&_eventId=submit&submit1=%B5%C7%A1%A1%C2%BC' | |
}).catch(e=>{ | |
// 被 request 坑了 1h 烦死 | |
ticket_url = e.response.headers.location.replace('http','https') | |
ticket = ticket_url.split('ticket=')[1].split('&')[0] | |
caUserName = ticket_url.split('caUserName=')[1] | |
}) | |
await rq({ | |
// 同上 被坑死了 | |
url: 'https://my.muc.edu.cn/user/simpleSSOLogin', | |
qs: { | |
ticket: ticket, | |
caUserName: caUserName | |
}, | |
jar: j, | |
headers: { | |
'User-Agent': ua, | |
cookie: cookie, | |
}, | |
followRedirect: false | |
}).catch(x=>{ | |
// 获取登录后的新 cookie | |
cookie = j.getCookieString('https://my.muc.edu.cn/user/simpleSSOLogin') | |
}) | |
// 测试 获取登录信息 ok | |
let user_info = await rq.post({ | |
url: 'https://my.muc.edu.cn/comsys-owner-portlet-web/getOwner', | |
headers: { | |
'User-Agent': ua, | |
cookie: cookie, | |
form: 'portletInstanceId=0' | |
}, | |
json: true | |
}) | |
console.table(user_info) | |
} | |
async function new_pre_login_value(){ | |
// 获取 💩 | |
let j = rq.jar() | |
let body = await rq({ | |
url: url, | |
jar: j, | |
headers: { | |
'User-Agent': ua | |
} | |
}) | |
return { | |
cookie: j.getCookieString(url), | |
lt: body.split('name="lt" value="')[1].split('"')[0] | |
} | |
} | |
run(process.argv[2],process.argv[3]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
yarn add request request-promise
模拟登录脚本 返回 cookie
node muc.js 'username' 'password'
记得加引号
可以自己改改 比如 console.log 换成 return 之类的 任君发挥~