|
@@ -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);
|