Jelajahi Sumber

修改授权回调域名为worktime.ttkuaiban.com

seyason 2 tahun lalu
induk
melakukan
7e7fa91af8

+ 6 - 8
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/AuthRedirectController.java

@@ -56,16 +56,13 @@ public class AuthRedirectController {
     UserMapper userMapper;
 
     @RequestMapping("/corpWXAuth")
-    public ModelAndView auth(String code, Integer state) {
+    public ModelAndView auth(String code, String state) {
         Map<String,Object> reqParam = new HashMap<String,Object>(16);
         String userAgent = request.getHeader("User-Agent");
         //获取设备类型
         String deviceType = UserAgentUtils.getDeviceType(userAgent);
-        if ("MOBILE".equals(deviceType)) {
-            state = 0;
-        } else {
-            state = 1;
-        }
+        boolean isMobile = "MOBILE".equals(deviceType);
+        System.out.println("corpWXAuth state=="+state);
         System.out.println("企微用户登录 code="+code);
         String url = WeiXinCorpController.GET_CORP_USERINFO_URL.replace("SUITE_ACCESS_TOKEN", getSuiteAccessToken()).replace("CODE", code);
         String forObject = this.restTemplate.getForObject(url, String.class);
@@ -89,9 +86,9 @@ public class AuthRedirectController {
         }
         reqParam.put("hasTriedAutoLogin", 1);
         String redirecUrl = null;
-        if (state == 0) {
+        if (isMobile) {
             redirecUrl = "http://mobworktime.ttkuaiban.com";
-        } else if (state == 1) {
+        } else {
             redirecUrl = "http://worktime.ttkuaiban.com";
         }
         ModelAndView modelAndView = new ModelAndView(
@@ -100,6 +97,7 @@ public class AuthRedirectController {
         return modelAndView;
     }
 
+
     @GetMapping("testClient")
     @ResponseBody
     public String test(HttpServletRequest request) {

+ 52 - 48
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/WeiXinCorpController.java

@@ -20,8 +20,11 @@ import org.springframework.http.*;
 import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.client.RestTemplate;
+import org.springframework.web.servlet.ModelAndView;
+import org.springframework.web.servlet.view.RedirectView;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
 import java.net.URLEncoder;
 import java.time.*;
 import java.time.format.DateTimeFormatter;
@@ -86,6 +89,8 @@ public class WeiXinCorpController {
     @Value("${corpId}")
     private String corpId;
 
+    @Resource
+    HttpServletRequest request;
     @Resource
     private SysRoleMapper sysRoleMapper;
     @Resource
@@ -132,11 +137,11 @@ public class WeiXinCorpController {
         public String jsTicket = null;
         public LocalDateTime expireTime = null;
     }
-    public static Map<String, AgentItem> agentCorpTicketMap = new HashMap<String,AgentItem>();
-    public class AgentItem {
+    public static class AgentItem {
         public String jsTicket = null;
         public LocalDateTime expireTime = null;
     }
+    public static Map<String, AgentItem> agentCorpTicketMap = new HashMap<String,AgentItem>();
 
     @Resource
     SysConfigMapper sysConfigMapper;
@@ -1224,58 +1229,53 @@ public class WeiXinCorpController {
         return SUITE_ACCESS_TOKEN;
     }
 
-    @RequestMapping(value = "/bindCorpWeiXin", method = RequestMethod.GET)
-    public HttpRespMsg bindCorpWeiXin(String code, String userId) {
-        HttpRespMsg msg = new HttpRespMsg();
+    @RequestMapping(value = "/bindCorpWeiXin")
+    public ModelAndView bindCorpWeiXin(String code, String userId, Integer state) {
+        Map<String,Object> reqParam = new HashMap<String,Object>(16);
+        String userAgent = request.getHeader("User-Agent");
+        //获取设备类型
+        String deviceType = UserAgentUtils.getDeviceType(userAgent);
+        boolean isMobile = "MOBILE".equals(deviceType);
+        String redirecUrl = null;
+        if (isMobile) {
+            redirecUrl = "http://mobworktime.ttkuaiban.com";
+        } else {
+            redirecUrl = "http://worktime.ttkuaiban.com";
+        }
         User curUser = userMapper.selectById(userId);
         //https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=ACCESS_TOKEN&code=CODE
         if (curUser == null) {
             //msg.setError("该用户不存在,请退出重新登录");
-            msg.setError(MessageUtils.message("user.notExists"));
-            return msg;
-        }
-        String url = null;
-        try {
-            url = GET_CORP_USERINFO_URL.replace("SUITE_ACCESS_TOKEN", getSuiteAccessToken()).replace("CODE", code);
-        } catch (Exception exception) {
-            exception.printStackTrace();
-            msg.setError(exception.getMessage());
-            return msg;
-        }
-        String forObject = this.restTemplate.getForObject(url, String.class);
-        JSONObject obj = JSONObject.parseObject(forObject);
-        String wxUserId = obj.getString("UserId");
-        if (userId == null) {
-            //msg.setError("该用户企业未授权");
-            msg.setError(MessageUtils.message("access.grant"));
+            System.out.println("该用户不存在,请退出重新登录");
+            reqParam.put("errorMsg",MessageUtils.message("user.notExists"));
         } else {
-            curUser.setCorpwxUserid(wxUserId);
-            //如果之前有用户存在该企业微信wxopenid,需要清空掉
-            User newUser = new User();
-            newUser.setCorpwxUserid("");
-            QueryWrapper<User> queryWrapper = new QueryWrapper<>();
-            queryWrapper.eq("corpwx_userid", wxUserId).eq("company_id", curUser.getCompanyId());
-            userMapper.update(newUser, queryWrapper);
-
-            userMapper.updateById(curUser);
-            Company company = companyMapper.selectOne(new QueryWrapper<Company>().eq("id", curUser.getCompanyId()));
+            String url = null;
+            try {
+                url = GET_CORP_USERINFO_URL.replace("SUITE_ACCESS_TOKEN", getSuiteAccessToken()).replace("CODE", code);
+                String forObject = this.restTemplate.getForObject(url, String.class);
+                JSONObject obj = JSONObject.parseObject(forObject);
+                System.out.println("获取授权的用户身份信息:"+obj.toString());
+                String wxUserId = obj.getString("open_userid");
+                String realUserId = obj.getString("UserId");
+                if (userId == null) {
+                    //msg.setError("该用户企业未授权");
+                    System.out.println("该用户企业未授权");
+                    reqParam.put("errorMsg",MessageUtils.message("access.grant"));
+                } else {
+                    curUser.setCorpwxRealUserid(realUserId);
+                    curUser.setCorpwxUserid(wxUserId);
+                    userMapper.updateById(curUser);
+                }
+            } catch (Exception exception) {
+                exception.printStackTrace();
+                reqParam.put("errorMsg",exception.getMessage());
+            }
+        }
 
-            //检测密码正确时
-            UserVO userVO = new UserVO().setCompanyName(company.getCompanyName());
-            userVO.setCompany(company);
-            BeanUtils.copyProperties(curUser, userVO);
-            //还要多返回一个公司名字
-            userVO.setPassword("");
-            LocalDateTime remainingTime = company.getExpirationDate() == null ? LocalDateTime.now() : company.getExpirationDate();
-            userVO.setRemainingTime(remainingTime.toInstant(ZoneOffset.of("+8")).toEpochMilli() -
-                    LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli());
-            //检测是否是项目经理,项目经理有审核功能权限
-            userVO.setLeader(judgeIsLeader(userVO.getId()));
-            userService.setUserRoleMenu(userVO);
-            msg.data = userVO;
+        ModelAndView modelAndView = new ModelAndView(
+                new RedirectView(redirecUrl), reqParam);
 
-        }
-        return msg;
+        return modelAndView;
     }
 
     //企业微信用户登录
@@ -1695,7 +1695,7 @@ public class WeiXinCorpController {
                 if (!userItem.getCorpwxDeptid().equals(oldUser.getCorpwxDeptid())) {
                     changeUser.setId(oldUser.getId());
                     if (userItem.getCorpwxDeptid() != 1) {
-                        changeUser.setDepartmentId(allDeptList.stream().filter(d->d.getCorpwxDeptid().equals(userItem.getCorpwxDeptid())).findFirst().get().getDepartmentId());
+                        changeUser.setDepartmentId(allDeptList.stream().filter(d->d.getCorpwxDeptid() != null && d.getCorpwxDeptid().equals(userItem.getCorpwxDeptid())).findFirst().get().getDepartmentId());
                         //设置层级部门
                         changeUser.setDepartmentCascade(convertDepartmentIdToCascade(changeUser.getDepartmentId(), allDeptList));
                     } else {
@@ -1703,6 +1703,10 @@ public class WeiXinCorpController {
                         changeUser.setDepartmentCascade("0");
                     }
                 }
+                if (oldUser.getCorpwxRealUserid() == null || !userItem.getCorpwxRealUserid().equals(oldUser.getCorpwxRealUserid())) {
+                    changeUser.setId(oldUser.getId());
+                    changeUser.setCorpwxRealUserid(userItem.getCorpwxRealUserid());
+                }
                 if (changeUser.getId() != null) {
                     //有变动
                     finalUpdateUserList.add(changeUser);

+ 1 - 1
fhKeeper/formulahousekeeper/timesheet/src/views/Login.vue

@@ -196,7 +196,7 @@
             },
             tryAutoLogin() {
                 var appId = "ww4e237fd6abb635af";//企业微信第三方的SUIT ID
-                var url = "http://mobworktime.ttkuaiban.com/api/corpWXAuth";//授权回调页面
+                var url = "http://worktime.ttkuaiban.com/api/corpWXAuth";//授权回调页面
                 var weixinUrl="https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri="+encodeURI(url)+"&response_type=code&scope=snsapi_base&state=1#wechat_redirect";
                 window.location.href = weixinUrl;
             },

+ 1 - 1
fhKeeper/formulahousekeeper/timesheet_h5/src/views/login/index.vue

@@ -161,7 +161,7 @@
             },
             tryAutoLogin() {
                 var appId = "ww4e237fd6abb635af";//企业微信第三方的SUIT ID
-                var url = "http://mobworktime.ttkuaiban.com/api/corpWXAuth";//授权回调页面
+                var url = "http://worktime.ttkuaiban.com/api/corpWXAuth";//授权回调页面
                 var weixinUrl="https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri="+encodeURI(url)+"&response_type=code&scope=snsapi_base&state=0#wechat_redirect";
                 window.location.href = weixinUrl;
             },

+ 2 - 3
fhKeeper/formulahousekeeper/timesheet_h5/src/views/my/children/center.vue

@@ -71,11 +71,10 @@
                     appId = "ww4e237fd6abb635af"; //企业微信第三方的SUIT ID
                 } 
 
-                var url = "http://mobworktime.ttkuaiban.com/";//授权回调页面
-                var weixinUrl="https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri="+encodeURI(url)+"&response_type=code&scope=snsapi_base&state="+this.userInfo.id+"#wechat_redirect";
+                var url = "http://worktime.ttkuaiban.com/api/wxcorp/bindCorpWeiXin?userId="+this.userInfo.id;//授权回调页面
+                var weixinUrl="https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appId+"&redirect_uri="+encodeURI(url)+"&response_type=code&scope=snsapi_base&state=0#wechat_redirect";
                 window.location.href = weixinUrl;
             },
-
         },
         create() {