|
|
@@ -6,8 +6,13 @@ import cn.hutool.core.lang.Validator;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.cyksj.common.EnvCommonService;
|
|
|
import com.cyksj.common.constant.TaskTypeEnum;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
+import com.cyksj.common.snowflake.Sequence;
|
|
|
+import com.cyksj.common.util.Codec;
|
|
|
+import com.cyksj.common.util.Jsons;
|
|
|
+import com.cyksj.config.wxlogin.WxOpenPlatYHLXLoginConfig;
|
|
|
import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayApiCode;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
@@ -15,16 +20,16 @@ import com.cyksj.mapper.PhoneCodeMapper;
|
|
|
import com.cyksj.mapper.UserMapper;
|
|
|
import com.cyksj.mapper.market.task.TaskTypeMapper;
|
|
|
import com.cyksj.mapper.market.task.UserBindDetailMapper;
|
|
|
+import com.cyksj.model.dto.AuthRedirect;
|
|
|
import com.cyksj.model.entity.PhoneCode;
|
|
|
import com.cyksj.model.entity.TaskType;
|
|
|
import com.cyksj.model.entity.User;
|
|
|
import com.cyksj.model.entity.UserBindDetail;
|
|
|
import com.cyksj.model.request.UserBindInfoReq;
|
|
|
-import com.cyksj.model.response.WxGzhQrCodeTicketRep;
|
|
|
import com.cyksj.redis.RedisService;
|
|
|
+import com.cyksj.service.authorization.AuthorizationService;
|
|
|
import com.cyksj.service.market.task.BindTaskService;
|
|
|
import com.cyksj.service.market.task.TaskService;
|
|
|
-import com.cyksj.service.wechat.WeChatService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -52,7 +57,13 @@ public class BindTaskServiceImpl implements BindTaskService {
|
|
|
|
|
|
private final UserMapper userMapper;
|
|
|
|
|
|
- private final WeChatService weChatService;
|
|
|
+ private final AuthorizationService authorizationService;
|
|
|
+
|
|
|
+ private final EnvCommonService envCommonService;
|
|
|
+
|
|
|
+ private final WxOpenPlatYHLXLoginConfig wxOpenPlatYHLXLoginConfig;
|
|
|
+
|
|
|
+ private final static Sequence SEQUENCE = new Sequence(0);
|
|
|
|
|
|
@Override
|
|
|
public UserBindDetail bindPhone(User user, String phone, String code) {
|
|
|
@@ -68,18 +79,23 @@ public class BindTaskServiceImpl implements BindTaskService {
|
|
|
.eq(StrUtil.isNotBlank(user.getOpenId()), UserBindDetail::getUserId, user.getId())
|
|
|
.last("limit 1");
|
|
|
|
|
|
- UserBindDetail bindPhone = Optional.ofNullable(userBindDetailMapper.selectOne(wrapper)).orElse(new UserBindDetail());
|
|
|
- if (StrUtil.isNotBlank(bindPhone.getPhone())) {
|
|
|
+ UserBindDetail bindPhone = userBindDetailMapper.selectOne(wrapper);
|
|
|
+ if (bindPhone != null && StrUtil.isNotBlank(bindPhone.getPhone())) {
|
|
|
throw BusinessRuntimeException.getInstance("您已绑定手机号");
|
|
|
}
|
|
|
|
|
|
UserBindDetail other = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
|
|
|
.eq(UserBindDetail::getPhone, phone)
|
|
|
- .select(UserBindDetail::getId)
|
|
|
+ .ne(StrUtil.isNotBlank(user.getEmail()), UserBindDetail::getEmail, StrUtil.EMPTY)
|
|
|
+ .isNotNull(StrUtil.isNotEmpty(user.getOpenId()), UserBindDetail::getUserId)
|
|
|
.last("limit 1"));
|
|
|
if (other != null) {
|
|
|
throw BusinessRuntimeException.getInstance("该手机号已被绑定");
|
|
|
}
|
|
|
+ if (bindPhone == null) {
|
|
|
+ bindPhone = Optional.ofNullable(userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
|
|
|
+ .eq(UserBindDetail::getPhone, phone).last("limit 1"))).orElse(new UserBindDetail());
|
|
|
+ }
|
|
|
|
|
|
if (StrUtil.isNotBlank(code)) {
|
|
|
//校验
|
|
|
@@ -139,7 +155,7 @@ public class BindTaskServiceImpl implements BindTaskService {
|
|
|
throw BusinessRuntimeException.getInstance("换绑手机号重复");
|
|
|
}
|
|
|
UserBindDetail other = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
|
|
|
- .eq(UserBindDetail::getPhone, phone).ne(UserBindDetail::getUserId, userId).select(UserBindDetail::getId).last("limit 1"));
|
|
|
+ .eq(UserBindDetail::getPhone, phone).select(UserBindDetail::getId).last("limit 1"));
|
|
|
if (other != null) {
|
|
|
throw BusinessRuntimeException.getInstance("该手机号已被绑定");
|
|
|
}
|
|
|
@@ -179,7 +195,7 @@ public class BindTaskServiceImpl implements BindTaskService {
|
|
|
throw BusinessRuntimeException.getInstance("换绑邮箱重复");
|
|
|
}
|
|
|
UserBindDetail other = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
|
|
|
- .eq(UserBindDetail::getEmail, email).ne(UserBindDetail::getUserId, userId).select(UserBindDetail::getId).last("limit 1"));
|
|
|
+ .eq(UserBindDetail::getEmail, email).select(UserBindDetail::getId).last("limit 1"));
|
|
|
if (other != null) {
|
|
|
throw BusinessRuntimeException.getInstance("该邮箱已被绑定");
|
|
|
}
|
|
|
@@ -211,18 +227,24 @@ public class BindTaskServiceImpl implements BindTaskService {
|
|
|
.eq(StrUtil.isNotBlank(user.getLoginPhone()), UserBindDetail::getPhone, user.getLoginPhone())
|
|
|
.eq(StrUtil.isNotBlank(user.getOpenId()), UserBindDetail::getUserId, user.getId())
|
|
|
.last("limit 1");
|
|
|
- UserBindDetail bindPhone = Optional.ofNullable(userBindDetailMapper.selectOne(wrapper)).orElse(new UserBindDetail());
|
|
|
- if (StrUtil.isNotBlank(bindPhone.getEmail())) {
|
|
|
+ UserBindDetail bindPhone = userBindDetailMapper.selectOne(wrapper);
|
|
|
+ if (bindPhone != null && StrUtil.isNotBlank(bindPhone.getEmail())) {
|
|
|
throw BusinessRuntimeException.getInstance("您已绑定邮箱");
|
|
|
}
|
|
|
|
|
|
UserBindDetail other = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
|
|
|
.eq(UserBindDetail::getEmail, account)
|
|
|
+ .ne(StrUtil.isNotBlank(user.getPhone()), UserBindDetail::getPhone, StrUtil.EMPTY)
|
|
|
+ .isNotNull(StrUtil.isNotBlank(user.getOpenId()), UserBindDetail::getUserId)
|
|
|
.select(UserBindDetail::getId)
|
|
|
.last("limit 1"));
|
|
|
if (other != null) {
|
|
|
throw BusinessRuntimeException.getInstance("该邮箱已被绑定");
|
|
|
}
|
|
|
+ if (bindPhone == null) {
|
|
|
+ bindPhone = Optional.ofNullable(userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
|
|
|
+ .eq(UserBindDetail::getEmail, account).last("limit 1"))).orElse(new UserBindDetail());
|
|
|
+ }
|
|
|
|
|
|
if (StrUtil.isNotBlank(inputCode)) {
|
|
|
checkEmailCode(account, inputCode);
|
|
|
@@ -258,7 +280,7 @@ public class BindTaskServiceImpl implements BindTaskService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Result<Object> bindOtherAccount(UserBindInfoReq request) throws Exception {
|
|
|
+ public Result<String> bindOtherAccount(UserBindInfoReq request) throws Exception {
|
|
|
Long userId = request.getUserId();
|
|
|
User user = userMapper.selectById(userId);
|
|
|
Integer type = request.getType();
|
|
|
@@ -300,10 +322,26 @@ public class BindTaskServiceImpl implements BindTaskService {
|
|
|
if (StrUtil.isNotBlank(user.getOpenId())) {
|
|
|
throw BusinessRuntimeException.getInstance("您通过微信登录,无法绑定其他微信");
|
|
|
}
|
|
|
- //绑定微信 获取临时带参数二维码
|
|
|
- //获取gzh带参数的二维码
|
|
|
- WxGzhQrCodeTicketRep result = weChatService.getWxGzhQrCode(null, null, null, user.getLoginPhone(), user.getEmail(), null);
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(result);
|
|
|
+ //网页授权二维码
|
|
|
+ Long mappingId = SEQUENCE.nextId();
|
|
|
+ AuthRedirect redirect = new AuthRedirect()
|
|
|
+ .setMappingId(mappingId)
|
|
|
+ .setLp(user.getLoginPhone())
|
|
|
+ .setLe(user.getEmail());
|
|
|
+ String returnUrl = request.getReturnUrl();
|
|
|
+ String envType = request.getEnvType();
|
|
|
+ if (StrUtil.isNotBlank(returnUrl)) {
|
|
|
+ if (StrUtil.isNotBlank(envType)) {
|
|
|
+ returnUrl = envCommonService.getDomain() + envType + "/web/" + returnUrl;
|
|
|
+ } else {
|
|
|
+ returnUrl = envCommonService.getDomain() + "/web/" + returnUrl;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ redisService.set(mappingId.toString(), returnUrl, 60 * 60 * 24L);
|
|
|
+ String redirectUrl = wxOpenPlatYHLXLoginConfig.getBaRedirectUrl();
|
|
|
+ String state = Codec.DoBase64.custom().setData(Jsons.toJson(redirect)).encodeAsText();
|
|
|
+ String wxAuthUrl = authorizationService.createWxAuthLoginUrl(state, redirectUrl);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(wxAuthUrl);
|
|
|
}
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
}
|