瀏覽代碼

修改微信授权功能

lex 2 年之前
父節點
當前提交
742919a49a

+ 25 - 15
public/project/initiation.html

@@ -348,20 +348,20 @@
         }
 
         // 判断是否是微信,只能微信中打开
-        // if (!browser().weixin) {
-        //   this.showPopup = true
-        //   return
-        // } else {
-        //   //授权
-        //   const code = getUrlCode()
-        //   console.log(code)
-        //   if (!code) {
-        //     this.getAppIdAndCode(window.location.href)
-        //     return
-        //   } else {
-        //     this.code = code
-        //   }
-        // }
+        if (!browser().weixin) {
+          this.showPopup = true
+          return
+        } else {
+          //授权
+          const code = getUrlCode()
+          console.log(code)
+          if (!code) {
+            this.getAppIdAndCode(window.location.href)
+            return
+          } else {
+            this.code = code
+          }
+        }
 
         if (!this.orchestraId) {
           vant.showToast('信息获取失败,请联系老师')
@@ -405,12 +405,22 @@
             // 判断是否有微信appId
             if (res.data.code === 200 && res.data.data) {
               vant.closeToast()
-              this.goAuth(res.data.data, url)
+              if (/online.lexiaoya/.test(location.href)) {
+                this.goAuth(res.data.data, url)
+              } else {
+                this.goTestAuth(res.data.data, url)
+              }
             }
           } catch {
             //
           }
         },
+        goTestAuth(wxAppId, urlString) {
+          const replaceUrl =
+            `https://online.lexiaoya.cn/getWxCode?appid=${wxAppId || 'wx8654c671631cfade'}&state=STATE&redirect_uri=` +
+            encodeURIComponent(urlString || window.location.href)
+          window.location.replace(replaceUrl)
+        },
         goAuth(wxAppId, urlString) {
           // 用户授权
           console.log(urlString || window.location.href, 'urlString || window.location.href')

+ 25 - 15
public/project/preRegister.html

@@ -380,20 +380,20 @@
         }
 
         // 判断是否是微信,只能微信中打开
-        // if (!browser().weixin) {
-        //   this.showPopup = true
-        //   return
-        // } else {
-        //   //授权
-        //   const code = getUrlCode()
-        //   console.log(code)
-        //   if (!code) {
-        //     this.getAppIdAndCode(window.location.href)
-        //     return
-        //   } else {
-        //     this.code = code
-        //   }
-        // }
+        if (!browser().weixin) {
+          this.showPopup = true
+          return
+        } else {
+          //授权
+          const code = getUrlCode()
+          console.log(code)
+          if (!code) {
+            this.getAppIdAndCode(window.location.href)
+            return
+          } else {
+            this.code = code
+          }
+        }
 
         if (!this.orchestraId) {
           vant.showToast('信息获取失败,请联系老师')
@@ -452,12 +452,22 @@
             // 判断是否有微信appId
             if (res.data.code === 200 && res.data.data) {
               vant.closeToast()
-              this.goAuth(res.data.data, url)
+              if (/online.lexiaoya/.test(location.href)) {
+                this.goAuth(res.data.data, url)
+              } else {
+                this.goTestAuth(res.data.data, url)
+              }
             }
           } catch {
             //
           }
         },
