123456789101112131415161718192021222324252627282930 |
- /**
- * 获取 code
- * @returns
- */
- export function getCode () {
- const matched = /[?&]*code=([^&]+)/.exec(location.search)
- if (matched) {
- return decodeURIComponent(matched[1])
- }
- }
-
- /**
- * 跳转授权页面
- */
- export function getRedirectURL (force, code) {
- if (import.meta.env.DEV) return;
-
- const originCode = localStorage.getItem('wxcode');
- const wxfirst = localStorage.getItem('wxfirst') === null;
-
- localStorage.setItem('wxcode', code)
- localStorage.setItem('wxfirst', 'not');
-
- if (force || wxfirst || !code || code === originCode) {
- const origin = location.origin + location.pathname
- const searchStr = location.search.replace(/code\=[^&]+/, '').replace(/state\=[^&]+/, '').replace(/^&+/, '').replace(/\?+$/, '')
- const local = encodeURIComponent(origin + searchStr + location.hash)
- return `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd3bab568bc42d1de&redirect_uri=${local}&response_type=code&scope=snsapi_base&state=123#wechat_redirect`
- }
- }
|