Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

access_token 如何获得 #64

Closed
Chinalover opened this issue Nov 6, 2020 · 1 comment
Closed

access_token 如何获得 #64

Chinalover opened this issue Nov 6, 2020 · 1 comment

Comments

@Chinalover
Copy link

如何获得自己bilbili账号的access_token

@umuoy1
Copy link
Collaborator

umuoy1 commented Nov 7, 2020

function login(username, password) {
return new Promise(async (resolve, reject) => {
let data
try {
data = await get_key()
} catch (error) {
return reject(`An error occurred when login: ${error}`)
}
const encoded_password = crypt.make_rsa(`${data.hash}${password}`, data.key)
const url = "https://passport.bilibili.com/api/oauth2/login"
const headers = {
'Connection': 'keep-alive',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'User-Agent': '',
'Accept-Encoding': 'gzip,deflate',
}
let post_data = {
'appkey': APPKEY,
'password': encoded_password,
'platform': "pc",
'ts': String(parseInt(new Date() / 1000)),
'username': username
}
post_data["sign"] = md5(crypt.make_sign(post_data, APPSECRET))
try {
const result = await superagent
.post(url)
.set(headers)
.type('form')
.send(post_data)
const res = JSON.parse(result.text);
if (res.code !== 0) {
return reject(`An error occurred when login: ${res.message}`)
}
resolve({
access_token: res.data.access_token,
mid: res.data.mid,
})
} catch (err) {
// console.log(err)
// logger.info(err)
reject(`An error occurred when login: ${res}`)
}
})
}

登录成功会返回access_token

@umuoy1 umuoy1 closed this as completed May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants