我已经为验证手机创建了Api,我想提出一些逻辑 我可以限制尝试在4小时后验证otp的用户。一世 创建了两个Apis 第一个发送otp给用户和输入 参数是手机号码。 第二个API通过比较第一个API期间用户插入的otp和存储在数据库中的otp来验证手机号
@RestController
@RequestMapping("/api/v1")
public class MobileController2 {
private String To = null;
OtpGenerator otp = new OtpGenerator();
@Autowired
private MobileRepository mobileRepository;
Sms sms = new Sms();
Date date = new Date();
Timestamp timestamp1 = new Timestamp(date.getTime());
Calendar cal = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
@PostMapping(value = "/mobile", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Mobile> createMobile(@RequestBody Mobile mobile) {
int hashcode = otp.RandomOtp();
this.To = mobile.getMob();
String Message = hashcode + " is your Pharmerz verification code ";
if (mobileRepository.findByUserid(mobile.getUserid()) != null) {
Mobile mobileprevious = mobileRepository.findByUserid(mobile.getUserid());
mobileprevious.setMob(mobile.getMob());
mobileprevious.setHASHCODE("" + hashcode);
mobileprevious.setUpdated(mobile.getUpdated());
mobileprevious.setVERIFIED(0);
mobileRepository.save(mobileprevious);
sms.sms_generation(To, Message);
return new ResponseEntity<Mobile>(mobileprevious, HttpStatus.OK);
} else {
mobile.setHASHCODE("" + hashcode);
mobile.setVERIFIED(0);
mobileRepository.save(mobile);
sms.sms_generation(To, Message);
return new ResponseEntity<Mobile>(mobile, HttpStatus.OK);
}
}
@PostMapping(value = "/verifymobile", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Mobile> verifyMobile(@RequestBody Mobile mobile) {
String userid = mobile.getUserid();
String userotp = mobile.getHASHCODE();
Mobile mobileobject = mobileRepository.findByUserid(userid);
if (mobileobject.getHASHCODE().equals(userotp)) {
System.out.println("Matched");
mobileobject.setHASHCODE("");
mobileobject.setVERIFIED(1);
mobileRepository.save(mobileobject);
String Acknowledge = "Thank you for verifying on Pharmerz";
sms.sms_generation(To, Acknowledge);
return new ResponseEntity<Mobile>(mobileobject, HttpStatus.OK);
} else {
System.out.println("Miss matched");
return new ResponseEntity<Mobile>(HttpStatus.BAD_REQUEST);
}
}
}
答案 0 :(得分:4)
在此处为您提供非答案:了解如何编写有用的日志消息以及如何使用debuggers或profilers等工具。
含义: nobody 可以从远程调试此类问题。可能有各种根本原因给你这种行为。
你必须退后一步
换句话说:应用程序中日志记录信息的主要目标是启用您可以在问题发生后进行调试。正是在这种情况下为你提供支持。