飞滴出行网约车2022-乘客端 校验验证码骨架完成

master
yh 3 years ago
parent 90ee01ad22
commit 0ebcfa6f94

@ -6,6 +6,7 @@ import com.mashibing.apipassenger.service.VerificationCodeService;
import com.mashibing.internalcommon.dto.ResponseResult; import com.mashibing.internalcommon.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
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.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -15,13 +16,25 @@ public class VerificationController {
@Autowired @Autowired
private VerificationCodeService service; private VerificationCodeService service;
// 实现 乘客获取验证码 API // 乘客获取验证码 API
@GetMapping("/verification-code") @GetMapping("/verification-code")
public ResponseResult verificationcode(@RequestBody VerificationCodeDTO verificationCodeDTO){ public ResponseResult verificationCode(@RequestBody VerificationCodeDTO verificationCodeDTO){
String passengerPhone = verificationCodeDTO.getPassengerPhone(); String passengerPhone = verificationCodeDTO.getPassengerPhone();
return service.generatorCode(passengerPhone); return service.generatorCode(passengerPhone);
} }
// 校验乘客获取验证码 API
@PostMapping("/verification-code-check")
public ResponseResult checkVerificationCode(@RequestBody VerificationCodeDTO verificationCodeDTO){
String passengerPhone = verificationCodeDTO.getPassengerPhone();
String verificationCode = verificationCodeDTO.getVerificationCode();
System.out.println("手机号 "+passengerPhone+",验证码 "+verificationCode);
return service.checkCode(passengerPhone,verificationCode);
}
} }

@ -1,15 +1,13 @@
package com.mashibing.apipassenger.request; package com.mashibing.apipassenger.request;
import lombok.Data;
@Data
public class VerificationCodeDTO { public class VerificationCodeDTO {
private String passengerPhone; private String passengerPhone;
public String getPassengerPhone() { private String verificationCode;
return passengerPhone;
}
public void setPassengerPhone(String passengerPhone) {
this.passengerPhone = passengerPhone;
}
} }

@ -3,6 +3,7 @@ package com.mashibing.apipassenger.service;
import com.mashibing.apipassenger.remote.ServiceVerificationcodeClient; import com.mashibing.apipassenger.remote.ServiceVerificationcodeClient;
import com.mashibing.internalcommon.dto.ResponseResult; import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.response.NumberCodeResponse; import com.mashibing.internalcommon.response.NumberCodeResponse;
import com.mashibing.internalcommon.response.TokenResponse;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
@ -22,6 +23,11 @@ public class VerificationCodeService {
private String prefixKey = "passenger-verification-code-"; private String prefixKey = "passenger-verification-code-";
/**
* redis
* @param passengerPhone
* @return
*/
public ResponseResult generatorCode(String passengerPhone){ public ResponseResult generatorCode(String passengerPhone){
// 使用 feign 远程调用生成验证码服务接口 // 使用 feign 远程调用生成验证码服务接口
@ -36,4 +42,29 @@ public class VerificationCodeService {
return ResponseResult.success(""); return ResponseResult.success("");
} }
/**
* redis
* @param passengerPhone
* @return
*/
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);
// 对比验证码是否相同
// if(codetmp.equals(verificationCode)){
// System.out.println("验证码校验正确");
// }
// 返回处理结果
TokenResponse tokenResponse = new TokenResponse();
tokenResponse.setToken("token value");
return ResponseResult.success(tokenResponse);
}
} }

@ -0,0 +1,10 @@
package com.mashibing.internalcommon.response;
import lombok.Data;
@Data
public class TokenResponse {
private String token;
}
Loading…
Cancel
Save