2025-05-26 08:59:24 +08:00
|
|
|
// src/composables/useWeChatAuth.js
|
|
|
|
import { ref } from 'vue';
|
|
|
|
import request from '@/request/index.js';
|
|
|
|
|
|
|
|
const APPID = 'wx8fc3e4305d2fbf0b';
|
2025-06-03 17:29:22 +08:00
|
|
|
const REDIRECT_URI = encodeURIComponent('https://www.focusnu.com/wechat/thd/#/pages/login/callback');
|
2025-05-26 08:59:24 +08:00
|
|
|
|
|
|
|
export function useWeChatAuth() {
|
|
|
|
const code = ref('');
|
|
|
|
const openid = ref('');
|
|
|
|
const userInfo = ref(null);
|
|
|
|
|
|
|
|
function login(scope = 'snsapi_userinfo', state = '') {
|
|
|
|
const url =
|
|
|
|
`https://open.weixin.qq.com/connect/oauth2/authorize` +
|
|
|
|
`?appid=${APPID}` +
|
|
|
|
`&redirect_uri=${REDIRECT_URI}` +
|
|
|
|
`&response_type=code` +
|
|
|
|
`&scope=${scope}` +
|
|
|
|
`&state=${state}` +
|
|
|
|
`#wechat_redirect`;
|
2025-05-26 16:48:12 +08:00
|
|
|
|
2025-05-26 08:59:24 +08:00
|
|
|
window.location.href = url;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2025-05-26 16:48:12 +08:00
|
|
|
return { login };
|
2025-05-26 08:59:24 +08:00
|
|
|
}
|