Commit a40ae852 authored by youjie's avatar youjie

line 密钥

parent f4387953
...@@ -68,7 +68,7 @@ const router = createRouter({ ...@@ -68,7 +68,7 @@ const router = createRouter({
] ]
}, },
{ {
path: "/login", path: "/login/:type?",
name: "login", name: "login",
component: () => import("../views/auth/Login.vue"), component: () => import("../views/auth/Login.vue"),
meta: { title: "page.login" }, meta: { title: "page.login" },
......
...@@ -59,19 +59,6 @@ ...@@ -59,19 +59,6 @@
</a-form> </a-form>
</a-space> </a-space>
<!-- Line登录 -->
<div v-if="loginMsg.reType==3" class="login-form-content scan-content">
<div class="qr-container">
<div class="qr-box line-qr-box">
<div class="qr-code-placeholder">
<i class="ki-outline ki-message-text"></i>
</div>
</div>
<p class="scan-instruction">{{ t('login.scanTip') }}</p>
<p class="scan-status">{{ t('login.scanWaiting') }}</p>
</div>
</div>
<div class="mt-[40px] flex items-center justify-center"> <div class="mt-[40px] flex items-center justify-center">
<a-divider orientation="center" class="text-[16px] text-[#EEEFEB]"></a-divider> <a-divider orientation="center" class="text-[16px] text-[#EEEFEB]"></a-divider>
<span class="text-nowrap customPrimary-5 px-[14px]">{{ t('login.othenLogin') }}</span> <span class="text-nowrap customPrimary-5 px-[14px]">{{ t('login.othenLogin') }}</span>
...@@ -152,12 +139,13 @@ const systemConfigStore = useSystemConfigStore() ...@@ -152,12 +139,13 @@ const systemConfigStore = useSystemConfigStore()
const loading = ref(true) const loading = ref(true)
const router = useRouter() const router = useRouter()
const { params } = router.currentRoute.value
const googleButtonContainer = ref(null); const googleButtonContainer = ref(null);
const loginMsg = reactive({ const loginMsg = reactive({
tenantId: systemConfigStore.tenantId || null, tenantId: systemConfigStore.tenantId || null,
reType: 0,//登录方式 0账号密码 1谷歌授权 3LINE授权 7FaceBook授权 reType: 0,//登录方式 0账号密码 1谷歌授权 2微信授权 3LINE授权 7FaceBook授权
openId: "", openId: "",
email: "",//2310721242@qq.com email: "",//2310721242@qq.com
password: '',//yj123456 password: '',//yj123456
...@@ -165,6 +153,7 @@ const loginMsg = reactive({ ...@@ -165,6 +153,7 @@ const loginMsg = reactive({
parentId: null, parentId: null,
redirectUri: '', redirectUri: '',
}) })
if(params&&params.type) loginMsg.reType = Number(params.type)
const loginMethods = ref([ const loginMethods = ref([
{ {
...@@ -213,24 +202,48 @@ const rules = computed(() => ({ ...@@ -213,24 +202,48 @@ const rules = computed(() => ({
const openInfo = ref({} as any) const openInfo = ref({} as any)
// 随机生成 state 参数
const generateState = () => {
return Math.random().toString(36).substring(2); // 简单的生成随机字符串
}
// line授权登录
const loginWithLine = () => {
const channelId = openInfo.value.appId; // 替换为你的 LINE Channel ID
const redirectUri = encodeURIComponent(openInfo.value.redirectUri || 'https://www.oytour.com/#/login/3'); // 替换为你的重定向 URI
const state = generateState(); // 防止 CSRF 攻击,生成随机的 state 参数
// 构造 LINE 授权 URL
const lineLoginUrl = `https://access.line.me/oauth2/v2.1/authorize?response_type=code&client_id=${channelId}&redirect_uri=${redirectUri}&state=${state}&scope=openid%20profile`;
// 跳转到 LINE 登录页面
window.location.href = lineLoginUrl;
}
// 微信授权登录
const loginWechat = () => {
const redirect_url = openInfo.value.redirectUri || 'https://www.oytour.com/#/login/2'
const url = `https://open.weixin.qq.com/connect/qrconnect?appid=${openInfo.value.appId}&redirect_uri=${encodeURIComponent(redirect_url)}&response_type=code&scope=snsapi_login&state=${1}&wechat_redirect=${redirect_url}`;
window.location.href = url;
}
// 获取微信登录AppID 域名 重定向页面 // 获取AppID 域名 重定向页面
const getAppIdRedirectUri = async () => { const getAppIdRedirectUri = async (providerType: string) => {
// const { AppID, State, OpenRedirectUri } = openInfo.value; // const { AppID, State, OpenRedirectUri } = openInfo.value;
// let redirect_uri = OpenRedirectUri; // let redirect_uri = OpenRedirectUri;
// const url = `https://open.weixin.qq.com/connect/qrconnect?appid=${AppID}&redirect_uri=${encodeURIComponent('https://www.oytour.com/#/login')}&response_type=code&scope=snsapi_login&state=${State}&wechat_redirect=${redirect_uri}`; // const url = `https://open.weixin.qq.com/connect/qrconnect?appid=${AppID}&redirect_uri=${encodeURIComponent('https://www.oytour.com/#/login')}&response_type=code&scope=snsapi_login&state=${State}&wechat_redirect=${redirect_uri}`;
// window.location.href = url; // window.location.href = url;
// return
loading.value = true loading.value = true
try { try {
// 获取微信登录AppID 域名 // 获取微信绑定AppID 域名
const response = await userStore.getUserWechatAppIdAsync(loginMsg.tenantId?.toString() || '',providerTypeEnum.WECHAT.value) const response = await userStore.getUserWechatAppIdAsync(loginMsg.tenantId?.toString() || '',providerType)
if (response.status == 'SUCCESS') { if (response.status == 'SUCCESS') {
openInfo.value = response.data[0] openInfo.value = response.data[0]
const { appId, redirectUri } = openInfo.value; if(openInfo.value.appId){
const redirect_url = redirectUri?redirectUri:'https://www.oytour.com/#/login' if(providerType==providerTypeEnum.WECHAT.value){
const url = `https://open.weixin.qq.com/connect/qrconnect?appid=${appId}&redirect_uri=${encodeURIComponent(redirect_url)}&response_type=code&scope=snsapi_login&state=${1}&wechat_redirect=${redirect_url}`; loginWechat()
window.location.href = url; }else if(providerType==providerTypeEnum.GOOGLE.value){
renderGoogleButton(openInfo.value.appId)
}else if(providerType==providerTypeEnum.LINE.value){
loginWithLine()
}
}
} }
}catch (error: any) { }catch (error: any) {
Message.error(error.message) Message.error(error.message)
...@@ -265,9 +278,10 @@ const handleClick = (path: string) => { ...@@ -265,9 +278,10 @@ const handleClick = (path: string) => {
} }
const toggleLoginType = (type: number) => { const toggleLoginType = (type: number) => {
if(type==3||type==7) return Message.error(t('login.loginTypeNotSupport')) if(type==7) return Message.error(t('login.loginTypeNotSupport'))
loginMsg.reType = type loginMsg.reType = type
if(type==2) { getAppIdRedirectUri() } if(type==3) getAppIdRedirectUri(providerTypeEnum.LINE.value)
if(type==2) getAppIdRedirectUri(providerTypeEnum.WECHAT.value)
// if(type==1) { // if(type==1) {
// loginWithGoogle() // loginWithGoogle()
// } // }
...@@ -399,17 +413,17 @@ onMounted(async () => { ...@@ -399,17 +413,17 @@ onMounted(async () => {
}) })
const queryParams = query() const queryParams = query()
const code = queryParams.code const code = queryParams.code
if (code) { if (code) {
loginMsg.reType = 2 if(loginMsg.reType==2) useWechatLogin(code)
useWechatLogin(code) else if(loginMsg.reType==3) {}
} }
try { try {
await initGoogleSDK(); await initGoogleSDK();
// 确保 SDK 加载完成后渲染按钮 // 确保 SDK 加载完成后渲染按钮
await new Promise(resolve => setTimeout(resolve)); await new Promise(resolve => setTimeout(resolve));
renderGoogleButton() getAppIdRedirectUri(providerTypeEnum.GOOGLE.value)
} catch (error) { } catch (error) {
console.error('SDK 初始化失败:', error); console.error('SDK 初始化失败:', error);
......
...@@ -242,20 +242,20 @@ const generateState = () => { ...@@ -242,20 +242,20 @@ const generateState = () => {
// line授权 // line授权
const loginWithLine = () => { const loginWithLine = () => {
const channelId = openInfo.value.appId; // 替换为你的 LINE Channel ID const channelId = openInfo.value.appId; // 替换为你的 LINE Channel ID
const redirectUri = encodeURIComponent(openInfo.value.redirectUri || 'https://www.oytour.com/#/login'); // 替换为你的重定向 URI const redirectUri = encodeURIComponent(openInfo.value.redirectUri || 'https://www.oytour.com/#/login/3'); // 替换为你的重定向 URI
const state = generateState(); // 防止 CSRF 攻击,生成随机的 state 参数 const state = generateState(); // 防止 CSRF 攻击,生成随机的 state 参数
// 构造 LINE 授权 URL // 构造 LINE 授权 URL
const lineLoginUrl = `https://access.line.me/oauth2/v2.1/authorize?response_type=code&client_id=${channelId}&redirect_uri=${redirectUri}&state=${state}&scope=openid%20profile`; const lineLoginUrl = `https://access.line.me/oauth2/v2.1/authorize?response_type=code&client_id=${channelId}&redirect_uri=${redirectUri}&state=${state}&scope=openid%20profile`;
// 跳转到 LINE 登录页面 // 跳转到 LINE 登录页面
window.location.href = lineLoginUrl; window.location.href = lineLoginUrl;
} }
// 微信授权登录 // 微信授权
const loginWechat = () => { const loginWechat = () => {
const redirect_url = openInfo.value.redirectUri || 'https://www.oytour.com/#/login' const redirect_url = openInfo.value.redirectUri || 'https://www.oytour.com/#/login/2'
const url = `https://open.weixin.qq.com/connect/qrconnect?appid=${appId}&redirect_uri=${encodeURIComponent(redirect_url)}&response_type=code&scope=snsapi_login&state=${1}&wechat_redirect=${redirect_url}`; const url = `https://open.weixin.qq.com/connect/qrconnect?appid=${openInfo.value.appId}&redirect_uri=${encodeURIComponent(redirect_url)}&response_type=code&scope=snsapi_login&state=${1}&wechat_redirect=${redirect_url}`;
window.location.href = url; window.location.href = url;
} }
// 获取绑定AppID 域名 重定向页面 // 获取AppID 域名 重定向页面
const getAppIdRedirectUri = async (providerType: string) => { const getAppIdRedirectUri = async (providerType: string) => {
// const { AppID, State, OpenRedirectUri } = openInfo.value; // const { AppID, State, OpenRedirectUri } = openInfo.value;
// let redirect_uri = OpenRedirectUri; // let redirect_uri = OpenRedirectUri;
...@@ -267,8 +267,7 @@ const getAppIdRedirectUri = async (providerType: string) => { ...@@ -267,8 +267,7 @@ const getAppIdRedirectUri = async (providerType: string) => {
const response = await userStore.getUserWechatAppIdAsync(systemConfig.tenantId?.toString() || '',providerType) const response = await userStore.getUserWechatAppIdAsync(systemConfig.tenantId?.toString() || '',providerType)
if (response.status == 'SUCCESS') { if (response.status == 'SUCCESS') {
openInfo.value = response.data[0] openInfo.value = response.data[0]
if(openInfo.value?.appId){ if(openInfo.value.appId){
console.log(openInfo.value,'----------')
if(providerType==providerTypeEnum.WECHAT.value){ if(providerType==providerTypeEnum.WECHAT.value){
loginWechat() loginWechat()
}else if(providerType==providerTypeEnum.GOOGLE.value){ }else if(providerType==providerTypeEnum.GOOGLE.value){
...@@ -294,10 +293,8 @@ const useWechatBind = async(code:string) => { ...@@ -294,10 +293,8 @@ const useWechatBind = async(code:string) => {
Message.success(t('personal.bindWechatSuccess')) Message.success(t('personal.bindWechatSuccess'))
getPersonalInfor() getPersonalInfor()
} }
router.push('/accountCenter')
}catch (error: any) { }catch (error: any) {
// Message.error(error.message) Message.error(error.message)
router.push('/accountCenter')
} finally { } finally {
loading.value = false loading.value = false
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment