주기성을 위해 어떤 기술을 써야할까 고민이 많았다
카카오메시지 api 사용을 위해서는 access 토큰이 필요한 것이 핵심포인트였다 .. 하지만 access token 은 유효기간이 짧았고 로그인할때 발급받는 것 이므로 서버에서 재사용하는 것이 불가하였다.
=> 따라서 나는 자바스크립트에서 setInterval 함수를 쓰기로 결정!
sendMessage = setInterval(function() {
console.log($(".test").css("background-color"))
if ( $(".test").css("background-color")=='rgb(255, 0, 0)'){
console.log('메시지 보내야됨')
REST_Call('/message');
}
else{
console.log('글 썼네')
}
}, 86400000);
function REST_Call (path)
{
let access_token=localStorage.getItem('access_token')
console.log(access_token);
$.ajax({
type: "POST",
url: path,
contentType: "application/json",
data: JSON.stringify({'token':access_token}),
success: (data) => { alert('메시지가 전송되었습니다!'); }
});
}
@PostMapping("/message")
public void message(@RequestBody SocialLoginDto socialLoginDto) {
//access 토큰을 발급받아야함
String token = socialLoginDto.getToken();
log.info(token);
String message= userService.sendmessage(token);
}
try {
authenticationManager.authenticate(
new UsernamePasswordAuthenticationToken(userDto.getUsername(), userDto.getPassword())
);