| | |
| | | @Lazy
|
| | | @Resource
|
| | | private UserInfoModifyRecordService userInfoModifyRecordService;
|
| | | |
| | | |
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public LoginResult login(HttpServletRequest request, AcceptData acceptData, Boolean first, String appId,
|
| | |
| | | updateUserInfo.setLastLoginTime(System.currentTimeMillis());
|
| | | updateUserInfo.setLoginType(loginType);
|
| | | updateUserInfo.setLastLoginIp(request.getRemoteHost());
|
| | | //更新openId
|
| | | // 更新openId
|
| | | updateUserInfo.setOpenid(weiXinUser.getOpenid());
|
| | |
|
| | | userInfoMapper.updateByPrimaryKeySelective(updateUserInfo);
|
| | |
| | | addUser(userInfo);
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public void addUser(UserInfo user) {
|
| | |
|
| | |
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | // 添加账号绑定历史
|
| | | if (!StringUtil.isNullOrEmpty(user.getPhone()))
|
| | | userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindPhone, user.getPhone());
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(user.getWxUnionId()))
|
| | | userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindWeiXin, user.getWxUnionId());
|
| | |
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | | } finally {
|
| | | jedis.del(watchKey);
|
| | | jedis.unwatch();
|
| | | jedisPool.returnResource(jedis);
|
| | | jedis.close();
|
| | | }
|
| | | throw new UserAccountException(10, "请稍后再试");
|
| | | }
|
| | |
| | |
|
| | | // 通过Code换取信息
|
| | | WXAccountInfoDTO wxAccount = Constant.getWXAccount(acceptData.getPlatform(), acceptData.getVersion());
|
| | | WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code, wxAccount.getAppId(),
|
| | | wxAccount.getAppSecret());
|
| | | WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code, wxAccount.getAppId(), wxAccount.getAppSecret());
|
| | | if (weiXinUser == null) {
|
| | | throw new UserAccountException(1, "微信帐号授权失败");
|
| | | }
|
| | |
| | | spreadUserImgService.deleteImgUrl(userInfo.getId());
|
| | | } else {
|
| | | LogHelper.test("微信unionID不存在:" + weiXinUser.getUnionid());
|
| | | |
| | |
|
| | | String portrait = null;
|
| | | if (!StringUtil.isNullOrEmpty(weiXinUser.getHeadimgurl())) {
|
| | | InputStream asInputStream = HttpUtil.getAsInputStream(weiXinUser.getHeadimgurl());
|
| | | if (asInputStream != null) {
|
| | | FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream,
|
| | | String.format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + ""));
|
| | | String.format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(),
|
| | | System.currentTimeMillis() + ""));
|
| | | if (result != null && !StringUtil.isNullOrEmpty(result.getUrl()))
|
| | | portrait = result.getUrl();
|
| | | } else {
|
| | | portrait = weiXinUser.getHeadimgurl();
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | if (StringUtil.isNullOrEmpty(portrait))
|
| | | portrait = Constant.systemCommonConfig.getDefaultPortrait();
|
| | | |
| | |
|
| | | // 创建新账户
|
| | | userInfo = new UserInfo();
|
| | | userInfo.setPortrait(portrait);
|
| | |
| | | } finally {
|
| | | jedis.del(watchKey);
|
| | | jedis.unwatch();
|
| | | jedisPool.returnResource(jedis);
|
| | | jedis.close();
|
| | | }
|
| | | throw new UserAccountException(10, "请稍后再试");
|
| | | }
|
| | |
|
| | | |
| | | @Transactional
|
| | | @Override
|
| | | public UserInfo loginWeiXinNew(HttpServletRequest request, AcceptData acceptData, int loginType, String wxCode, String appId) throws UserAccountException {
|
| | | public UserInfo loginWeiXinNew(HttpServletRequest request, AcceptData acceptData, int loginType, String wxCode,
|
| | | String appId) throws UserAccountException {
|
| | | // 日志信息
|
| | | JSONObject logInfo = new JSONObject();
|
| | | logInfo.put("appId", appId);
|
| | |
| | |
|
| | | // 通过Code换取信息
|
| | | WXAccountInfoDTO wxAccount = Constant.getWXAccount(acceptData.getPlatform(), acceptData.getVersion());
|
| | | WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(wxCode, wxAccount.getAppId(),
|
| | | wxAccount.getAppSecret());
|
| | | WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(wxCode, wxAccount.getAppId(), wxAccount.getAppSecret());
|
| | | if (weiXinUser == null) {
|
| | | throw new UserAccountException(1, "微信帐号授权失败");
|
| | | }
|
| | |
| | | throw new UserAccountException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC);
|
| | | }
|
| | |
|
| | | |
| | | UserInfo userInfo = userInfoMapper.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid());
|
| | | if (userInfo == null) {
|
| | | String longinKey = StringUtil.Md5("WXLogin:" + weiXinUser.getUnionid());
|
| | |
| | | return userInfo;
|
| | | }
|
| | |
|
| | | |
| | | |
| | | /**
|
| | | * 更新账户登录信息
|
| | | *
|
| | |
| | | throw new UserAccountException(1, "用户不存在");
|
| | | }
|
| | | WXAccountInfoDTO wxAccount = Constant.getWXAccount(acceptData.getPlatform(), acceptData.getVersion());
|
| | | WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code, wxAccount.getAppId(),
|
| | | wxAccount.getAppSecret());
|
| | | WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code, wxAccount.getAppId(), wxAccount.getAppSecret());
|
| | | if (weiXinUser == null) {
|
| | | throw new UserAccountException(2, "微信帐号授权失败");
|
| | | }
|
| | |
| | | String headimgurl = weiXinUser.getHeadimgurl();
|
| | | InputStream asInputStream = HttpUtil.getAsInputStream(headimgurl);
|
| | | if (asInputStream == null) {
|
| | | LogHelper.test("微信头像下载失败: " +weiXinUser.getUnionid()+ " " + headimgurl);
|
| | | LogHelper.test("微信头像下载失败: " + weiXinUser.getUnionid() + " " + headimgurl);
|
| | | } else {
|
| | | FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream,
|
| | | String.format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + ""));
|
| | | FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, String
|
| | | .format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + ""));
|
| | | if (result != null && !StringUtil.isNullOrEmpty(result.getUrl())) {
|
| | | headimgurl = result.getUrl();
|
| | | } else {
|
| | | LogHelper.test("微信头像上传失败: " +weiXinUser.getUnionid()+ " " + headimgurl);
|
| | | LogHelper.test("微信头像上传失败: " + weiXinUser.getUnionid() + " " + headimgurl);
|
| | | }
|
| | | }
|
| | | updateUserInfo.setPortrait(headimgurl);
|
| | |
| | |
|
| | | userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindWeiXin, wxUnionId);
|
| | | }
|
| | | |
| | | |
| | |
|
| | | @Override
|
| | | public UserInfo bindPhoneToLogin(String phone, String key, String appId, HttpServletRequest request) throws UserAccountException {
|
| | | public UserInfo bindPhoneToLogin(String phone, String key, String appId, HttpServletRequest request)
|
| | | throws UserAccountException {
|
| | | UserInfo phoneUser = userInfoMapper.getEffectiveUserInfoByPhone(phone);
|
| | | if (phoneUser != null) |
| | | if (phoneUser != null)
|
| | | throw new UserAccountException(1, "号码已经被占用");
|
| | | |
| | |
|
| | | // 判断手机号码是否被封禁
|
| | | ForbiddenUserIdentifyCode identifyCode1 = forbiddenUserIdentifyCodeService
|
| | | .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.phone, phone);
|
| | | if (identifyCode1 != null && identifyCode1.getEffective() != null && identifyCode1.getEffective())
|
| | | throw new UserAccountException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC);
|
| | | |
| | |
|
| | | String value = redisManager.getCommonString(key);
|
| | | if (StringUtil.isNullOrEmpty(value))
|
| | | throw new UserAccountException(1, "微信授权失效,请使用微信重新登录");
|
| | | |
| | |
|
| | | WeiXinUser weiXinUser = JsonUtil.getSimpleGson().fromJson(value, WeiXinUser.class);
|
| | | if (weiXinUser == null)
|
| | | throw new UserAccountException(1, "微信授权失效,请使用微信重新登录");
|
| | | |
| | |
|
| | | UserInfo userInfo = userInfoMapper.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid());
|
| | | // 直接用的微信登录
|
| | | if (userInfo != null) |
| | | if (userInfo != null)
|
| | | throw new UserAccountException(10, "该微信号已被占用");
|
| | | |
| | |
|
| | | String portrait = null;
|
| | | if (!StringUtil.isNullOrEmpty(weiXinUser.getHeadimgurl())) {
|
| | | InputStream asInputStream = HttpUtil.getAsInputStream(weiXinUser.getHeadimgurl());
|
| | | if (asInputStream != null) {
|
| | | FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream,
|
| | | String.format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + ""));
|
| | | FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, String
|
| | | .format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + ""));
|
| | | if (result != null && !StringUtil.isNullOrEmpty(result.getUrl()))
|
| | | portrait = result.getUrl();
|
| | | } else {
|
| | | portrait = weiXinUser.getHeadimgurl();
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | if (StringUtil.isNullOrEmpty(portrait))
|
| | | portrait = Constant.systemCommonConfig.getDefaultPortrait();
|
| | | |
| | |
|
| | | // 创建新账户
|
| | | userInfo = new UserInfo();
|
| | | userInfo.setPhone(phone);
|
| | |
| | | userInfo.setLastLoginIp(request.getRemoteHost());
|
| | | userInfo.setState(UserInfo.STATE_NORMAL);
|
| | | addUser(userInfo);
|
| | | |
| | |
|
| | | Long uid = userInfo.getId();
|
| | | ThreadUtil.run(new Runnable() {
|
| | | public void run() {
|
| | |
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | |
| | |
|
| | | // 加入绑定记录
|
| | | UserAccountBindingHistory history = new UserAccountBindingHistory();
|
| | | history.setContent(phone);
|
| | |
| | | userAccountBindingHistoryService.addUserAccountBindingHistory(history);
|
| | |
|
| | | userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindPhone, phone);
|
| | | userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindWeiXin, weiXinUser.getUnionid());
|
| | | userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindWeiXin, weiXinUser.getUnionid());
|
| | | }
|
| | | });
|
| | | // 删除缓存
|
| | | redisManager.removeCommonString(key);
|
| | | |
| | |
|
| | | return userInfo;
|
| | | }
|
| | |
|
| | | |
| | |
|
| | | @Override
|
| | | public void forbiddenUserAll(Long uid, String reason) {
|