瀏覽代碼

调整测试环境登录

lishanshan 7 月之前
父節點
當前提交
4272885eee
共有 2 個文件被更改,包括 18 次插入4 次删除
  1. 16 3
      src/pages/index/index.vue
  2. 2 1
      src/pages/login/wxLogin.vue

+ 16 - 3
src/pages/index/index.vue

@@ -192,7 +192,20 @@ export default {
   },
   onLoad(query) {
     // 静默登录
-    if (query.code) this.onLogin()
+    // 1. 获取URL中的code和state参数
+    const urlParams = new URLSearchParams(window.location.search)
+    const code = urlParams.get('code')
+    const state = urlParams.get('state')
+
+    // 2. 如果有code参数,就跳转到目标Hash路径并携带参数
+    if (code && state) {
+      const targetUrl = `https://test.baoxianzhanggui.com/fragrance/#/?code=${code}&state=${
+        state || 'STATE'
+      }`
+      // 替换当前页面,避免浏览器返回按钮出现重复授权
+      window.location.replace(targetUrl)
+    }
+    if (query.code) this.onLogin(query.code)
 
     // uni.setStorageSync('wx_copenid', 'o-HEJ6VP2YNi0HPeLaIHCQsQD69s')
     // uni.setStorageSync('access-token', 'eyJhbGciOiJIUzUxMiJ9.eyJ0ZjoiOiJlNGNiNjY0ZS05Y2Q5LTRlOWItODU1Yy0zN2RlNjRiOGI3ZDIifQ.xj0ZBULLc7wYOaUgDQd_zbeynbJ8M3M-UQM6JPUKcV9rIWVlax8dJnU247om39nialcKnklKFZ8m8oerc-NY0A')
@@ -325,8 +338,8 @@ export default {
       )
     },
     // 静默登录
-    onLogin() {
-      let wxCode = this.getUrlCode('code')
+    onLogin(wxCode) {
+      // let wxCode = this.getUrlCode('code')
       let params = {
         code: wxCode,
       }

+ 2 - 1
src/pages/login/wxLogin.vue

@@ -51,7 +51,8 @@
 			},
 			login() {
 				if (this.look) {
-					let ruri = encodeURIComponent('https://test.baoxianzhanggui.com/nightFragrance')
+					// let ruri = encodeURIComponent('https://test.baoxianzhanggui.com/nightFragrance')
+					let ruri = encodeURIComponent('https://test.baoxianzhanggui.com/fragrance/')
 				 	window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa72f643173a90106&redirect_uri=${ruri}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`
 					// 正式——广誉源
 				 	// window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx9dc677bd41e82569&redirect_uri=https://city.baoxianzhanggui.com/fragrance/&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect'