From b56640e5f85de5e2553b33a21d361a49e1400b81 Mon Sep 17 00:00:00 2001 From: gaojuan Date: Tue, 7 Sep 2021 16:43:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=A4=E6=B5=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../open/controllers/UsersController.java | 9 +- .../controllers/weixin/UserController.java | 149 +++++++++++++++++- .../fangjia/open/model/weixin/Message.java | 2 + .../fangjia/open/model/weixin/UserModel.java | 18 +++ .../src/main/webapp/district/weXinList.ftl | 3 + .../main/webapp/static/images/login_code.png | Bin 0 -> 9042 bytes .../webapp/static/images/login_mobile.png | Bin 0 -> 7426 bytes .../src/main/webapp/static/style/wx.css | 12 +- .../src/main/webapp/user/bhydLoginPage.ftl | 129 ++++++++++++++- .../src/main/webapp/user/setup.ftl | 128 +++++++++++++++ 10 files changed, 436 insertions(+), 14 deletions(-) create mode 100644 projects/fangjia-open/src/main/webapp/static/images/login_code.png create mode 100644 projects/fangjia-open/src/main/webapp/static/images/login_mobile.png create mode 100644 projects/fangjia-open/src/main/webapp/user/setup.ftl diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/UsersController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/UsersController.java index bc3ce63bb..2c5bbea24 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/UsersController.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/UsersController.java @@ -1,8 +1,13 @@ package com.fangjia.open.controllers; +import java.util.Date; import java.util.HashMap; import java.util.Map; +import com.fangjia.core.util.AnalyticsUtil; +import com.fangjia.dal.mongo.model.SendSmsLog; +import com.fangjia.open.model.weixin.SendCodeJsonModel; +import com.fangjia.open.model.weixin.SendCodeModel; import net.sf.json.JSONObject; import org.apache.commons.codec.digest.DigestUtils; @@ -18,6 +23,8 @@ import com.fangjia.service.mongo.mobile.UserInfoService; import com.fangjia.service.sql.UserService; import com.fangjia.service.util.UsersUtils; +import javax.servlet.http.HttpServletRequest; + public class UsersController { private UserService userService; private UserInfoService userInfoService; @@ -114,5 +121,5 @@ public class UsersController { this.userInfoService = userInfoService; } - + } diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/weixin/UserController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/weixin/UserController.java index d40136cb2..fc03b5129 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/weixin/UserController.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/weixin/UserController.java @@ -12,6 +12,7 @@ import javax.servlet.http.HttpServletResponse; import com.fangjia.dal.common.XcxKey; import com.fangjia.dal.mongo.model.bkoff.XcxUserInfo; +import com.fangjia.service.fangjia.FangJiaUserService; import com.fangjia.service.mongo.fangjia.XcxUserInfoService; import com.fangjia.service.open.WeChatAuthService; import com.fangjia.service.open.WeChatAuthServiceImpl; @@ -296,6 +297,70 @@ public class UserController { } + + public Object enterpriseLoginBHAction(UserModel model, HttpServletResponse response, HttpServletRequest request) { + UserJsonModel resultModel = new UserJsonModel(); + resultModel.setResult(Message.RESULT_FAIL); + String username = StringUtils.trimToNull(model.getUsername()); + String pass = StringUtils.trimToNull(model.getPass()); + String code = model.getCode(); + String type = StringUtils.trimToNull(model.getType()); + + String cacheCode = getCacheCode(username, type, request); + if (cacheCode == null) { + resultModel.setMsg(Message.MOBILE_NOT_SEND_CODE); + return resultModel; + } + if (!cacheCode.equals(code)) { + resultModel.setMsg(Message.CODE_ERROR); + return resultModel; + } + + String weiXinId = CookieUtils.getCookieValue(request,"we_chat_open_id"); + + if(StringUtils.isBlank(weiXinId) && StringUtils.isNotBlank(model.getCode())){ + System.out.println("С³ÌÐòcode:"+model.getCode()); + System.out.println("С³ÌÐòAppId:"+model.getAppId()); + System.out.println("С³ÌÐòAppSecret:"+model.getAppSecret()); + System.out.println("sid:"+model.getSid()); + XcxKey sessionValue = getSessionValue(model.getCode(), null, model.getAppId(), model.getAppSecret()); + if(sessionValue!=null){ + weiXinId = sessionValue.getOpenId(); + } + if(weiXinId == null) { + weiXinId = CookieUtils.getCookieValue(request,"we_chat_open_id"); + } + if(weiXinId != null && !weiXinId.equals("")){ + CookieUtils.setCookie("we_chat_open_id", weiXinId, "/", 60 * 60 * 24 *7, response); + } + System.out.println("[sid]С³ÌÐò΢ÐÅOPEN_ID£º" + weiXinId); + } + + //²âÊÔʱ¿ÉÒÔÏÈȥµô + if (StringUtils.isBlank(username) || StringUtils.isBlank(pass) || StringUtils.isBlank(weiXinId)){ + resultModel.setMsg(Message.PARAM_NOT_NULL); + return resultModel; + } + + try { + FjtUsers user = usersInfoService.enterpriseLogin(username, pass); + if(user == null) { + resultModel.setMsg(Message.LOGIN_FAIL); + return resultModel; + } + CookieUtils.setCookie("login_user_id", user.getId() + "", "/", 60 * 60 * 24 *7, response); + CookieUtils.setCookie("login_user_type", "b", "/", 60 * 60 * 24 *7, response); + CookieUtils.setCookie("login_enterpriseuser_weixinid", weiXinId, "/", 60 * 60 * 24 *7, response); + //CacheUtils.putValue(CachePolicyEnum.LONG, UsersInfoService.class, weiXinId + "_" + Message.SMS_CODE_TYPE_ENTER_LOGIN , user.getId()); + resultModel.setResult(Message.RESULT_SUCCESS); + return resultModel; + } catch (Exception e) { + e.printStackTrace(); + resultModel.setMsg(e.getMessage()); + return resultModel; + } + } + public XcxKey getSessionValue(String code, String sid, String appId, String secret){ XcxKey sessionValue = null; if(StringUtils.isNotBlank(sid)){ @@ -347,18 +412,31 @@ public class UserController { String type = StringUtils.trimToNull(model.getType()); String codeToken = StringUtils.trimToNull(model.getCodeToken()); String code = StringUtils.trimToNull(model.getCode()); - if (StringUtils.isBlank(mobile) || StringUtils.isBlank(type) || StringUtils.isBlank(codeToken) || StringUtils.isBlank(code)) { - resultModel.setResult(Message.RESULT_FAIL); - resultModel.setMsg(Message.PARAM_NOT_NULL); - return resultModel; + if(StringUtils.isNotBlank(type) && type.equals("bindmobilebh")){ + if (StringUtils.isBlank(mobile)) { + resultModel.setResult(Message.RESULT_FAIL); + resultModel.setMsg(Message.PARAM_NOT_NULL); + return resultModel; + } + }else{ + if (StringUtils.isBlank(mobile) || StringUtils.isBlank(type) || StringUtils.isBlank(codeToken) || StringUtils.isBlank(code)) { + resultModel.setResult(Message.RESULT_FAIL); + resultModel.setMsg(Message.PARAM_NOT_NULL); + return resultModel; + } } + String cacheCode = getCacheCode(codeToken, Message.SMS_CODE_TYPE_LOGIN, request); - if(!code.equals(cacheCode)){ + if(!type.equals("bindmobilebh") && !code.equals(cacheCode)){ resultModel.setResult(Message.RESULT_FAIL); resultModel.setMsg(Message.IMG_CODE_ERROR); return resultModel; } - return sendCode(model, resultModel, mobile, type, resp); + if(type.equals("bindmobilebh")){ + return sendBHCode(model, resultModel, mobile, type, resp); + }else{ + return sendCode(model, resultModel, mobile, type, resp); + } } /** @@ -399,6 +477,34 @@ public class UserController { return resultModel; } + + private Object sendBHCode(SendCodeModel model, SendCodeJsonModel resultModel, String mobile, String type, HttpServletResponse resp) { + + Long sendCodeTime = (Long) CacheUtils.getValue(FjtUsers.class, mobile); + if(sendCodeTime != null) { + Long curTime = new Date().getTime(); + long second = (curTime - sendCodeTime)/1000; + if(second < 300 ){ + resultModel.setResult(Message.RESULT_FAIL); + resultModel.setMsg(Message.SMS_CODE_SEND_FAIL_TIME); + return resultModel; + } + } + + String code = usersInfoService.randomCode(); + System.out.println(code); + try { + smsService.send(model.getMobile(), "¡¾²³º£ÒøÐС¿ÄãµÄÑé֤ÂëÊÇ" + code + "£¬ÇëÁ¢¼´Ñé֤¡£"); + resultModel.setResult(Message.RESULT_SUCCESS); + CookieUtils.setCookie(mobile + "_" + type, code, "/", 60 * 60 * 24 *7, resp); + CacheUtils.putValue(CachePolicyEnum.TINY, FjtUsers.class, mobile, new Date().getTime()); + } catch (SmsException e) { + resultModel.setResult(Message.RESULT_FAIL); + resultModel.setMsg(Message.SMS_CODE_SEND_FAIL); + } + return resultModel; + } + public void setWeChatAuthService(WeChatAuthService weChatAuthService) { this.weChatAuthService = weChatAuthService; } @@ -416,4 +522,35 @@ public class UserController { CacheUtils.putValue(CachePolicyEnum.LONG, "fangjia-weiXin-key", model.getWeiXinId(), model.getUsername()); return resultModel; } + + public Object setupAction(UserModel model){ + return model; + } + + public Object updateInfoAction(UserModel model, HttpServletRequest request){ + UserJsonModel resultModel = new UserJsonModel(); + Long userId = Long.parseLong(CookieUtils.getCookieValue(request,"login_user_id")); + if(null != userId){ + if(!model.getPass1().equals(model.getPass2())){ + resultModel.setResult(Message.RESULT_FAIL); + resultModel.setMsg(Message.PASS_REPEAT); + return resultModel; + } + FjtUsers users = fjtUsersService.findById(userId); + if(null != users){ + if(!users.getPassword().equals(model.getPass())){ + resultModel.setResult(Message.RESULT_FAIL); + resultModel.setMsg(Message.LOGIN_UPPSW); + return resultModel; + }else{ + users.setPassword(model.getPass1()); + fjtUsersService.update(users); + resultModel.setResult(Message.RESULT_SUCCESS); + } + } + } + return resultModel; + } + + } diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/model/weixin/Message.java b/projects/fangjia-open/src/main/java/com/fangjia/open/model/weixin/Message.java index 864525278..dd123cc38 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/model/weixin/Message.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/model/weixin/Message.java @@ -46,4 +46,6 @@ public class Message { public static final String PAY_PASSWORD_ERROR = "֧¸¶ÃÜÂë´íÎó£¬ÇëÖØÐÂÊäÈë"; public static final String NOT_LOGIN = "ÇëÏȽøÐеǼ"; + + public static final String LOGIN_UPPSW = "ԭʼÃÜÂëÊäÈë´íÎó"; } diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/model/weixin/UserModel.java b/projects/fangjia-open/src/main/java/com/fangjia/open/model/weixin/UserModel.java index 1db056696..400112bfb 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/model/weixin/UserModel.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/model/weixin/UserModel.java @@ -14,6 +14,8 @@ public class UserModel extends BaseModel { private String weiXinId; private String username; private String pass; + private String pass1; + private String pass2; private String code; private List citys; @@ -108,4 +110,20 @@ public class UserModel extends BaseModel { public void setSid(String sid) { this.sid = sid; } + + public String getPass1() { + return pass1; + } + + public void setPass1(String pass1) { + this.pass1 = pass1; + } + + public String getPass2() { + return pass2; + } + + public void setPass2(String pass2) { + this.pass2 = pass2; + } } diff --git a/projects/fangjia-open/src/main/webapp/district/weXinList.ftl b/projects/fangjia-open/src/main/webapp/district/weXinList.ftl index 0119892b7..6018fe8f2 100644 --- a/projects/fangjia-open/src/main/webapp/district/weXinList.ftl +++ b/projects/fangjia-open/src/main/webapp/district/weXinList.ftl @@ -52,6 +52,9 @@ <#else>