// create 6-digit public int create6digit() { SecureRandom sr = SecureRandom.getInstance("SHA1PRNG"); int verificationNumber = sr.nextInt(900000) + 100000; } @Configuration public class RetrofitConfig { @Bean public CoolSMSService coolSMSService(ObjectMapper objectMapper) { Retrofit retrofit = new Retrofit.Builder().baseUrl("https://api.coolsms.co.kr/") .addConverterFactory(JacksonConverterFactory.create(objectMapper)) .build(); return retrofit.create(CoolSMSService.class); } } @Service public interface CoolSMSService { @POST("sms/2/send") Call sendSms(@Body CoolSMSRequest coolSMSRequest); } public class CoolSMSRequest { @JsonProperty("api_key") String apiKey; String timestamp; String salt; String signature; final String encoding = "base64"; String to; final String from = ""; String text; public static CoolSMSRequest of() { CoolSMSRequest coolSMSRequest = new CoolSMSRequest(); try { coolSMSRequest.apiKey = ""; String apiSecret = ""; coolSMSRequest.timestamp = String.valueOf(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()); coolSMSRequest.salt = UUID.randomUUID().toString(); String hmacData = coolSMSRequest.timestamp + coolSMSRequest.salt; SecretKeySpec key = new SecretKeySpec(apiSecret.getBytes(), "HmacMD5"); Mac mac = Mac.getInstance("HmacMD5"); mac.init(key); coolSMSRequest.signature = Base64.encodeBase64String(mac.doFinal(hmacData.getBytes())); } catch (Exception ex) { } return coolSMSRequest; } public String getApiKey() { return this.apiKey; } public String getTimestamp() { return this.timestamp; } public String getSalt() { return this.salt; } public String getSignature() { return this.signature; } public String getEncoding() { return this.encoding; } public String getTo() { return this.to; } public void setTo(String to) { this.to = to; } public String getFrom() { return this.from; } public String getText() { return this.text; } public void setText(String text) { this.text = text; } } @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) public class CoolSMSResponse { Boolean successful; Integer successCount; Integer errorCount; String groupId; String resultCode; String resultMessage; LinkedHashMap errorList; public Boolean getSuccessful() { return this.successful; } public Integer getSuccessCount() { return this.successCount; } public Integer getErrorCount() { return this.errorCount; } public String getGroupId() { return this.groupId; } public String getResultCode() { return this.resultCode; } public String getResultMessage() { return this.resultMessage; } public LinkedHashMap getErrorList() { return this.errorList; } }