| | |
| | | |
| | | import com.alipay.api.AlipayApiException; |
| | | import com.google.gson.Gson; |
| | | import com.ks.push.service.BDeviceTokenService; |
| | | import com.yeshi.fanli.dto.wx.WXAccountInfoDTO; |
| | | import com.yeshi.fanli.entity.accept.AcceptData; |
| | | import com.yeshi.fanli.entity.bus.user.*; |
| | |
| | | import com.yeshi.fanli.util.*; |
| | | import com.yeshi.fanli.util.account.UserUtil; |
| | | import com.yeshi.fanli.util.wx.MyWXLoginUtil; |
| | | import com.yeshi.fanli.vo.user.QQUserInfoVO; |
| | | import net.sf.json.JSONObject; |
| | | import org.apache.dubbo.config.annotation.Reference; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.yeshi.utils.JsonUtil; |
| | | import org.yeshi.utils.TimeUtil; |
| | | import org.yeshi.utils.encrypt.DESUtil; |
| | | import org.yeshi.utils.entity.ProxyIP; |
| | | import org.yeshi.utils.entity.wx.WeiXinUser; |
| | |
| | | @Controller |
| | | @RequestMapping("api/v1/user") |
| | | public class UserAccountController { |
| | | |
| | | private Logger logger = LoggerFactory.getLogger(UserAccountController.class); |
| | | |
| | | @Resource |
| | | private UserInfoService userInfoService; |
| | |
| | | |
| | | @Resource |
| | | private DeviceActiveService deviceActiveService; |
| | | |
| | | |
| | | @Reference(version = "1.0", check = false) |
| | | private BDeviceTokenService bDeviceTokenService; |
| | | |
| | | private BusinessSystem getSystem(AcceptData acceptData) { |
| | | BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(), |
| | |
| | | return; |
| | | if ("android".equalsIgnoreCase(acceptData.getPlatform())) { |
| | | DeviceActive deviceActive = deviceActiveService.getFirstActiveInfo(acceptData.getDevice()); |
| | | // 需要解绑HW推送的用户绑定 |
| | | deviceTokenHWService.unBindDeviceToken(acceptData.getDevice()); |
| | | if (deviceActive != null) { |
| | | // 解绑OPPO推送的用户绑定 |
| | | deviceTokenOPPOService.unBindUid(uid, deviceActive.getId()); |
| | | // 解绑VIVO推送的用户绑定 |
| | | deviceTokenVIVOService.unBindUid(uid, deviceActive.getId()); |
| | | // 解绑XM推送的用户绑定 |
| | | deviceTokenXMService.unBindUid(deviceActive.getId()); |
| | | |
| | | //新版推送解绑 |
| | | if (acceptData.getSystem().isNewPush()) { |
| | | try { |
| | | bDeviceTokenService.unBindUid(acceptData.getSystem().name(), StringUtil.isNullOrEmpty(acceptData.getUtdid()) ? acceptData.getDevice() : acceptData.getUtdid()); |
| | | } catch (Exception e) { |
| | | logger.error("新版推送解绑出错:{}", uid, e); |
| | | } |
| | | } else { |
| | | // 需要解绑HW推送的用户绑定 |
| | | deviceTokenHWService.unBindDeviceToken(acceptData.getDevice()); |
| | | if (deviceActive != null) { |
| | | // 解绑OPPO推送的用户绑定 |
| | | deviceTokenOPPOService.unBindUid(uid, deviceActive.getId()); |
| | | // 解绑VIVO推送的用户绑定 |
| | | deviceTokenVIVOService.unBindUid(uid, deviceActive.getId()); |
| | | // 解绑XM推送的用户绑定 |
| | | deviceTokenXMService.unBindUid(deviceActive.getId()); |
| | | } |
| | | } |
| | | |
| | | } |
| | | out.print(JsonUtil.loadTrueResult("")); |
| | | } |
| | |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "loginNew", method = RequestMethod.POST) |
| | | public void loginNew(AcceptData acceptData, String vcode, String phone, String code, int loginType, |
| | | public void loginNew(AcceptData acceptData, String vcode, String phone, String code, String aliAccessToken, int loginType, |
| | | HttpServletRequest request, PrintWriter out) { |
| | | |
| | | // 2.0以下版本不允许登录 |
| | | if (!VersionUtil.greaterThan_2_0(acceptData.getPlatform(), acceptData.getVersion())) { |
| | | out.print("请升级到最新版本"); |
| | | return; |
| | | } |
| | | |
| | | if (!StringUtil.isNullOrEmpty(aliAccessToken)) { |
| | | long now = System.currentTimeMillis(); |
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.oneKeyLoginCount, StringUtil.Md5(StringUtil.isNullOrEmpty(acceptData.getUtdid()) ? acceptData.getDevice() : acceptData.getUtdid())); |
| | | redisManager.increase(key); |
| | | int expire = (int) ((TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(now + 1000 * 60 * 60 * 24L, "yyyyMMdd"), "yyyyMMdd") - now) / 1000); |
| | | redisManager.expire(key, expire); |
| | | } |
| | | |
| | | try { |
| | |
| | | UserInfo userInfo = null; |
| | | // 手机登录 |
| | | if (loginType == 1) { |
| | | userInfo = userAccountService.loginPhone(new ProxyIP(request.getRemoteHost(), request.getRemotePort()), loginType, vcode, phone, system); |
| | | userInfo = userAccountService.loginPhone(new ProxyIP(request.getRemoteHost(), request.getRemotePort()), loginType, vcode, phone, aliAccessToken, system); |
| | | } |
| | | |
| | | // 微信登录 |
| | |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "bindPhoneNew") |
| | | public void bindPhoneNew(AcceptData acceptData, Long uid, String vcode, String phone, PrintWriter out) { |
| | | public void bindPhoneNew(AcceptData acceptData, Long uid, String vcode, String phone, String aliAccessToken, PrintWriter out) { |
| | | |
| | | BusinessSystem system = getSystem(acceptData); |
| | | if (system == null) { |
| | |
| | | return; |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(vcode)) { |
| | | out.print(JsonUtil.loadFalseResult("验证码不能为空")); |
| | | return; |
| | | if (!StringUtil.isNullOrEmpty(aliAccessToken)) { |
| | | long now = System.currentTimeMillis(); |
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.oneKeyLoginCount, StringUtil.Md5(StringUtil.isNullOrEmpty(acceptData.getUtdid()) ? acceptData.getDevice() : acceptData.getUtdid())); |
| | | redisManager.increase(key); |
| | | int expire = (int) ((TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(now + 1000 * 60 * 60 * 24L, "yyyyMMdd"), "yyyyMMdd") - now) / 1000); |
| | | redisManager.expire(key, expire); |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(phone)) { |
| | | out.print(JsonUtil.loadFalseResult("电话号码不能为空")); |
| | | String mobile = null; |
| | | try { |
| | | mobile = userAccountService.getMobile(vcode, phone, aliAccessToken, acceptData.getSystem(), SMSHistory.TYPE_BIND); |
| | | } catch (UserAccountException e) { |
| | | out.print(JsonUtil.loadFalseResult(e.getMsg())); |
| | | return; |
| | | } |
| | | |
| | | phone = phone.replaceAll(" ", ""); |
| | | |
| | | String oldVCode = redisManager.getSMSVCode(phone, SMSHistory.TYPE_BIND); |
| | | if (Constant.IS_OUTNET) { |
| | | if (!vcode.equalsIgnoreCase(oldVCode)) { |
| | | out.print(JsonUtil.loadFalseResult(9001, "验证码错误,重新输入")); |
| | | return; |
| | | } |
| | | redisManager.clearSMSFrequencyLimit(phone, SMSHistory.TYPE_BIND); |
| | | } |
| | | |
| | | try { |
| | | // 绑定用户 |
| | | userAccountService.bindPhoneNew(uid, phone); |
| | | userAccountService.bindPhoneNew(uid, mobile); |
| | | |
| | | UserInfo user = userInfoService.getUserByIdWithMybatis(uid); |
| | | // 判断电话号码是否已经封禁 |
| | | ForbiddenUserIdentifyCode ic = forbiddenUserIdentifyCodeService |
| | | .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.phone, phone); |
| | | .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.phone, mobile); |
| | | if (ic != null && ic.getEffective() != null && ic.getEffective()) { |
| | | out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC)); |
| | | // 封禁用户 |
| | |
| | | } |
| | | |
| | | try { |
| | | userAccountService.bindWeiXin(acceptData, uid, code); |
| | | userAccountService.bindWeiXin(system, uid, code); |
| | | |
| | | UserInfo user = userInfoService.getUserByIdWithMybatis(uid); |
| | | // 判断taoBaoUid是否已经封禁 |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 更改微信 |
| | | * |
| | | * @param acceptData |
| | | * @param uid |
| | | * @param qqUser |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "bindQQ") |
| | | public void bindQQ(AcceptData acceptData, Long uid, String qqUser, PrintWriter out) { |
| | | BusinessSystem system = getSystem(acceptData); |
| | | |
| | | if (system == null) { |
| | | out.print(JsonUtil.loadFalseResult("系统不存在")); |
| | | return; |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(qqUser)) { |
| | | out.print(JsonUtil.loadFalseResult("请上传qqUser")); |
| | | return; |
| | | } |
| | | |
| | | String qqUserStr = StringUtil.getFromBase64(qqUser); |
| | | QQUserInfoVO qqUserInfo = new Gson().fromJson(qqUserStr, QQUserInfoVO.class); |
| | | try { |
| | | userAccountService.bindQQ(uid, qqUserInfo); |
| | | |
| | | UserInfo user = userInfoService.getUserByIdWithMybatis(uid); |
| | | |
| | | JSONObject data = new JSONObject(); |
| | | data.put("userInfo", UserUtil.filterForClientUser(user)); |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | } catch (UserAccountException e) { |
| | | out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg())); |
| | | } |
| | | } |
| | | |
| | | } |