Refactor code structure and remove redundant changes
This commit is contained in:
31
utils/login.ts
Normal file
31
utils/login.ts
Normal file
@ -0,0 +1,31 @@
|
||||
export const QQ_APP_ID = '102796005' // QQ appid
|
||||
export const WECHAT_APP_ID = 'wxc2fa7aafa1649f7a' // 微信 appid
|
||||
|
||||
// 生成随机字符串
|
||||
export const generateRandomString = (length: number) => {
|
||||
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
|
||||
let result = ''
|
||||
for (let i = 0; i < length; i++) {
|
||||
result += characters.charAt(Math.floor(Math.random() * characters.length))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// QQ登录
|
||||
export const handleLoginQQ = () => {
|
||||
const appId = QQ_APP_ID // APP ID
|
||||
const redirectUri = encodeURIComponent('https://tuxixi.net/index?type=35') // 回调地址
|
||||
const state = generateRandomString(16) // 生成随机state
|
||||
// 存储state用于后续验证
|
||||
localStorage.setItem('qq_login_state', state)
|
||||
window.location.href = `https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=${appId}&redirect_uri=${redirectUri}&state=${state}`
|
||||
}
|
||||
|
||||
export const handleLoginWechat = () => {
|
||||
const appId = WECHAT_APP_ID // APP ID
|
||||
const redirectUri = encodeURIComponent('https://tuxixi.net?type=32') // 回调地址
|
||||
const state = generateRandomString(16) // 生成随机state
|
||||
// 存储state用于后续验证
|
||||
localStorage.setItem('wechat_login_state', state)
|
||||
window.location.href = `https://open.weixin.qq.com/connect/qrconnect?appid=${appId}&redirect_uri=${redirectUri}&response_type=code&scope=snsapi_login&state=${state}`
|
||||
}
|
||||
Reference in New Issue
Block a user