|
@@ -72,6 +72,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
private String providerSecret;
|
|
|
public static final String GET_TOKEN_URL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code";
|
|
|
public static final String GET_USERINFO_URL = "https://api.weixin.qq.com/sns/userinfo?access_token=accessToken&openid=openId&lang=zh_CN";
|
|
|
+ //扫码获取企业内部用户信息
|
|
|
+ public static final String GET_CORP_SCANNING_CODE_LOGININFO_URL = " https://qyapi.weixin.qq.com/cgi-bin/service/get_login_info?access_token=PROVIDER_ACCESS_TOKEN";
|
|
|
|
|
|
//用于控制线程锁
|
|
|
public static HashMap<String, CorpwxJobResult> corpwxJobCenter = new HashMap();
|
|
@@ -416,6 +418,83 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg corpWeiXinScanningCodeLogin(String code) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+
|
|
|
+ String url = null;
|
|
|
+ try {
|
|
|
+ url = GET_CORP_SCANNING_CODE_LOGININFO_URL.replace("PROVIDER_ACCESS_TOKEN", getProviderAccessToken());
|
|
|
+ } catch (Exception exception) {
|
|
|
+ exception.printStackTrace();
|
|
|
+ msg.setError(exception.getMessage());
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ 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 reqParam = new JSONObject();
|
|
|
+ reqParam.put("auth_code", code);
|
|
|
+ HttpEntity<JSONObject> Entity = new HttpEntity<>(reqParam, headers);
|
|
|
+ ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, Entity, String.class);
|
|
|
+ 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");
|
|
|
+ String wxUserId = userInfo.getString("open_userid");
|
|
|
+ List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("corpwx_userid", wxUserId));
|
|
|
+ if (userList.size() > 0) {
|
|
|
+ //该用户已存在
|
|
|
+ User curUser = userList.get(0);
|
|
|
+
|
|
|
+ //写死进行测试
|
|
|
+// if (curUser.getName().equals("屈跃庭")) {
|
|
|
+// curUser = userMapper.selectById("7913998191517310976");
|
|
|
+// }
|
|
|
+ Company company = companyMapper.selectOne(new QueryWrapper<Company>().eq("id", curUser.getCompanyId()));
|
|
|
+ WxCorpInfo info = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", curUser.getCompanyId()));
|
|
|
+ curUser.setUserNameNeedTranslate(info.getSaasSyncContact());
|
|
|
+ //检测密码正确时
|
|
|
+ UserVO userVO = new UserVO().setCompanyName(company.getCompanyName());
|
|
|
+ userVO.setCompany(company);
|
|
|
+ BeanUtils.copyProperties(curUser, userVO);
|
|
|
+ if (userVO.getRoleId() == null || userVO.getRoleId() == 0) {
|
|
|
+ //msg.setError("请先联系管理员为您分配角色");
|
|
|
+ msg.setError(MessageUtils.message("user.noRole"));
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ //还要多返回一个公司名字
|
|
|
+ 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()));
|
|
|
+ userVO.setTimeType(timeTypeMapper.selectById(company.getId()));
|
|
|
+ List<Department> manageDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("manager_id", userVO.getId()));
|
|
|
+ List<Integer> deptIds = manageDeptList.stream().map(Department::getDepartmentId).collect(Collectors.toList());
|
|
|
+ int num = 0;
|
|
|
+ if (deptIds.size() > 0) {
|
|
|
+ num = auditWorkflowTimeSettingMapper.selectCount(new QueryWrapper<AuditWorkflowTimeSetting>().in("audit_dept_id", deptIds));
|
|
|
+ }
|
|
|
+ userVO.setHasAuditDept(num>0);
|
|
|
+ setUserRoleMenu(userVO);
|
|
|
+ msg.data = userVO;
|
|
|
+ } else {
|
|
|
+ //msg.setError("该用户尚未绑定企业微信,需要通过账号密码登录");
|
|
|
+ msg.setError(MessageUtils.message("wx.bindError"));
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ System.err.println("====================用户信息获取获取失败======================");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public void setUserRoleMenu(UserVO user) {
|
|
|
Integer roleId = user.getRoleId();
|