|
@@ -1,11 +1,37 @@
|
1
|
1
|
|
2
|
|
-function wxsdk() {
|
3
|
|
- const isDev = import.meta.env.DEV
|
|
2
|
+let APPID = '';
|
|
3
|
+const isDev = import.meta.env.DEV
|
|
4
|
+
|
|
5
|
+/**
|
|
6
|
+ * 获取 code
|
|
7
|
+ * @returns
|
|
8
|
+ */
|
|
9
|
+export function getCode () {
|
|
10
|
+ if (isDev) return '123';
|
|
11
|
+
|
|
12
|
+ const matched = /[?&]*code=([^&]+)/.exec(location.search)
|
|
13
|
+ if (matched) {
|
|
14
|
+ return decodeURIComponent(matched[1])
|
|
15
|
+ }
|
|
16
|
+}
|
4
|
17
|
|
|
18
|
+/**
|
|
19
|
+ * 跳转授权页面
|
|
20
|
+ */
|
|
21
|
+export function redirect () {
|
|
22
|
+ if (isDev) return;
|
|
23
|
+
|
|
24
|
+ const appid = APPID || 'wx5d0c5a7f210d872f';
|
|
25
|
+ const local = encodeURIComponent(location.origin + location.pathname)
|
|
26
|
+ const scope = 'snsapi_userinfo'; // snsapi_base
|
|
27
|
+ const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${local}&response_type=code&scope=${scope}&state=123#wechat_redirect`
|
|
28
|
+ window.location.href = url;
|
|
29
|
+}
|
|
30
|
+
|
|
31
|
+function wxsdk() {
|
5
|
32
|
// API_BASE 来源 public/config.js
|
6
|
33
|
const apiBase = API_BASE // import.meta.env.VITE_APP_API_BASE
|
7
|
34
|
|
8
|
|
- let APPID = '';
|
9
|
35
|
|
10
|
36
|
// 分享接口
|
11
|
37
|
const shareAPIs = [
|
|
@@ -69,32 +95,6 @@ function wxsdk() {
|
69
|
95
|
});
|
70
|
96
|
}
|
71
|
97
|
|
72
|
|
- /**
|
73
|
|
- * 获取 code
|
74
|
|
- * @returns
|
75
|
|
- */
|
76
|
|
- function getCode () {
|
77
|
|
- if (isDev) return '123';
|
78
|
|
-
|
79
|
|
- const matched = /[?&]*code=([^&]+)/.exec(location.search)
|
80
|
|
- if (matched) {
|
81
|
|
- return decodeURIComponent(matched[1])
|
82
|
|
- }
|
83
|
|
- }
|
84
|
|
-
|
85
|
|
- /**
|
86
|
|
- * 跳转授权页面
|
87
|
|
- */
|
88
|
|
- function redirect () {
|
89
|
|
- if (isDev) return;
|
90
|
|
-
|
91
|
|
- const appid = APPID || 'wx5d0c5a7f210d872f';
|
92
|
|
- const local = encodeURIComponent(location.origin + location.pathname)
|
93
|
|
- const scope = 'snsapi_userinfo'; // snsapi_base
|
94
|
|
- const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${local}&response_type=code&scope=${scope}&state=123#wechat_redirect`
|
95
|
|
- window.location.href = url;
|
96
|
|
- }
|
97
|
|
-
|
98
|
98
|
return {
|
99
|
99
|
share,
|
100
|
100
|
getCode,
|