|
@@ -151,6 +151,107 @@ public class AuthRedirectController {
|
|
|
return modelAndView;
|
|
|
}
|
|
|
|
|
|
+ @RequestMapping("/corpWXScanningAuth")
|
|
|
+ public ModelAndView scanningAuth(String auth_code, String state)throws Exception {
|
|
|
+ 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 url = WeiXinCorpController.GET_CORP_SCANNING_CODE_LOGININFO_URL.replace("PROVIDER_ACCESS_TOKEN",wxCorpInfoService.getProviderAccessToken());
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
|
|
|
+ headers.setContentType(type);
|
|
|
+ headers.add("Accept", MediaType.APPLICATION_JSON.toString());
|
|
|
+ JSONObject ob = new JSONObject();
|
|
|
+ ob.put("auth_code", auth_code);
|
|
|
+ HttpEntity<JSONObject> Entity = new HttpEntity<>(ob, headers);
|
|
|
+ ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, Entity, String.class);
|
|
|
+ String redirecUrl = null;
|
|
|
+ if (responseEntity.getStatusCode() == HttpStatus.OK) {
|
|
|
+ String resp = responseEntity.getBody();
|
|
|
+ System.err.println(resp);
|
|
|
+ JSONObject obj = JSONObject.parseObject(resp);
|
|
|
+ if (obj.getIntValue("errcode") == 0) {
|
|
|
+ JSONObject userInfo = obj.getJSONObject("user_info");
|
|
|
+ System.out.println(obj.toString());
|
|
|
+ String wxUserId = userInfo.getString("userid");
|
|
|
+ String openUserId = userInfo.getString("open_userid");
|
|
|
+ JSONObject corpInfo = obj.getJSONObject("corp_info");
|
|
|
+ String corpId = corpInfo.getString("corpid");
|
|
|
+ System.out.println("登录 wxUserId="+wxUserId+", openUserId="+openUserId);
|
|
|
+ List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("corpwx_userid", openUserId));
|
|
|
+ Integer companyId = 0;
|
|
|
+ if (userList.size() > 0) {
|
|
|
+ //该用户已存在
|
|
|
+ User curUser = userList.get(0);
|
|
|
+ System.out.println("找到用户corpwxUserid=="+curUser.getCorpwxUserid());
|
|
|
+ companyId = curUser.getCompanyId();
|
|
|
+ if (curUser.getIsActive() == 1) {
|
|
|
+ reqParam.put("userId", curUser.getId());
|
|
|
+ } else {
|
|
|
+ //提示账号已停用
|
|
|
+ //reqParam.put("errorMsg", "您的账号已停用,无法登录");
|
|
|
+ reqParam.put("errorMsg", MessageUtils.message("user.inactive"));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //使用UserId比对,之前有的老用户存的是UserId
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectById(corpId);
|
|
|
+ if (wxCorpInfo == null) {
|
|
|
+ reqParam.put("errorMsg", MessageUtils.message("user.accountNoExist"));
|
|
|
+ } else {
|
|
|
+ User curUser = userMapper.selectOne(new QueryWrapper<User>().eq("company_id", wxCorpInfo.getCompanyId()).eq("corpwx_userid", wxUserId));
|
|
|
+ if (curUser == null) {
|
|
|
+// reqParam.put("errorMsg", MessageUtils.message("user.accountNoExist"));
|
|
|
+ //用户不存在,去生成该用户
|
|
|
+ if (wxCorpInfo.getSaasSyncContact() == 1) {
|
|
|
+ curUser = wxCorpInfoService.generateUserInfo(wxCorpInfo.getCompanyId(), openUserId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (curUser != null) {
|
|
|
+ if (curUser.getIsActive() == 1) {
|
|
|
+ companyId = curUser.getCompanyId();
|
|
|
+ reqParam.put("userId", curUser.getId());
|
|
|
+ } else {
|
|
|
+ //提示账号已停用
|
|
|
+ //reqParam.put("errorMsg", "您的账号已停用,无法登录");
|
|
|
+ reqParam.put("errorMsg", MessageUtils.message("user.inactive"));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ System.err.println("==生成企业微信User失败==");
|
|
|
+ reqParam.put("errorMsg", MessageUtils.message("user.accountNoExist"));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ reqParam.put("hasTriedAutoLogin", 1);
|
|
|
+ if (!StringUtils.isEmpty(state) && state.length() > 1) {
|
|
|
+ reqParam.put("path", state);
|
|
|
+ }
|
|
|
+ String router = "index";
|
|
|
+ if (companyId > 0) {
|
|
|
+ HashMap compExpireInfo = getCompExpireInfo(companyId);
|
|
|
+ if (compExpireInfo != null) {
|
|
|
+ //过期了
|
|
|
+ router = "expire";
|
|
|
+ reqParam.put("expDate", compExpireInfo.get("expDate"));
|
|
|
+ reqParam.put("version", compExpireInfo.get("version"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (isMobile) {
|
|
|
+ redirecUrl = "http://mobworktime.ttkuaiban.com/#/" + router;
|
|
|
+ } else {
|
|
|
+ redirecUrl = "http://worktime.ttkuaiban.com/#/" + router;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ModelAndView modelAndView = new ModelAndView(
|
|
|
+ new RedirectView(redirecUrl), reqParam);
|
|
|
+
|
|
|
+ return modelAndView;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@RequestMapping("/corpInsideWXAuth")
|
|
|
public ModelAndView authInside(String code, String state) throws Exception{
|