|
|
@@ -27,12 +27,14 @@ import com.cyksj.service.authorization.AuthorizationService;
|
|
|
import com.cyksj.service.distribute.DistributeService;
|
|
|
import com.cyksj.service.mail.MailService;
|
|
|
import com.cyksj.service.template.TemplateCommonService;
|
|
|
+import com.cyksj.service.user.BadIntentionOpService;
|
|
|
import com.cyksj.service.user.UserService;
|
|
|
import com.cyksj.service.wechat.WeChatService;
|
|
|
import com.cyksj.web.util.StpUserUtil;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.dao.DuplicateKeyException;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
@@ -67,6 +69,8 @@ public class AuthorizationController {
|
|
|
|
|
|
private final RedisService redisService;
|
|
|
|
|
|
+ private final BadIntentionOpService badIntentionOpService;
|
|
|
+
|
|
|
private final WxOpenPlatYHLXLoginConfig wxOpenPlatYHLXLoginConfig;
|
|
|
|
|
|
private final EnvCommonService envCommonService;
|
|
|
@@ -77,10 +81,6 @@ public class AuthorizationController {
|
|
|
|
|
|
private final TemplateCommonService templateCommonService;
|
|
|
|
|
|
- private final DistributeService distributeService;
|
|
|
-
|
|
|
- private final UserDistributePopularizeMapper distributePopularizeMapper;
|
|
|
-
|
|
|
@GetMapping(value = "/weChat")
|
|
|
public void base(String url, String dsCode, Long sharedId, Integer dsType, Long popularizeId, String authType, String callbackType, String callback, HttpServletResponse response) throws Exception {
|
|
|
|
|
|
@@ -309,34 +309,47 @@ public class AuthorizationController {
|
|
|
*/
|
|
|
@GetMapping("/get/phone/code")
|
|
|
@NoSubmit
|
|
|
- public Result<String> getPhoneCode(String phone, Integer digit, @RequestParam(defaultValue = "0") Boolean isFree, Integer cid) {
|
|
|
+ public Result<String> getPhoneCode(String phone, Integer digit, @RequestParam(defaultValue = "0") Boolean isFree, Integer cid) throws Exception {
|
|
|
if (cid == null) cid = 86;
|
|
|
if (StrUtil.isBlank(phone) || (86 == cid && !Validator.isMobile(phone))) {
|
|
|
throw BusinessRuntimeException.getInstance("请输入正确的手机号");
|
|
|
}
|
|
|
- if ("13662979985".equals(phone)) {
|
|
|
- throw BusinessRuntimeException.getInstance("异常手机号");
|
|
|
- }
|
|
|
//是否是虚拟手机号开头
|
|
|
if (BlackOpsUtil.phoneIsStart(phone)) {
|
|
|
throw BusinessRuntimeException.getInstance("请输入正确的手机号");
|
|
|
}
|
|
|
- PhoneCode phoneCode = phoneCodeMapper.selectOne(Wrappers.lambdaQuery(PhoneCode.class).eq(PhoneCode::getPhone, phone).last("limit 1"));
|
|
|
- if (phoneCode == null) {
|
|
|
- phoneCode = new PhoneCode();
|
|
|
- phoneCode.setPhone(phone);
|
|
|
+ Object exists = redisService.get(RedisService.key.PHONE_CODE_KEY.getName() + phone);
|
|
|
+ if (exists != null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("短信验证码未失效");
|
|
|
}
|
|
|
+ //是否是恶意用户
|
|
|
+ badIntentionOpService.checkHandleBadUserOp(phone);
|
|
|
String code = StringUtil.getRandomCodeStr(digit);
|
|
|
- phoneCode.setCode(code);
|
|
|
- if (phoneCode.getId() == null) {
|
|
|
- phoneCode.setCid(cid);
|
|
|
- phoneCodeMapper.insert(phoneCode);
|
|
|
- } else phoneCodeMapper.updateById(phoneCode);
|
|
|
+ Boolean isFlag;
|
|
|
if (!isFree) {
|
|
|
- SmsUtil.sendTencent(cid, phone, code);
|
|
|
+ isFlag = SmsUtil.sendTencent(cid, phone, code);
|
|
|
} else {
|
|
|
// 发送短信
|
|
|
- SmsUtil.sendLuoKey2Msg(phone, String.format("尊敬的用户,您的验证码为%s,此验证码仅用于银河录像。【银河录像局】", code));
|
|
|
+ isFlag = SmsUtil.sendLuoKey2Msg(phone, String.format("尊敬的用户,您的验证码为%s,此验证码仅用于银河录像。【银河录像局】", code));
|
|
|
+ }
|
|
|
+ if (!isFlag) {
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult("发送短信验证码失败");
|
|
|
+ }
|
|
|
+ redisService.setNx(RedisService.key.PHONE_CODE_KEY.getName() + phone, phone, RedisService.key.PHONE_CODE_KEY.getTimeout());
|
|
|
+ try {
|
|
|
+ PhoneCode phoneCode = phoneCodeMapper.selectOne(Wrappers.lambdaQuery(PhoneCode.class).eq(PhoneCode::getPhone, phone).last("limit 1"));
|
|
|
+ if (phoneCode == null) {
|
|
|
+ phoneCode = new PhoneCode();
|
|
|
+ phoneCode.setPhone(phone);
|
|
|
+ }
|
|
|
+ phoneCode.setCode(code);
|
|
|
+ if (phoneCode.getId() == null) {
|
|
|
+ phoneCode.setCid(cid);
|
|
|
+ phoneCodeMapper.insert(phoneCode);
|
|
|
+ } else {
|
|
|
+ phoneCodeMapper.updateById(phoneCode);
|
|
|
+ }
|
|
|
+ } catch (DuplicateKeyException e) {
|
|
|
}
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(
|
|
|
"发送成功");
|
|
|
@@ -375,6 +388,9 @@ public class AuthorizationController {
|
|
|
//写回登陆信息
|
|
|
StpUserUtil.login(user.getId());
|
|
|
LoginPhoneRep loginPhoneRep = new LoginPhoneRep(StpUserUtil.getTokenValue(), user.getShowId(), user.getNickname(), user.getHeadimgurl());
|
|
|
+ if (loginReq.getPhone() != null) {
|
|
|
+ redisService.del(RedisService.key.PHONE_CODE_KEY.getName() + loginReq.getPhone());
|
|
|
+ }
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(loginPhoneRep);
|
|
|
}
|
|
|
|