|
|
|
@ -5,29 +5,36 @@ import com.internal.response.NumberResponse;
|
|
|
|
|
import com.taxi.apipassenger.remote.ServiceVerificatoncodeClient;
|
|
|
|
|
import net.sf.json.JSONObject;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class VerificationCodeService {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ServiceVerificatoncodeClient serviceVerificatoncodeClient;
|
|
|
|
|
|
|
|
|
|
public String generatorCode(String passenegerPhone) {
|
|
|
|
|
//乘客验证码的前缀
|
|
|
|
|
private String verificationCodePrefix = "passenger-verificatioin-code-";
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private StringRedisTemplate stringRedisTemplate;
|
|
|
|
|
|
|
|
|
|
public ResponseResult generatorCode(String passenegerPhone) {
|
|
|
|
|
//调用验证码服务,获取验证码
|
|
|
|
|
System.out.println("调用验证码服务,获取验证码");
|
|
|
|
|
|
|
|
|
|
ResponseResult<NumberResponse> responseResult = serviceVerificatoncodeClient.getNumberCode(6);
|
|
|
|
|
int code = responseResult.getData().getNumberCode();
|
|
|
|
|
System.out.println("访问service-verificationcode服务,获取验证码:" + code );
|
|
|
|
|
|
|
|
|
|
int numberCode = responseResult.getData().getNumberCode();
|
|
|
|
|
System.out.println("访问service-verificationcode服务,获取验证码:" + numberCode );
|
|
|
|
|
//key,value,过期时间
|
|
|
|
|
String key = verificationCodePrefix + passenegerPhone;
|
|
|
|
|
//存入redis
|
|
|
|
|
System.out.println("存入redis");
|
|
|
|
|
stringRedisTemplate.opsForValue().set(key,numberCode+"",2, TimeUnit.MINUTES);
|
|
|
|
|
|
|
|
|
|
//返回值
|
|
|
|
|
JSONObject result = new JSONObject();
|
|
|
|
|
result.put("code", code);
|
|
|
|
|
result.put("message", "success");
|
|
|
|
|
return result.toString();
|
|
|
|
|
//通过短信服务商,将对应的验证码发送到手机上。阿里短信服务,腾讯短信通,容联
|
|
|
|
|
|
|
|
|
|
return ResponseResult.success();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|