|
|
|
@ -1,10 +1,12 @@
|
|
|
|
|
package com.mashibing.apipassenger.service;
|
|
|
|
|
|
|
|
|
|
import com.mashibing.apipassenger.remote.ServiceVerificationcodeClient;
|
|
|
|
|
import com.mashibing.internalcommon.constant.CommonStatusEnum;
|
|
|
|
|
import com.mashibing.internalcommon.dto.ResponseResult;
|
|
|
|
|
import com.mashibing.internalcommon.response.NumberCodeResponse;
|
|
|
|
|
import com.mashibing.internalcommon.response.TokenResponse;
|
|
|
|
|
import net.sf.json.JSONObject;
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
@ -35,7 +37,7 @@ public class VerificationCodeService {
|
|
|
|
|
String numberCode = numberCodeResponse.getData().getNumberCode();
|
|
|
|
|
|
|
|
|
|
// 存入redis
|
|
|
|
|
String redisKey = prefixKey + passengerPhone;
|
|
|
|
|
String redisKey = getRdisKey(passengerPhone);
|
|
|
|
|
redisTemplate.opsForValue().set(redisKey,numberCode,2, TimeUnit.MINUTES);
|
|
|
|
|
|
|
|
|
|
// 返回处理结果
|
|
|
|
@ -43,7 +45,6 @@ public class VerificationCodeService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据 传入手机号 生成验证码并存入redis
|
|
|
|
|
* @param passengerPhone
|
|
|
|
@ -51,20 +52,26 @@ public class VerificationCodeService {
|
|
|
|
|
*/
|
|
|
|
|
public ResponseResult checkCode(String passengerPhone,String verificationCode){
|
|
|
|
|
|
|
|
|
|
System.out.println("passengerPhone = [" + passengerPhone + "], verificationCode = [" + verificationCode + "]");
|
|
|
|
|
|
|
|
|
|
// 根据 key前缀+号码 从redis取出对应 校验码比较
|
|
|
|
|
String redisKey = prefixKey + passengerPhone;
|
|
|
|
|
String codetmp = redisTemplate.opsForValue().get(redisKey);
|
|
|
|
|
String redisKey = getRdisKey(passengerPhone);
|
|
|
|
|
String codeRedis = redisTemplate.opsForValue().get(redisKey);
|
|
|
|
|
|
|
|
|
|
// 对比验证码是否相同
|
|
|
|
|
// if(codetmp.equals(verificationCode)){
|
|
|
|
|
// System.out.println("验证码校验正确");
|
|
|
|
|
// }
|
|
|
|
|
// 校验 验证码 是否相同
|
|
|
|
|
if(StringUtils.isBlank(codeRedis) || !StringUtils.equals(codeRedis,verificationCode) ){
|
|
|
|
|
return ResponseResult.fail(CommonStatusEnum.VERIFICATION_CODE_ERROR.getCode(), CommonStatusEnum.VERIFICATION_CODE_ERROR.getValue());
|
|
|
|
|
}
|
|
|
|
|
// 判断 登录手机号用户是否存在,不存在则注册登录
|
|
|
|
|
|
|
|
|
|
// 返回处理结果
|
|
|
|
|
// 颁布 token 令牌
|
|
|
|
|
TokenResponse tokenResponse = new TokenResponse();
|
|
|
|
|
tokenResponse.setToken("token value");
|
|
|
|
|
tokenResponse.setToken(null);
|
|
|
|
|
|
|
|
|
|
// 返回处理结果
|
|
|
|
|
return ResponseResult.success(tokenResponse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getRdisKey(String passengerPhone){
|
|
|
|
|
return prefixKey.trim() + passengerPhone.trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|