|
|
@ -1,23 +1,40 @@
|
|
|
|
package mashibing.online.text.controller;
|
|
|
|
package mashibing.online.text.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.mashibing.dto.PassengerRequestDto;
|
|
|
|
import com.mashibing.dto.PassengerRequestDto;
|
|
|
|
import com.mashibing.dto.ResponseResult;
|
|
|
|
import com.mashibing.dto.ResponseResult;
|
|
|
|
|
|
|
|
import com.mashibing.util.JwtUtils;
|
|
|
|
|
|
|
|
import mashibing.online.text.consonant.PassengerConsonant;
|
|
|
|
|
|
|
|
import mashibing.online.text.dto.UserInfo;
|
|
|
|
|
|
|
|
import mashibing.online.text.feign.SendSMSCodeService;
|
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @author zxx
|
|
|
|
* @author zxx
|
|
|
|
* @Description
|
|
|
|
* @Description
|
|
|
|
* @date 2022/10/5
|
|
|
|
* @date 2022/10/5
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
|
|
|
|
|
|
|
|
public class PassengerController {
|
|
|
|
public class PassengerController {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private SendSMSCodeService sendSMSCodeService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private StringRedisTemplate stringRedisTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/getPhoneNumberCode")
|
|
|
|
@PostMapping("/getPhoneNumberCode")
|
|
|
|
public ResponseResult getPhoneNumberCode(@RequestBody PassengerRequestDto passengerRequestDto){
|
|
|
|
public ResponseResult getPhoneNumberCode(@RequestBody PassengerRequestDto passengerRequestDto){
|
|
|
|
// 校验参数
|
|
|
|
// 校验参数
|
|
|
@ -27,9 +44,11 @@ public class PassengerController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 调服务获取验证码
|
|
|
|
// 调服务获取验证码
|
|
|
|
|
|
|
|
String smsCode = sendSMSCodeService.getSmsCode(6,passengerRequestDto.getPhoneNumber());
|
|
|
|
|
|
|
|
System.out.println(""+ JSON.toJSONString(smsCode));
|
|
|
|
// 存入redis 有限时间
|
|
|
|
// 存入redis 有限时间
|
|
|
|
|
|
|
|
stringRedisTemplate.opsForValue().set(PassengerConsonant.phoneNumberCodePreKey+passengerRequestDto.getPhoneNumber(),
|
|
|
|
|
|
|
|
smsCode,2, TimeUnit.MINUTES);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ResponseResult.success("成功!");
|
|
|
|
return ResponseResult.success("成功!");
|
|
|
@ -39,15 +58,29 @@ public class PassengerController {
|
|
|
|
@PostMapping("/checkPhoneNumberCode")
|
|
|
|
@PostMapping("/checkPhoneNumberCode")
|
|
|
|
public ResponseResult checkPhoneNumberCode(@RequestBody PassengerRequestDto passengerRequestDto){
|
|
|
|
public ResponseResult checkPhoneNumberCode(@RequestBody PassengerRequestDto passengerRequestDto){
|
|
|
|
// 校验参数
|
|
|
|
// 校验参数
|
|
|
|
|
|
|
|
if(ObjectUtil.isNull(passengerRequestDto)||ObjectUtil.isEmpty(passengerRequestDto.getPhoneNumber())||ObjectUtil.isEmpty(passengerRequestDto.getPhoneNumberCode())){
|
|
|
|
|
|
|
|
throw new RuntimeException("手机号码 和短信验证码必填");
|
|
|
|
|
|
|
|
|
|
|
|
// 校验验证码高大上地方
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 校验验证码
|
|
|
|
|
|
|
|
String phone=passengerRequestDto.getPhoneNumber();
|
|
|
|
|
|
|
|
String redisCode = stringRedisTemplate.opsForValue().get(PassengerConsonant.phoneNumberCodePreKey + phone);
|
|
|
|
|
|
|
|
if(StringUtils.isBlank(redisCode)){
|
|
|
|
|
|
|
|
throw new RuntimeException("短信验证码已过期!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String reqCode=passengerRequestDto.getPhoneNumberCode();
|
|
|
|
|
|
|
|
if(!reqCode.equals(redisCode)){
|
|
|
|
|
|
|
|
throw new RuntimeException("短信验证码错误!");
|
|
|
|
|
|
|
|
}
|
|
|
|
// 用户注册
|
|
|
|
// 用户注册
|
|
|
|
|
|
|
|
System.out.println("phone 短信验证码正确");
|
|
|
|
|
|
|
|
|
|
|
|
// 返回token
|
|
|
|
// 返回token
|
|
|
|
|
|
|
|
String token = JwtUtils.genaroteToken(phone, PassengerConsonant.PassengerIdendity);
|
|
|
|
|
|
|
|
UserInfo userInfo =new UserInfo();
|
|
|
|
return ResponseResult.success("成功!");
|
|
|
|
userInfo.setPhoneNumber(phone);
|
|
|
|
|
|
|
|
userInfo.setToken(token);
|
|
|
|
|
|
|
|
return ResponseResult.success(userInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|