| | |
| | | import com.yeshi.fanli.dao.mybatis.AccountMessageMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.UserConnectHistoryMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.UserInfoMapper;
|
| | | import com.yeshi.fanli.dto.user.wx.WXMPLoginData;
|
| | | import com.yeshi.fanli.dto.user.wx.WXMPLoginResult;
|
| | | import com.yeshi.fanli.dto.wx.WXAccountInfoDTO;
|
| | | import com.yeshi.fanli.entity.accept.AcceptData;
|
| | | import com.yeshi.fanli.entity.bus.user.BindingAccount;
|
| | |
| | | import com.yeshi.fanli.entity.bus.user.UserInfoModifyRecord.ModifyTypeEnum;
|
| | | import com.yeshi.fanli.entity.bus.user.WeiXinUser;
|
| | | import com.yeshi.fanli.exception.user.ForbiddenUserIdentifyCodeException;
|
| | | import com.yeshi.fanli.exception.user.ThreeSaleException;
|
| | | import com.yeshi.fanli.exception.user.UserAccountException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.money.extract.BindingAccountService;
|
| | |
| | | import com.yeshi.fanli.service.inter.user.msg.UserAccountMsgNotificationService;
|
| | | import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.FilePathEnum;
|
| | | import com.yeshi.fanli.util.FileUtil;
|
| | | import com.yeshi.fanli.util.RedisKeyEnum;
|
| | | import com.yeshi.fanli.util.RedisManager;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.ThreadUtil;
|
| | |
| | | @Resource
|
| | | private UserInfoModifyRecordService userInfoModifyRecordService;
|
| | |
|
| | | @Transactional(rollbackFor=Exception.class)
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public LoginResult login(HttpServletRequest request, AcceptData acceptData, Boolean first, String appId,
|
| | | String code, String phone, UserInfo tbUserInfo, boolean wxinstall, int loginType)
|
| | |
| | | userInfo = getUserInfoByTaoBaoOpenId(appId, tbUserInfo.getOpenid());
|
| | | // 判断用户是否被删除
|
| | | if (userInfo != null && userInfo.getState() != null
|
| | | && (userInfo.getState() == UserInfo.STATE_DELETE_OUT_OF_DATE
|
| | | || userInfo.getState() == UserInfo.STATE_DELETE))
|
| | | && (userInfo.getState() != UserInfo.STATE_NORMAL))
|
| | | userInfo = null;
|
| | | if (userInfo == null) {// 原先的账号不存在
|
| | | userInfo = new UserInfo();
|
| | |
| | | userInfo = getUserInfoByWXUnionId(appId, weiXinUser.getUnionid());
|
| | | // 判断用户是否被删除
|
| | | if (userInfo != null && userInfo.getState() != null
|
| | | && (userInfo.getState() == UserInfo.STATE_DELETE_OUT_OF_DATE
|
| | | || userInfo.getState() == UserInfo.STATE_DELETE))
|
| | | && (userInfo.getState() != UserInfo.STATE_NORMAL
|
| | | ))
|
| | | userInfo = null;
|
| | | // 直接用的微信登录
|
| | | if (lastUser == null) {
|
| | |
| | | userInfo = getUserInfoByPhone(appId, phone);
|
| | | // 判断用户是否被删除
|
| | | if (userInfo != null && userInfo.getState() != null
|
| | | && (userInfo.getState() == UserInfo.STATE_DELETE_OUT_OF_DATE
|
| | | || userInfo.getState() == UserInfo.STATE_DELETE))
|
| | | && (userInfo.getState() != UserInfo.STATE_NORMAL))
|
| | | userInfo = null;
|
| | |
|
| | | if (userInfo == null) {// 原先的账号不存在
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | @Transactional(rollbackFor=Exception.class)
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public LoginResult loginNoInstallWX(AcceptData acceptData, String appId, String code, String phone,
|
| | | UserInfo tbUserInfo, int loginType) throws UserAccountException {
|
| | |
| | | }
|
| | |
|
| | | // 判断用户是否被删除
|
| | | if (userInfo != null && userInfo.getState() != null && (userInfo.getState() == UserInfo.STATE_DELETE_OUT_OF_DATE
|
| | | || userInfo.getState() == UserInfo.STATE_DELETE))
|
| | | if (userInfo != null && userInfo.getState() != null && (userInfo.getState() != UserInfo.STATE_NORMAL))
|
| | | userInfo = null;
|
| | |
|
| | | if (userInfo != null) {
|
| | |
| | | connectUsers(mainUser, lessUser);
|
| | | }
|
| | |
|
| | | @Transactional(rollbackFor=Exception.class)
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public void connectUsers(UserInfo mainUser, UserInfo lessUser) throws UserAccountException {
|
| | | mainUser = userInfoMapper.selectByPrimaryKeyForUpdate(mainUser.getId());
|
| | |
| | | List<UserInfo> list = userInfoMapper.listByAppIdAndWXUnionId(appId, unionId);
|
| | | // 剔除被删除掉的用户
|
| | | for (int i = 0; i < list.size(); i++) {
|
| | | if (list.get(i).getState() == UserInfo.STATE_DELETE
|
| | | || list.get(i).getState() == UserInfo.STATE_DELETE_OUT_OF_DATE) {
|
| | | if (list.get(i).getState() == UserInfo.STATE_NORMAL) {
|
| | | list.remove(i);
|
| | | i--;
|
| | | }
|
| | |
| | |
|
| | | // 剔除被删除掉的用户
|
| | | for (int i = 0; i < list.size(); i++) {
|
| | | if (list.get(i).getState() == UserInfo.STATE_DELETE
|
| | | || list.get(i).getState() == UserInfo.STATE_DELETE_OUT_OF_DATE) {
|
| | | if (list.get(i).getState() != UserInfo.STATE_NORMAL) {
|
| | | list.remove(i);
|
| | | i--;
|
| | | }
|
| | |
| | |
|
| | | // 剔除被删除掉的用户
|
| | | for (int i = 0; i < list.size(); i++) {
|
| | | if (list.get(i).getState() == UserInfo.STATE_DELETE
|
| | | || list.get(i).getState() == UserInfo.STATE_DELETE_OUT_OF_DATE) {
|
| | | if (list.get(i).getState() !=UserInfo.STATE_NORMAL) {
|
| | | list.remove(i);
|
| | | i--;
|
| | | }
|
| | |
| | | userInfoMapper.updateByPrimaryKeySelective(userInfo);
|
| | | }
|
| | |
|
| | | @Transactional(rollbackFor=Exception.class)
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public void register(UserInfo userInfo) throws UserAccountException {
|
| | | if (!StringUtil.isNullOrEmpty(userInfo.getPhone())) {
|
| | |
| | | fw.close();
|
| | |
|
| | | String logUrl = COSManager.getInstance()
|
| | | .uploadFile(new File(logPath), "beifen/" + new File(logPath).getName()).getUrl();
|
| | | .uploadFile(new File(logPath), FilePathEnum.beifen.getPath() + new File(logPath).getName()).getUrl();
|
| | | return logUrl;
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | |
| | | return user.getPortrait();
|
| | | }
|
| | |
|
| | | @Transactional(rollbackFor=Exception.class)
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public UserInfo loginPhone(HttpServletRequest request, int loginType, String vcode, String phone, String appId)
|
| | | throws UserAccountException {
|
| | |
| | | // 清空限制
|
| | | redisManager.clearSMSFrequencyLimit(phone, SMSHistory.TYPE_LOGIN);
|
| | | // 清理次数
|
| | | redisManager.removeCommonString("sendMSNLoginCount" + phone);
|
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSLoginCount, phone);
|
| | | redisManager.removeCommonString(key);
|
| | |
|
| | |
|
| | | // 采用redis事务防止一个手机号多次注册问题
|
| | | String watchKey = StringUtil.Md5("REGISTER:" + phone);
|
| | |
| | | throw new UserAccountException(10, "请稍后再试");
|
| | | }
|
| | |
|
| | | @Transactional(rollbackFor=Exception.class)
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public UserInfo loginWinXin(HttpServletRequest request, AcceptData acceptData, int loginType, String code,
|
| | | String appId) throws UserAccountException {
|
| | |
| | | InputStream asInputStream = HttpUtil.getAsInputStream(weiXinUser.getHeadimgurl());
|
| | | if (asInputStream != null) {
|
| | | FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream,
|
| | | String.format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(),
|
| | | String.format(FilePathEnum.userPortrait.getPath() + "%s_%s.jpg", weiXinUser.getUnionid(),
|
| | | System.currentTimeMillis() + ""));
|
| | | if (result != null && !StringUtil.isNullOrEmpty(result.getUrl()))
|
| | | portrait = result.getUrl();
|
| | |
| | | throw new UserAccountException(10, "请稍后再试");
|
| | | }
|
| | |
|
| | | @Transactional(rollbackFor=Exception.class)
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public UserInfo loginWeiXinNew(HttpServletRequest request, AcceptData acceptData, int loginType, String wxCode,
|
| | | String appId) throws UserAccountException {
|
| | |
| | |
|
| | | UserInfo userInfo = userInfoMapper.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid());
|
| | | if (userInfo == null) {
|
| | | String longinKey = StringUtil.Md5("WXLogin:" + weiXinUser.getUnionid());
|
| | | redisManager.cacheCommonString(longinKey, JsonUtil.getSimpleGson().toJson(weiXinUser), 60 * 20);
|
| | | throw new UserAccountException(101, longinKey);
|
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.emptyKey, StringUtil.Md5("WXLogin:" + weiXinUser.getUnionid()));
|
| | | redisManager.cacheCommonString(key, JsonUtil.getSimpleGson().toJson(weiXinUser), 60 * 20);
|
| | | throw new UserAccountException(101, key);
|
| | | }
|
| | | // 更新账户登录信息
|
| | | updateLonginInfo(userInfo, loginType, request);
|
| | |
| | |
|
| | | }
|
| | |
|
| | | @Transactional(rollbackFor=UserAccountException.class)
|
| | | @Override
|
| | | public void bindWeiXin(AcceptData acceptData, Long uid, String code) throws UserAccountException {
|
| | | WXAccountInfoDTO wxAccount = Constant.getWXAccount(acceptData.getPlatform(), acceptData.getVersion());
|
| | | WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code, wxAccount.getAppId(), wxAccount.getAppSecret());
|
| | | if (weiXinUser == null) {
|
| | | throw new UserAccountException(2, "微信帐号授权失败");
|
| | | }
|
| | |
|
| | | String wxUnionId = weiXinUser.getUnionid();
|
| | | if (StringUtil.isNullOrEmpty(wxUnionId)) {
|
| | | throw new UserAccountException(2, "微信帐号授权失败");
|
| | | }
|
| | | bindWeiXin(uid, weiXinUser);
|
| | | }
|
| | | |
| | | |
| | | |
| | | |
| | | @Transactional(rollbackFor=UserAccountException.class)
|
| | | @Override
|
| | | public void bindWeiXin(Long uid,WeiXinUser weiXinUser) throws UserAccountException {
|
| | | UserInfo user = userInfoMapper.selectAvailableByPrimaryKey(uid);
|
| | | if (user == null) {
|
| | | throw new UserAccountException(1, "用户不存在");
|
| | | }
|
| | | WXAccountInfoDTO wxAccount = Constant.getWXAccount(acceptData.getPlatform(), acceptData.getVersion());
|
| | | WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code, wxAccount.getAppId(), wxAccount.getAppSecret());
|
| | | |
| | | if (weiXinUser == null) {
|
| | | throw new UserAccountException(2, "微信帐号授权失败");
|
| | | }
|
| | |
| | | LogHelper.test("微信头像下载失败: " + weiXinUser.getUnionid() + " " + headimgurl);
|
| | | } else {
|
| | | FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, String
|
| | | .format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + ""));
|
| | | .format(FilePathEnum.userPortrait.getPath() + "%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + ""));
|
| | | if (result != null && !StringUtil.isNullOrEmpty(result.getUrl())) {
|
| | | headimgurl = result.getUrl();
|
| | | } else {
|
| | |
| | | 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() + ""));
|
| | | .format(FilePathEnum.userPortrait.getPath() +"%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + ""));
|
| | | if (result != null && !StringUtil.isNullOrEmpty(result.getUrl()))
|
| | | portrait = result.getUrl();
|
| | | } else {
|
| | |
| | | // 插入记录
|
| | | userInfoDeleteRecordService.addDeleteRecord(uid, UserInfo.STATE_DELETE_OUT_OF_DATE, reason);
|
| | | }
|
| | |
|
| | |
|
| | | }
|