| | |
| | | import com.google.gson.GsonBuilder; |
| | | import com.yeshi.buwan.domain.*; |
| | | import com.yeshi.buwan.domain.user.LoginUser; |
| | | import com.yeshi.buwan.exception.LoginUserException; |
| | | import com.yeshi.buwan.dto.user.LoginInfoDto; |
| | | import com.yeshi.buwan.dto.user.QQUserInfo; |
| | | import com.yeshi.buwan.exception.user.LoginUserException; |
| | | import com.yeshi.buwan.exception.SMSException; |
| | | import com.yeshi.buwan.exception.user.RegisterUserException; |
| | | import com.yeshi.buwan.service.imp.CommentService; |
| | | import com.yeshi.buwan.service.imp.MaskKeyService; |
| | | import com.yeshi.buwan.service.imp.SystemService; |
| | |
| | | import com.yeshi.buwan.service.imp.push.PushService; |
| | | import com.yeshi.buwan.service.inter.LoginUserService; |
| | | import com.yeshi.buwan.service.inter.SMSService; |
| | | import com.yeshi.buwan.util.AliyunOneKeyLoginUtil; |
| | | import com.yeshi.buwan.util.JsonUtil; |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | import com.yeshi.buwan.util.*; |
| | | import com.yeshi.buwan.util.annotation.RequireUid; |
| | | import com.yeshi.buwan.util.wx.MyWXLoginUtil; |
| | | import com.yeshi.buwan.vo.AcceptData; |
| | |
| | | import java.io.PrintWriter; |
| | | import java.io.Serializable; |
| | | import java.util.ArrayList; |
| | | import java.util.Calendar; |
| | | import java.util.List; |
| | | |
| | | @Controller |
| | |
| | | |
| | | @Resource |
| | | private SMSService smsService; |
| | | |
| | | @Resource |
| | | private RedisManager redisManager; |
| | | |
| | | @RequireUid |
| | | public void getReadState(AcceptData acceptData, HttpServletRequest request, PrintWriter out) { |
| | |
| | | return; |
| | | } |
| | | |
| | | DetailSystem detailSystem = systemService.getDetailSystemByPackage(acceptData.getPackageName()); |
| | | LoginUser lu = userService.getLoginUser(openid, detailSystem.getId(), Integer.parseInt(loginType), portrait, |
| | | name, UserParser.getIp(request) + ":" + request.getRemotePort()); |
| | | if (lu != null) { |
| | | JSONObject object = new JSONObject(); |
| | | object.put("LoginUid", lu.getId()); |
| | | out.print(JsonUtil.loadTrueJson(object.toString())); |
| | | } else { |
| | | out.print(JsonUtil.loadFalseJson("登录失败")); |
| | | LoginInfoDto loginInfoDto = new LoginInfoDto(); |
| | | loginInfoDto.setSystemId(acceptData.getDetailSystem().getSystem().getId()); |
| | | |
| | | int loginTypeInt = Integer.parseInt(loginType); |
| | | loginInfoDto.setLoginType(loginTypeInt); |
| | | |
| | | switch (loginTypeInt) { |
| | | case LoginUser.LOGIN_TYPE_EMAIL: |
| | | loginInfoDto.setEmail(openid); |
| | | break; |
| | | case LoginUser.LOGIN_TYPE_QQ: |
| | | QQUserInfo qqUserInfo = new QQUserInfo(); |
| | | qqUserInfo.setName(name); |
| | | qqUserInfo.setOpenId(openid); |
| | | qqUserInfo.setPortrait(portrait); |
| | | qqUserInfo.setSex(sex); |
| | | loginInfoDto.setQqUserInfo(qqUserInfo); |
| | | break; |
| | | } |
| | | |
| | | |
| | | try { |
| | | LoginUser lu = userService.login(loginInfoDto); |
| | | if (lu != null) { |
| | | JSONObject object = new JSONObject(); |
| | | object.put("LoginUid", lu.getId()); |
| | | out.print(JsonUtil.loadTrueJson(object.toString())); |
| | | } else { |
| | | out.print(JsonUtil.loadFalseJson("登录失败")); |
| | | } |
| | | } catch (LoginUserException e) { |
| | | //用户不存在 |
| | | if (e.getCode() == LoginUserException.CODE_NO_USER && loginTypeInt == LoginUser.LOGIN_TYPE_EMAIL) { |
| | | //注册 |
| | | try { |
| | | userService.register(loginInfoDto); |
| | | } catch (RegisterUserException e1) { |
| | | out.print(JsonUtil.loadFalseJson("登录失败")); |
| | | } |
| | | |
| | | } else { |
| | | out.print(JsonUtil.loadFalseJson(e.getMessage())); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | return; |
| | | } |
| | | |
| | | DetailSystem detailSystem = systemService.getDetailSystemByPackage(acceptData.getPackageName()); |
| | | LoginInfoDto loginInfoDto = new LoginInfoDto(); |
| | | loginInfoDto.setSystemId(acceptData.getDetailSystem().getSystem().getId()); |
| | | loginInfoDto.setLoginType(LoginUser.LOGIN_TYPE_WX); |
| | | loginInfoDto.setWeiXinUser(weiXinUser); |
| | | |
| | | |
| | | LoginUser lu = userService.getLoginUser(weiXinUser.getOpenid(), detailSystem.getId(), 2, weiXinUser.getHeadimgurl(), |
| | | weiXinUser.getNickname(), UserParser.getIp(request) + ":" + request.getRemotePort()); |
| | | if (lu != null) { |
| | | JSONObject object = new JSONObject(); |
| | | object.put("user", new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(lu)); |
| | | out.print(JsonUtil.loadTrueJson(object.toString())); |
| | | } else { |
| | | out.print(JsonUtil.loadFalseJson("登录失败")); |
| | | try { |
| | | LoginUser lu = userService.login(loginInfoDto); |
| | | if (lu != null) { |
| | | JSONObject object = new JSONObject(); |
| | | object.put("user", new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(lu)); |
| | | out.print(JsonUtil.loadTrueJson(object.toString())); |
| | | } else { |
| | | out.print(JsonUtil.loadFalseJson("登录失败")); |
| | | } |
| | | } catch (LoginUserException e) { |
| | | //用户不存在 |
| | | if (e.getCode() == LoginUserException.CODE_NO_USER) { |
| | | //注册 |
| | | try { |
| | | userService.register(loginInfoDto); |
| | | } catch (RegisterUserException e1) { |
| | | out.print(JsonUtil.loadFalseJson("登录失败")); |
| | | } |
| | | } else { |
| | | out.print(JsonUtil.loadFalseJson(e.getMessage())); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 允许一键登录 |
| | | * |
| | | * @param acceptData |
| | | * @param request |
| | | * @param out |
| | | */ |
| | | public void allowOneKeyLogin(AcceptData acceptData, HttpServletRequest request, PrintWriter out) { |
| | | Long loginUid = StringUtil.isNullOrEmpty(request.getParameter("loginUid")) ? null : Long.parseLong(request.getParameter("loginUid")); |
| | | if (loginUid == null || loginUid == 0L) { |
| | | out.print(JsonUtil.loadFalseJson("尚未登录")); |
| | | return; |
| | | } |
| | | String device = request.getParameter("Device"); |
| | | long time = System.currentTimeMillis(); |
| | | |
| | | String key = "onkeylogin-" + StringUtil.Md5(device + "#" + TimeUtil.getGernalTime(time, "yyyyMMdd")); |
| | | |
| | | //一个设备一天之内只能允许5次 |
| | | String value = redisManager.getCommonString(key); |
| | | if (!StringUtil.isNullOrEmpty(value) && Integer.parseInt(value) > 10) { |
| | | out.print(JsonUtil.loadFalseJson("一键登录次数超限,请明天再试")); |
| | | return; |
| | | } |
| | | out.print(JsonUtil.loadTrueJson("")); |
| | | } |
| | | |
| | | |
| | |
| | | String code = request.getParameter("code"); |
| | | String accessToken = request.getParameter("accessToken"); |
| | | String systemId = request.getParameter("system"); |
| | | String device = request.getParameter("Device"); |
| | | |
| | | long time = System.currentTimeMillis(); |
| | | |
| | | |
| | | if (loginUid == null || loginUid == 0L) { |
| | | out.print(JsonUtil.loadFalseJson("登录失败")); |
| | | out.print(JsonUtil.loadFalseJson("尚未登录")); |
| | | return; |
| | | } |
| | | |
| | |
| | | if (!StringUtil.isNullOrEmpty(accessToken)) { |
| | | //一键登录 |
| | | mobile = AliyunOneKeyLoginUtil.getMobile(accessToken, ""); |
| | | |
| | | //增加一键登录的次数 |
| | | String key = "onkeylogin-" + StringUtil.Md5(device + "#" + TimeUtil.getGernalTime(time, "yyyyMMdd")); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTimeInMillis(time); |
| | | calendar.add(Calendar.DAY_OF_WEEK, 1); |
| | | int s = (int) ((TimeUtil.convertGernalTime(TimeUtil.getGernalTime(calendar.getTimeInMillis(), "yyyyMMdd"), "yyyyMMdd") - time) / 1000); |
| | | redisManager.increase(key, s); |
| | | } else { |
| | | //通过验证码登录 |
| | | //判断验证码是否正确 |
| | |
| | | return; |
| | | } |
| | | |
| | | if (smsService.verifyBindVCode(phone, code)) { |
| | | if (!smsService.verifyBindVCode(phone, code)) { |
| | | out.print(JsonUtil.loadFalseJson("验证码错误")); |
| | | return; |
| | | } |
| | | mobile = phone; |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(code)) { |
| | | out.print(JsonUtil.loadFalseJson("code为空")); |
| | | return; |
| | | } |
| | | |
| | | try { |
| | |
| | | } |
| | | |
| | | try { |
| | | smsService.sendBindVCode(Long.parseLong(loginUid), phone, 6); |
| | | smsService.sendBindVCode(loginUid, phone, 6); |
| | | } catch (SMSException e) { |
| | | e.printStackTrace(); |
| | | out.print(JsonUtil.loadFalseJson(e.getMessage())); |