|
@@ -36,6 +36,8 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
+import org.springframework.web.servlet.ModelAndView;
|
|
|
+import org.springframework.web.servlet.view.RedirectView;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
@@ -1760,45 +1762,61 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
System.out.println("返回信息==" + resp);
|
|
|
dataMap.put("resp", resp);
|
|
|
JSONObject OpenidJSONO = JSONObject.parseObject(resp);
|
|
|
- result = OpenidJSONO;
|
|
|
- //{"access_token":"32_sheMcGJRDYXVaBoc06o8iT9CyxquudqHl90qGKHg_MGxFhpFA5S8WKUL_mCnfY7O1gcJpS_gBFa4w5Vqb8pCHA","expires_in":7200,"refresh_token":"32_c4ocyhmbbbKyEmG4pS-ywgbV7FkK3A29F_GdZdHKrcvidy0amQeGmhBAo1WBcEWn0T7kSxjbp0BI4lYYtY4wAw","openid":"o1L3L5lOrOl3_UEJjONaoT2Rne1I","scope":"snsapi_userinfo"}
|
|
|
if (OpenidJSONO.containsKey("access_token")) {
|
|
|
// OpenidJSONO可以得到的内容:access_token expires_in refresh_token openid scope
|
|
|
String openid = String.valueOf(OpenidJSONO.get("openid"));
|
|
|
- String accessToken = String.valueOf(OpenidJSONO.get("access_token"));
|
|
|
- // 用户保存的作用域
|
|
|
- String scope = String.valueOf(OpenidJSONO.get("scope"));
|
|
|
- String refresh_token = String.valueOf(OpenidJSONO.get("refresh_token"));
|
|
|
|
|
|
- // 第四步:拉取用户信息(需scope为 snsapi_userinfo)
|
|
|
-// String url = GET_USERINFO_URL.replaceAll("accessToken", accessToken).replaceAll("openId", openid);
|
|
|
-// responseEntity = this.restTemplate.exchange(url,
|
|
|
-// HttpMethod.GET, null, String.class);
|
|
|
-// resp = responseEntity.getBody();
|
|
|
-// log.debug("获取微信个人信息返回==" + resp);
|
|
|
-// System.out.println("获取微信个人信息返回==" + resp);
|
|
|
-// JSONObject json = JSONObject.parseObject(resp);
|
|
|
User user = new User();
|
|
|
user.setId(userId);
|
|
|
user.setWxOpenid(openid);
|
|
|
userMapper.updateById(user);
|
|
|
-// if (!json.containsKey("errcode")) {
|
|
|
-// user.setWxOpenid(openid);
|
|
|
-// }
|
|
|
- //创建用户
|
|
|
-// int cnt = wechatUserMapper.selectCount(new QueryWrapper<WechatUser>().eq("open_id", openid));
|
|
|
-// if (cnt == 0) {
|
|
|
-// //检查昵称是否存在
|
|
|
-// WechatUser one = wechatUserMapper.selectOne(new QueryWrapper<WechatUser>().eq("nickname", user.getNickname()));
|
|
|
-// if (one != null) {
|
|
|
-// //按昵称更新
|
|
|
-// one.setAvatar(user.getAvatar());
|
|
|
-// one.setOpenId(user.getOpenId());
|
|
|
-// wechatUserMapper.updateById(one);
|
|
|
-// } else {
|
|
|
-// wechatUserMapper.insert(user);
|
|
|
-// }
|
|
|
-// }
|
|
|
+ //检测密码正确时
|
|
|
+ User u = userMapper.selectById(userId);
|
|
|
+
|
|
|
+ Company company = companyMapper.selectById(u.getCompanyId());
|
|
|
+ UserVO userVO = new UserVO().setCompanyName(company.getCompanyName());
|
|
|
+ userVO.setCompany(company);
|
|
|
+ BeanUtils.copyProperties(u, 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()));
|
|
|
+
|
|
|
+ setUserRoleMenu(userVO);
|
|
|
+ respMsg.data = userVO;
|
|
|
+ } else {
|
|
|
+ respMsg.setError(OpenidJSONO.getString("errcode") + ":" + OpenidJSONO.getString("errmsg"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return respMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ public HttpRespMsg bindWeiXin2(String code, String userId, Integer state) {
|
|
|
+ HttpRespMsg respMsg = new HttpRespMsg();
|
|
|
+ System.out.println("code==" + code);
|
|
|
+ // 拼接用户授权接口信息
|
|
|
+ String requestUrl = GET_TOKEN_URL.replace("APPID", appId).replace("SECRET", appSecret)
|
|
|
+ .replace("CODE", code);
|
|
|
+ // 存储获取到的授权字段信息
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ Map<String, String> dataMap = new HashMap<>();
|
|
|
+ ResponseEntity<String> responseEntity = this.restTemplate.exchange(requestUrl,
|
|
|
+ HttpMethod.GET, null, String.class);
|
|
|
+ if (responseEntity.getStatusCode() == HttpStatus.OK) {
|
|
|
+ String resp = responseEntity.getBody();
|
|
|
+ System.out.println("返回信息==" + resp);
|
|
|
+ dataMap.put("resp", resp);
|
|
|
+ JSONObject OpenidJSONO = JSONObject.parseObject(resp);
|
|
|
+ if (OpenidJSONO.containsKey("access_token")) {
|
|
|
+ // OpenidJSONO可以得到的内容:access_token expires_in refresh_token openid scope
|
|
|
+ String openid = String.valueOf(OpenidJSONO.get("openid"));
|
|
|
+
|
|
|
+ User user = new User();
|
|
|
+ user.setId(userId);
|
|
|
+ user.setWxOpenid(openid);
|
|
|
+ userMapper.updateById(user);
|
|
|
//检测密码正确时
|
|
|
User u = userMapper.selectById(userId);
|
|
|
|
|
@@ -2702,4 +2720,108 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
}
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ModelAndView loginByWXCode(String code, String 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 requestUrl = GET_TOKEN_URL.replace("APPID", appId).replace("SECRET", appSecret)
|
|
|
+ .replace("CODE", code);
|
|
|
+ // 存储获取到的授权字段信息
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ Map<String, String> dataMap = new HashMap<>();
|
|
|
+ ResponseEntity<String> responseEntity = this.restTemplate.exchange(requestUrl,
|
|
|
+ HttpMethod.GET, null, String.class);
|
|
|
+ List<User> userList = new ArrayList<>();
|
|
|
+ if (responseEntity.getStatusCode() == HttpStatus.OK) {
|
|
|
+ String resp = responseEntity.getBody();
|
|
|
+ log.debug("返回信息==" + resp);
|
|
|
+ System.out.println("返回信息==" + resp);
|
|
|
+ dataMap.put("resp", resp);
|
|
|
+ JSONObject OpenidJSONO = JSONObject.parseObject(resp);
|
|
|
+ if (OpenidJSONO.containsKey("access_token")) {
|
|
|
+ // OpenidJSONO可以得到的内容:access_token expires_in refresh_token openid scope
|
|
|
+ String openid = String.valueOf(OpenidJSONO.get("openid"));
|
|
|
+ userList = userMapper.selectList(new QueryWrapper<User>().eq("wx_openid", openid));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Integer companyId = null;
|
|
|
+ if (userList.size() > 0) {
|
|
|
+ //该用户已存在
|
|
|
+ User curUser = userList.get(0);
|
|
|
+ companyId = curUser.getCompanyId();
|
|
|
+ if (curUser.getIsActive() == 1) {
|
|
|
+ reqParam.put("userId", curUser.getId());
|
|
|
+ } else {
|
|
|
+ //提示账号已停用
|
|
|
+ //reqParam.put("errorMsg", "您的账号已停用,无法登录");
|
|
|
+ reqParam.put("errorMsg", MessageUtils.message("user.inactive"));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //该用户不存在
|
|
|
+ reqParam.put("errorMsg", "您的账号不存在,无法登录");
|
|
|
+ }
|
|
|
+ reqParam.put("hasTriedAutoLogin", 1);
|
|
|
+ if (!org.apache.commons.lang3.StringUtils.isEmpty(state) && state.length() > 1) {
|
|
|
+ reqParam.put("path", state);
|
|
|
+ }
|
|
|
+
|
|
|
+ String redirecUrl = null;
|
|
|
+ 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 = "https://mobworktime.ttkuaiban.com/#/" + router;
|
|
|
+ } else {
|
|
|
+ redirecUrl = "https://worktime.ttkuaiban.com/#/" + router;
|
|
|
+ }
|
|
|
+ ModelAndView modelAndView = new ModelAndView(
|
|
|
+ new RedirectView(redirecUrl), reqParam);
|
|
|
+
|
|
|
+ return modelAndView;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private HashMap getCompExpireInfo(Integer companyId) {
|
|
|
+ Company company = companyMapper.selectById(companyId);
|
|
|
+ int version = 1;
|
|
|
+ if (company.getPackageProject() == 1) {
|
|
|
+ version = 2;
|
|
|
+ }
|
|
|
+ if (company.getPackageOa() == 1) {
|
|
|
+ version = 3;
|
|
|
+ }
|
|
|
+ if (company.getPackageEngineering() == 1) {
|
|
|
+ version = 4;
|
|
|
+ }
|
|
|
+ boolean hasExp = false;
|
|
|
+ LocalDateTime expirationDate = company.getExpirationDate();
|
|
|
+ DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ if (null != company.getExpirationDate()) {
|
|
|
+ if (expirationDate.isBefore(LocalDateTime.now())) {
|
|
|
+ hasExp = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (hasExp) {
|
|
|
+ String format = dtf.format(expirationDate);
|
|
|
+ HashMap map = new HashMap();
|
|
|
+ map.put("version", version);
|
|
|
+ map.put("expDate", format);
|
|
|
+ return map;
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|