+        goTestAuth(wxAppId, urlString) {
+          const replaceUrl =
+            `https://online.lexiaoya.cn/getWxCode?appid=${wxAppId || 'wx8654c671631cfade'}&state=STATE&redirect_uri=` +
+            encodeURIComponent(urlString || window.location.href)
+          window.location.replace(replaceUrl)
+        },
         goAuth(wxAppId, urlString) {
           // 用户授权
           console.log(urlString || window.location.href, 'urlString || window.location.href')

+ 35 - 33
src/school/companion-teacher/companion-teacher-register.tsx

@@ -33,6 +33,7 @@ import router from '@/router'
 import dayjs from 'dayjs'
 import { browser, getUrlCode } from '@/helpers/utils'
 import qs from 'query-string'
+import { goWechatAuth } from '@/state'
 
 export default defineComponent({
   name: 'companion-teacher-register',
@@ -200,28 +201,28 @@ export default defineComponent({
       }
 
       // 判断是否是微信,只能微信中打开
-      // if (!browser().weixin) {
-      //   state.showPopup = true
-      //   return
-      // } else {
-      //   //授权
-      //   const code = getUrlCode()
-      //   if (!code) {
-      //     const newUrl =
-      //       window.location.origin +
-      //       window.location.pathname +
-      //       '#' +
-      //       route.path +
-      //       '?' +
-      //       qs.stringify({
-      //         ...route.query
-      //       })
-      //     getAppIdAndCode(newUrl)
-      //     return
-      //   } else {
-      //     state.code = code
-      //   }
-      // }
+      if (!browser().weixin) {
+        state.showPopup = true
+        return
+      } else {
+        //授权
+        const code = getUrlCode()
+        if (!code) {
+          const newUrl =
+            window.location.origin +
+            window.location.pathname +
+            '#' +
+            route.path +
+            '?' +
+            qs.stringify({
+              ...route.query
+            })
+          getAppIdAndCode(newUrl)
+          return
+        } else {
+          state.code = code
+        }
+      }
 
       // t: route.query.t, // 过期时间
       try {
@@ -330,22 +331,23 @@ export default defineComponent({
         // 判断是否有微信appId
         if (data) {
           closeToast()
-          goAuth(data, url)
+          // goAuth(data, url)
+          goWechatAuth(data, url)
         }
       } catch {
         //
       }
     }
-    const goAuth = (wxAppId: string, urlString?: string) => {
-      // 用户授权
-      console.log(urlString || window.location.href, 'urlString || window.location.href')
-      const urlNow = encodeURIComponent(urlString || window.location.href)
-      console.log(urlNow, 'urlNow')
-      const scope = 'snsapi_base' //snsapi_userinfo   //静默授权 用户无感知
-      const appid = wxAppId || 'wx8654c671631cfade'
-      const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=STATE&connect_redirect=1#wechat_redirect`
-      window.location.replace(url)
-    }
+    // const goAuth = (wxAppId: string, urlString?: string) => {
+    //   // 用户授权
+    //   console.log(urlString || window.location.href, 'urlString || window.location.href')
+    //   const urlNow = encodeURIComponent(urlString || window.location.href)
+    //   console.log(urlNow, 'urlNow')
+    //   const scope = 'snsapi_base' //snsapi_userinfo   //静默授权 用户无感知
+    //   const appid = wxAppId || 'wx8654c671631cfade'
+    //   const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=STATE&connect_redirect=1#wechat_redirect`
+    //   window.location.replace(url)
+    // }
 
     // 反显数据
     const getTeacherDetails = async () => {

+ 35 - 33
src/school/manage-teacher/manage-teacher-register.tsx

@@ -30,6 +30,7 @@ import dayjs from 'dayjs'
 import { browser, getUrlCode } from '@/helpers/utils'
 import OUpload from '@/components/o-upload'
 import qs from 'query-string'
+import { goWechatAuth } from '@/state'
 
 export default defineComponent({
   name: 'companion-teacher-register',
@@ -130,28 +131,28 @@ export default defineComponent({
       }
 
       // 判断是否是微信,只能微信中打开
-      // if (!browser().weixin) {
-      //   state.showPopup = true
-      //   return
-      // } else {
-      //   //授权
-      //   const code = getUrlCode()
-      //   if (!code) {
-      //     const newUrl =
-      //       window.location.origin +
-      //       window.location.pathname +
-      //       '#' +
-      //       route.path +
-      //       '?' +
-      //       qs.stringify({
-      //         ...route.query
-      //       })
-      //     getAppIdAndCode(newUrl)
-      //     return
-      //   } else {
-      //     state.code = code
-      //   }
-      // }
+      if (!browser().weixin) {
+        state.showPopup = true
+        return
+      } else {
+        //授权
+        const code = getUrlCode()
+        if (!code) {
+          const newUrl =
+            window.location.origin +
+            window.location.pathname +
+            '#' +
+            route.path +
+            '?' +
+            qs.stringify({
+              ...route.query
+            })
+          getAppIdAndCode(newUrl)
+          return
+        } else {
+          state.code = code
+        }
+      }
 
       // t: route.query.t, // 过期时间
       try {
@@ -234,22 +235,23 @@ export default defineComponent({
         // 判断是否有微信appId
         if (data) {
           closeToast()
-          goAuth(data, url)
+          // goAuth(data, url)
+          goWechatAuth(data, url)
         }
       } catch {
         //
       }
     }
-    const goAuth = (wxAppId: string, urlString?: string) => {
-      // 用户授权
-      console.log(urlString || window.location.href, 'urlString || window.location.href')
-      const urlNow = encodeURIComponent(urlString || window.location.href)
-      console.log(urlNow, 'urlNow')
-      const scope = 'snsapi_base' //snsapi_userinfo   //静默授权 用户无感知
-      const appid = wxAppId || 'wx8654c671631cfade'
-      const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=STATE&connect_redirect=1#wechat_redirect`
-      window.location.replace(url)
-    }
+    // const goAuth = (wxAppId: string, urlString?: string) => {
+    //   // 用户授权
+    //   console.log(urlString || window.location.href, 'urlString || window.location.href')
+    //   const urlNow = encodeURIComponent(urlString || window.location.href)
+    //   console.log(urlNow, 'urlNow')
+    //   const scope = 'snsapi_base' //snsapi_userinfo   //静默授权 用户无感知
+    //   const appid = wxAppId || 'wx8654c671631cfade'
+    //   const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=STATE&connect_redirect=1#wechat_redirect`
+    //   window.location.replace(url)
+    // }
 
     const onPreview = (type: string) => {
       if (type === 'REGISTER') {

+ 1 - 1
src/state.ts

@@ -74,7 +74,7 @@ export const goWechatAuth = (wxAppId: string, urlString?: string) => {
   // 开发环境
   if (import.meta.env.DEV) {
     const replaceUrl =
-      `https://online.lexiaoya.cn/getWxCode?appid=${wxAppId}&state=STATE&redirect_uri=` +
+      `https://online.lexiaoya.cn/getWxCode?appid=${wxAppId || 'wx8654c671631cfade'}&state=STATE&redirect_uri=` +
       encodeURIComponent(urlString || window.location.href)
     window.location.replace(replaceUrl)
   }

+ 11 - 10
src/student/music-group/pre-apply/index.tsx

@@ -7,7 +7,7 @@ import Payment from './component/payment'
 import Order from './component/order'
 import { useRoute, useRouter } from 'vue-router'
 
-import { setLogout } from '@/state'
+import { goWechatAuth, setLogout } from '@/state'
 import request from '@/helpers/request'
 import { browser, getUrlCode } from '@/helpers/utils'
 import ODialog from '@/components/o-dialog'
@@ -162,21 +162,22 @@ export default defineComponent({
       window.scrollTo(0, 0)
     }
 
-    const goAuth = (wxAppId: string) => {
-      // 用户授权
-      const urlNow = encodeURIComponent(window.location.href)
-      const scope = 'snsapi_base' //snsapi_userinfo   //静默授权 用户无感知
-      const appid = wxAppId || 'wx8654c671631cfade'
-      const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=STATE&connect_redirect=1#wechat_redirect`
-      window.location.replace(url)
-    }
+    // const goAuth = (wxAppId: string) => {
+    //   // 用户授权
+    //   const urlNow = encodeURIComponent(window.location.href)
+    //   const scope = 'snsapi_base' //snsapi_userinfo   //静默授权 用户无感知
+    //   const appid = wxAppId || 'wx8654c671631cfade'
+    //   const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=STATE&connect_redirect=1#wechat_redirect`
+    //   window.location.replace(url)
+    // }
 
     const getAppIdAndCode = async () => {
       try {
         const { data } = await request.get('/api-student/open/paramConfig/wechatAppId')
         // 判断是否有微信appId
         if (data) {
-          goAuth(data)
+          // goAuth(data)
+          goWechatAuth(data)
         }
       } catch {
         //

+ 11 - 9
src/views/adapay/pay-center/index.tsx

@@ -1,4 +1,5 @@
 import { browser, getUrlCode } from '@/helpers/utils'
+import { goWechatAuth } from '@/state'
 import { Icon } from 'vant'
 import { defineComponent, onMounted, reactive } from 'vue'
 import { useRoute, useRouter } from 'vue-router'
@@ -31,7 +32,8 @@ export default defineComponent({
             state.code = code // 赋值code码
             onPayPage() // 跳转支付页
           } else {
-            goAuth()
+            // goAuth()
+            goWechatAuth(state.wxAppId)
           }
           document.title = '微信支付'
         } else if (pay_channel == 'alipay_qr') {
@@ -66,14 +68,14 @@ export default defineComponent({
         }
       })
     }
-    const goAuth = () => {
-      // 用户授权
-      const urlNow = encodeURIComponent(window.location.href)
-      const scope = 'snsapi_base' //snsapi_userinfo   //静默授权 用户无感知
-      const appid = state.wxAppId || 'wx8654c671631cfade'
-      const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=STATE&connect_redirect=1#wechat_redirect`
-      window.location.replace(url)
-    }
+    // const goAuth = () => {
+    //   // 用户授权
+    //   const urlNow = encodeURIComponent(window.location.href)
+    //   const scope = 'snsapi_base' //snsapi_userinfo   //静默授权 用户无感知
+    //   const appid = state.wxAppId || 'wx8654c671631cfade'
+    //   const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=STATE&connect_redirect=1#wechat_redirect`
+    //   window.location.replace(url)
+    // }
 
     onMounted(() => {
       init()

+ 11 - 9
src/views/adapay/pay-define/index.tsx

@@ -1,5 +1,6 @@
 import request from '@/helpers/request'
 import { browser, getUrlCode, moneyFormat } from '@/helpers/utils'
+import { goWechatAuth } from '@/state'
 import numeral from 'numeral'
 import { Button, Cell, CellGroup, Icon, showToast } from 'vant'
 import { defineComponent, onMounted, reactive } from 'vue'
@@ -119,14 +120,14 @@ export default defineComponent({
       )
     }
 
-    const goAuth = () => {
-      // 用户授权
-      const urlNow = encodeURIComponent(window.location.href)
-      const scope = 'snsapi_base' //snsapi_userinfo   //静默授权 用户无感知
-      const appid = state.wxAppId || 'wx8654c671631cfade'
-      const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=STATE&connect_redirect=1#wechat_redirect`
-      window.location.replace(url)
-    }
+    // const goAuth = () => {
+    //   // 用户授权
+    //   const urlNow = encodeURIComponent(window.location.href)
+    //   const scope = 'snsapi_base' //snsapi_userinfo   //静默授权 用户无感知
+    //   const appid = state.wxAppId || 'wx8654c671631cfade'
+    //   const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=STATE&connect_redirect=1#wechat_redirect`
+    //   window.location.replace(url)
+    // }
 
     const init = () => {
       const pay_channel = state.pay_channel
@@ -138,7 +139,8 @@ export default defineComponent({
           if (code) {
             state.code = code // 赋值code码
           } else {
-            goAuth()
+            // goAuth()
+            goWechatAuth(state.wxAppId)
           }
           state.browserStatus = true
           document.title = '微信支付'

+ 11 - 9
src/views/adapay/pay-result/index.tsx

@@ -1,5 +1,6 @@
 import request from '@/helpers/request'
 import { browser, getUrlCode, moneyFormat } from '@/helpers/utils'
+import { goWechatAuth } from '@/state'
 import {
   Cell,
   CellGroup,
@@ -166,20 +167,21 @@ export default defineComponent({
       //授权
       const code = getUrlCode()
       if (!code) {
-        goAuth()
+        // goAuth()
+        goWechatAuth(state.wxAppId)
       } else {
         state.code = code
         getPayment()
       }
     }
-    const goAuth = () => {
-      // 用户授权
-      const urlNow = encodeURIComponent(window.location.href)
-      const scope = 'snsapi_base' //snsapi_userinfo   //静默授权 用户无感知
-      const appid = state.wxAppId || 'wx8654c671631cfade'
-      const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=STATE&connect_redirect=1#wechat_redirect`
-      window.location.replace(url)
-    }
+    // const goAuth = () => {
+    //   // 用户授权
+    //   const urlNow = encodeURIComponent(window.location.href)
+    //   const scope = 'snsapi_base' //snsapi_userinfo   //静默授权 用户无感知
+    //   const appid = state.wxAppId || 'wx8654c671631cfade'
+    //   const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=STATE&connect_redirect=1#wechat_redirect`
+    //   window.location.replace(url)
+    // }
 
     onMounted(() => {
       init()