彭景 10 months ago
parent
commit
fdb39bf58e

+ 1 - 1
h5app/public/appconfig.json

@@ -1,5 +1,5 @@
 {
   "isDev": true,
-  "webSiteUrl": "http://www.bowintek.com/hzyz/mobile/index.html/#",
+  "webSiteUrl": "http://www.bowintek.com/hzyz/mobile",
   "webApiServiceUrl": "/api"
 }

+ 3 - 4
h5app/src/App.vue

@@ -21,7 +21,7 @@ const user = ref(userStore.getUserInfo);
 if (user.value != null) {
   globalProperties.$routeActive = true;
 } else {
-  let redirectUrl = "/login";
+  let redirectUrl = "";
 
   const url = location.href;
 
@@ -32,9 +32,8 @@ if (user.value != null) {
     redirectUrl = splits[1];
   }
 
-  redirectUrl = redirectUrl.replace("/index?redirectUrl=", "").replace("/?redirectUrl=","").replace("?redirectUrl=","");
-
-  router.push({path: "/index", query: {redirectUrl: redirectUrl}})
+  if (!redirectUrl || redirectUrl==='/')
+     router.push({path: "/login", query: {}})
 }
 
 </script>

+ 2 - 2
h5app/src/router/index.ts

@@ -11,10 +11,10 @@ import JobUserInfoCompanyEdit from '../views/pages/jobUserInfo/companyEdit.vue';
 import IndexPage from '../views/index.vue';
 
 const routes: Array<RouteRecordRaw> = [
-    {
+    /*{
         path: '/',
         redirect: '/index'
-    },
+    },*/
     {
         path: '/tabs/',
         component: StudentTabsPage,

+ 4 - 2
h5app/src/utils/urlUtils.ts

@@ -34,8 +34,10 @@ export const uniqueSlash = (path: string) => path.replace(/(https?:\/)|(\/)+/g,
 
 
 export function getUrlParams() {
-    let href = decodeURIComponent(location.href);
-    href = decodeURIComponent(href);
+    /*let href = decodeURIComponent(location.href);
+    href = decodeURIComponent(href);*/
+    const href = location.href;
+
     /*alert("href:"+href);*/
     const theRequest = new Object();
     let urls = [];

+ 12 - 38
h5app/src/utils/wechat.ts

@@ -10,27 +10,18 @@ export function isWechat() {
     /* return true;*/
 }
 
-export const wxAuth = async <Object>(redirectUrl: string): Promise<string> => {
-    /*alert("22redirectUrl:" + decodeURIComponent(redirectUrl));*/
-    redirectUrl = decodeURIComponent(redirectUrl)
+export const wxAuth = async <Object>(routePath: string): Promise<string> => {
     try {
         const userStore = useUserStore();
-        let oAuthUrl_redirectUrl = "";
         const router = useRouter();
+        const urlParams = getUrlParams() as any;
+        const openId = urlParams["openId"] || userStore.getOpenId;
+        const code = urlParams["code"];
 
-        if (isWechat() && !userStore.getOpenId) {
-            await getConfig().then((data: any) => {
-                oAuthUrl_redirectUrl = data.webSiteUrl + "?redirectUrl=" + redirectUrl;
-            })
-            const urlParams = getUrlParams() as any;
-            const code = urlParams["code"];
-            const openId = urlParams["openId"];
+        if (isWechat()) {
             if (openId) {
                 userStore.setOpenId(openId);
-                /*alert("22redirectUrl:" + decodeURIComponent(redirectUrl));*/
-                router.push(redirectUrl);
             } else {
-                /* alert("33redirectUrl:" + decodeURIComponent(redirectUrl));*/
                 if (!code) {
                     const loading = await loadingController.create({
                         cssClass: 'my-custom-class',
@@ -39,6 +30,11 @@ export const wxAuth = async <Object>(redirectUrl: string): Promise<string> => {
                     });
                     await loading.present();
 
+                    let oAuthUrl_redirectUrl = "";
+                    await getConfig().then((data: any) => {
+                        oAuthUrl_redirectUrl = data.webSiteUrl + "?routePath=" + encodeURIComponent(routePath); //www.aa.com/mobile?routePath=xxxxx
+                    })
+
                     getOAuthUrl(encodeURIComponent(oAuthUrl_redirectUrl)).then((res: any) => {
                         if (res) {
                             window.location.replace(res);
@@ -56,36 +52,14 @@ export const wxAuth = async <Object>(redirectUrl: string): Promise<string> => {
                     await getWxOpenId(code).then((res: any) => {
                         userStore.setOpenId(res);
 
-                        const currentUrl = redirectUrl + (redirectUrl.indexOf("?") >= 0 ? "&" : "?") + "openId=" + res;
-
-                        alert("currentUrl:" + currentUrl);
+                        const currentUrl = routePath + (routePath.indexOf("?") >= 0 ? "&" : "?") + "openId=" + res;
 
                         router.push(currentUrl);
                     });
                 }
             }
-        } else {
-            router.push(decodeURIComponent(redirectUrl));
-
-        }        /* const router = useRouter();
-         await getWxOpenId("").then((res: any) => {
-             userStore.setOpenId(res);
-
-             const currentUrl = redirectUrl + (redirectUrl.indexOf("?") >= 0 ? "&" : "?") + "openId=" + res;
-
-             alert("currentUrl:" + currentUrl);
-
-             router.push(currentUrl);
-         },()=>{
-             userStore.setOpenId("2222");
-
-
-             const currentUrl = redirectUrl + (redirectUrl.indexOf("?") >= 0 ? "&" : "?") + "openId=2222";
-
-             alert("currentUrl222:" + currentUrl);
+        }
 
-             router.push(currentUrl);
-         });*/
         return "";
     } catch (e) {
         return Promise.reject(null);

+ 10 - 8
h5app/src/views/index.vue

@@ -11,6 +11,8 @@ import {useRoute, useRouter} from "vue-router";
 import {useUserStore} from "@/store/modules/user";
 import {isWechat, wxAuth} from "@/utils/wechat";
 import {onIonViewDidEnter} from "@ionic/vue";
+import {getUrlParams} from "@/utils/urlUtils";
+import {alert} from "ionicons/icons";
 
 export default defineComponent({
   name: "sysindex",
@@ -18,22 +20,22 @@ export default defineComponent({
     const route = useRoute();
     const router = useRouter();
     const userStore = useUserStore();
-    const redirectUrl = ref("");
+    const urlParams = getUrlParams();
+    const routePath = ref("");
 
     const wxLogin = async function () {
-      await wxAuth(redirectUrl.value);
+      await wxAuth(routePath.value);
     };
 
     onIonViewDidEnter(() => {
-      redirectUrl.value = route.query.redirectUrl || '/login';
-      if (redirectUrl.value === '/index') {
-        redirectUrl.value = '/login';
-      }
+      routePath.value = urlParams["routePath"] || '/login';
+
+      routePath.value = decodeURIComponent(routePath.value);
 
-      if (isWechat() && redirectUrl.value.indexOf("wxMessage") < 0) {
+      if (isWechat() && routePath.value.indexOf("wxMessage") < 0) {
         wxLogin();
       } else {
-        router.push(redirectUrl.value);
+        router.push(routePath.value);
       }
 
     });

+ 4 - 6
src/main/java/com/hz/employmentsite/controller/AppController.java

@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 import java.util.Date;
 import java.util.HashMap;
@@ -58,12 +59,9 @@ public class AppController {
     }
 
     @GetMapping("mobile")
-    public String mobile(String ticket,String loginType) {
-        /*if (!stringUtils.IsNullOrEmpty(ticket))
-            return "redirect:/mobile/index.html?ticket=" + encoderTicket(ticket,appConfig.oauthconfig_mobileServiceUrl);
-
-        if (!stringUtils.IsNullOrEmpty(loginType))
-            return "redirect:/mobile/index.html?loginType=" + loginType;*/
+    public String mobile(String routePath,String code) throws UnsupportedEncodingException {
+        if (!stringUtils.IsNullOrEmpty(routePath))
+            return "redirect:/mobile/index.html/#/index?routePath=" + URLEncoder.encode(routePath,"UTF-8")+"&code="+code;
 
         return "redirect:/mobile/index.html";
     }

+ 8 - 1
src/main/java/com/hz/employmentsite/controller/WxController.java

@@ -5,6 +5,7 @@ import com.hz.employmentsite.filter.exception.BaseResponse;
 import com.hz.employmentsite.filter.exception.RespGenerstor;
 import com.hz.employmentsite.services.service.WechatService;
 import com.hz.employmentsite.util.QrCodeUtils;
+import lombok.extern.slf4j.Slf4j;
 import me.chanjar.weixin.common.error.WxErrorException;
 import org.apache.tomcat.util.buf.UDecoder;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -23,6 +24,7 @@ import java.util.UUID;
 
 @RestController
 @RequestMapping("/api/wx")
+@Slf4j
 public class WxController {
 
     /*@Autowired
@@ -47,7 +49,12 @@ public class WxController {
 
     @GetMapping("getOAuthUrl")
     public BaseResponse<String> getOAuthUrl(String redirectUrl) throws UnsupportedEncodingException {
-        return RespGenerstor.success(wechatService.getOAuthUrl(URLDecoder.decode(redirectUrl, "UTF-8")));
+
+        String url = wechatService.getOAuthUrl(URLDecoder.decode(redirectUrl, "UTF-8"));
+
+        log.info("getOAuthUrl:" + url);
+
+        return RespGenerstor.success(url);
     }
 
 

+ 11 - 2
src/main/java/com/hz/employmentsite/services/impl/WechatServiceImpl.java

@@ -17,6 +17,8 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
 import java.util.*;
 
 @Service("WechatService")
@@ -177,7 +179,7 @@ public class WechatServiceImpl implements WechatService {
     }
 
     @Override
-    public String getQrcodeUrl(String url, String userId) {
+    public String getQrcodeUrl(String url, String userId){
         Date nowDate = dateUtils.formatDateToYYYYMMDD(new Date());
 
         WxQrcodeExample exp = new WxQrcodeExample();
@@ -193,7 +195,14 @@ public class WechatServiceImpl implements WechatService {
             Map<String, String> params = new HashMap<>();
             params.put("userId", userId);
             params.put("qrCodeId", qrCodeId);
-            String fullUrl = appConfig.wxMessageBaseUrl + "?redirectUrl=" + urlUtils.getUrl(url, params);
+            String fullUrl = "";
+            try{
+                //www.aa.com/mobile/index.html/#/index?routePath=xxxxxxxxxxxxxx
+                fullUrl = appConfig.wxMessageBaseUrl + "/index?routePath=" + URLEncoder.encode(urlUtils.getUrl(url, params),"UTF-8");
+            }
+            catch (Exception e){
+                return "";
+            }
 
             dbData = new WxQrcode();
             dbData.setQrcodeId(qrCodeId);

+ 2 - 1
src/main/java/com/hz/employmentsite/services/service/WechatService.java

@@ -4,6 +4,7 @@ import com.hz.employmentsite.model.WxMessagetempsetting;
 import com.hz.employmentsite.model.WxMessagetempsettingField;
 import me.chanjar.weixin.common.error.WxErrorException;
 
+import java.io.UnsupportedEncodingException;
 import java.util.List;
 import java.util.Map;
 
@@ -19,7 +20,7 @@ public interface WechatService {
 
     List<WxMessagetempsettingField> getWxMessagetempFieldList(String templateNo);
 
-    String getQrcodeUrl(String url, String userId);
+    String getQrcodeUrl(String url, String userId) throws UnsupportedEncodingException;
 
     Boolean qrcodeVerify(String qrCodeId, String openId);