保誠-保戶業務員媒合平台
wayne
2021-11-24 03a858f2882bedeb5925b65cb045ccbbb1202329
pamapi/src/main/java/com/pollex/pam/web/rest/OtpResource.java
@@ -21,6 +21,7 @@
import javax.xml.rpc.ServiceException;
import java.rmi.RemoteException;
import java.util.Arrays;
import java.util.UUID;
@RestController
@@ -43,22 +44,18 @@
    @PostMapping("/sendOtp")
    public ResponseEntity<Object> sendOtp(@RequestBody OtpLoginVM login) {
        try {
            if(applicationProperty.isMockLogin()) {
                return new ResponseEntity<>(getMockSendOtpResponse(), HttpStatus.OK);
            }
            if(login.getLoginType() == OtpLoginTypeEnum.SMS) {
                return new ResponseEntity<>(otpWebService.sendByPhone(login.getAccount()), HttpStatus.OK);
            }
            else if(login.getLoginType() == OtpLoginTypeEnum.EMAIL) {
                return new ResponseEntity<>(otpWebService.sendByEmail(login.getAccount()), HttpStatus.OK);
            }
            return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("can not support this login type, loginType = " + login.getLoginType().name());
        } catch (ServiceException | RemoteException e) {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("connecting otp web service error");
        if(applicationProperty.isMockLogin()) {
            return new ResponseEntity<>(getMockSendOtpResponse(), HttpStatus.OK);
        }
        if(login.getLoginType() == OtpLoginTypeEnum.SMS) {
            return new ResponseEntity<>(otpWebService.sendByPhone(login.getAccount()), HttpStatus.OK);
        }
        else if(login.getLoginType() == OtpLoginTypeEnum.EMAIL) {
            return new ResponseEntity<>(otpWebService.sendByEmail(login.getAccount()), HttpStatus.OK);
        }
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("can not support this login type, loginType = " + login.getLoginType().name());
    }
    @PostMapping("/verify")
@@ -79,6 +76,6 @@
    private OtpResponseDTO getMockSendOtpResponse() {
        String indexKey = UUID.randomUUID().toString().substring(0, 8);
        return new OtpResponseDTO(new String[]{indexKey, "0", "", ""});
        return new OtpResponseDTO(Arrays.asList(indexKey, "0", "", ""));
    }
}