28 lines
731 B
JavaScript
28 lines
731 B
JavaScript
// src/composables/useWeChatAuth.js
|
|
import { ref } from 'vue';
|
|
import request from '@/request/index.js';
|
|
|
|
const APPID = 'wx8fc3e4305d2fbf0b';
|
|
const REDIRECT_URI = encodeURIComponent('https://www.focusnu.com/wechat/thd/#/pages/login/callback');
|
|
|
|
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`;
|
|
|
|
window.location.href = url;
|
|
}
|
|
|
|
|
|
return { login };
|
|
} |