-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 카카오 메시지 (포인트 충전 접수, 포인트 충전 완료, 포인트 출금 접수, 포인트 출금 완료) 추가
- Loading branch information
Showing
7 changed files
with
294 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
254 changes: 254 additions & 0 deletions
254
src/main/java/com/example/sinitto/common/service/KakaoMessageService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,254 @@ | ||
package com.example.sinitto.common.service; | ||
|
||
import com.example.sinitto.auth.service.KakaoTokenService; | ||
import com.example.sinitto.common.properties.KakaoProperties; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.RequestEntity; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.net.URI; | ||
import java.net.URLEncoder; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
@Service | ||
public class KakaoMessageService { | ||
|
||
private static final String KAKAO_SEND_ME_BASE_URL = "https://kapi.kakao.com/v2/api/talk/memo/default/send"; | ||
private static final String SINITTO_IMAGE_URL = "https://ifh.cc/g/GhjQyC.jpg"; | ||
|
||
private final KakaoTokenService kakaoTokenService; | ||
private final RestTemplate restTemplate; | ||
private final KakaoProperties kakaoProperties; | ||
|
||
public KakaoMessageService(KakaoTokenService kakaoTokenService, RestTemplate restTemplate, KakaoProperties kakaoProperties) { | ||
this.kakaoTokenService = kakaoTokenService; | ||
this.restTemplate = restTemplate; | ||
this.kakaoProperties = kakaoProperties; | ||
} | ||
|
||
public void sendPointChargeRequestReceivedMessage(String email, int point, String name) { | ||
String accessToken = kakaoTokenService.getValidAccessTokenInServer(email); | ||
|
||
if (accessToken == null) { | ||
return; | ||
} | ||
|
||
HttpHeaders headers = new HttpHeaders(); | ||
headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE); | ||
headers.setBearerAuth(accessToken); | ||
|
||
String templateObject = String.format( | ||
"{" + | ||
"\"object_type\": \"feed\"," + | ||
"\"content\": {" + | ||
"\"title\": \"%s님의 포인트 충전 요청 접수\"," + | ||
"\"description\": \"충전까지 최대 2~3영업일이 소요됩니다.\"," + | ||
"\"image_url\": \"%s\"," + | ||
"\"image_width\": 640," + | ||
"\"image_height\": 640," + | ||
"\"link\": {" + | ||
"\"web_url\": \"%s\"," + | ||
"\"mobile_web_url\": \"%s\"" + | ||
"}" + | ||
"}," + | ||
"\"item_content\": {" + | ||
"\"items\": [" + | ||
"{\"item\": \"충전 요청\", \"item_op\": \"%d points\"}" + | ||
"]" + | ||
"}," + | ||
"\"buttons\": [" + | ||
"{" + | ||
"\"title\": \"서비스 이용하기\"," + | ||
"\"link\": {" + | ||
"\"web_url\": \"%s\"," + | ||
"\"mobile_web_url\": \"%s\"" + | ||
"}" + | ||
"}" + | ||
"]" + | ||
"}", | ||
name, SINITTO_IMAGE_URL, kakaoProperties.frontUri(), kakaoProperties.frontUri(), point, | ||
kakaoProperties.frontUri(), kakaoProperties.frontUri() | ||
); | ||
|
||
|
||
String encodedTemplateObject = URLEncoder.encode(templateObject, StandardCharsets.UTF_8); | ||
|
||
RequestEntity<String> request = new RequestEntity<>( | ||
"template_object=" + encodedTemplateObject, | ||
headers, HttpMethod.POST, URI.create(KAKAO_SEND_ME_BASE_URL)); | ||
|
||
restTemplate.exchange(request, String.class); | ||
} | ||
|
||
public void sendPointChargeCompleteMessage(String email, int point, String name) { | ||
String accessToken = kakaoTokenService.getValidAccessTokenInServer(email); | ||
|
||
if (accessToken == null) { | ||
return; | ||
} | ||
|
||
HttpHeaders headers = new HttpHeaders(); | ||
headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE); | ||
headers.setBearerAuth(accessToken); | ||
|
||
String templateObject = String.format( | ||
"{" + | ||
"\"object_type\": \"feed\"," + | ||
"\"content\": {" + | ||
"\"title\": \"%s님의 포인트 충전이 완료\"," + | ||
"\"description\": \"서비스를 이용해주셔서 감사합니다.\"," + | ||
"\"image_url\": \"%s\"," + | ||
"\"image_width\": 640," + | ||
"\"image_height\": 640," + | ||
"\"link\": {" + | ||
"\"web_url\": \"%s\"," + | ||
"\"mobile_web_url\": \"%s\"" + | ||
"}" + | ||
"}," + | ||
"\"item_content\": {" + | ||
"\"items\": [" + | ||
"{\"item\": \"충전된 포인트\", \"item_op\": \"%d points\"}" + | ||
"]" + | ||
"}," + | ||
"\"buttons\": [" + | ||
"{" + | ||
"\"title\": \"서비스 이용하기\"," + | ||
"\"link\": {" + | ||
"\"web_url\": \"%s\"," + | ||
"\"mobile_web_url\": \"%s\"" + | ||
"}" + | ||
"}" + | ||
"]" + | ||
"}", | ||
name, SINITTO_IMAGE_URL, kakaoProperties.frontUri(), kakaoProperties.frontUri(), point, | ||
kakaoProperties.frontUri(), kakaoProperties.frontUri() | ||
); | ||
|
||
String encodedTemplateObject = URLEncoder.encode(templateObject, StandardCharsets.UTF_8); | ||
|
||
RequestEntity<String> request = new RequestEntity<>( | ||
"template_object=" + encodedTemplateObject, | ||
headers, HttpMethod.POST, URI.create(KAKAO_SEND_ME_BASE_URL)); | ||
|
||
restTemplate.exchange(request, String.class); | ||
} | ||
|
||
public void sendPointWithdrawRequestReceivedMessage(String email, int point, String name, String bankName, String accountNumber) { | ||
String accessToken = kakaoTokenService.getValidAccessTokenInServer(email); | ||
|
||
if (accessToken == null) { | ||
return; | ||
} | ||
|
||
HttpHeaders headers = new HttpHeaders(); | ||
headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE); | ||
headers.setBearerAuth(accessToken); | ||
|
||
String templateObject = String.format( | ||
"{" + | ||
"\"object_type\": \"feed\"," + | ||
"\"content\": {" + | ||
"\"title\": \"%s님의 포인트 인출 요청 접수\"," + | ||
"\"description\": \"인출에는 최대 2~3영업일이 소요됩니다.\"," + | ||
"\"image_url\": \"%s\"," + | ||
"\"image_width\": 640," + | ||
"\"image_height\": 640," + | ||
"\"link\": {" + | ||
"\"web_url\": \"%s\"," + | ||
"\"mobile_web_url\": \"%s\"" + | ||
"}" + | ||
"}," + | ||
"\"item_content\": {" + | ||
"\"items\": [" + | ||
"{\"item\": \"인출 포인트\", \"item_op\": \"%d points\"}," + | ||
"{\"item\": \"인출 금액\", \"item_op\": \"%.0f 원\"}," + | ||
"{\"item\": \"은행\", \"item_op\": \"%s\"}," + | ||
"{\"item\": \"계좌번호\", \"item_op\": \"%s\"}," + | ||
"{\"item\": \"성명\", \"item_op\": \"%s\"}" + | ||
"]" + | ||
"}," + | ||
"\"buttons\": [" + | ||
"{" + | ||
"\"title\": \"서비스 이용하기\"," + | ||
"\"link\": {" + | ||
"\"web_url\": \"%s\"," + | ||
"\"mobile_web_url\": \"%s\"" + | ||
"}" + | ||
"}" + | ||
"]" + | ||
"}", | ||
name, SINITTO_IMAGE_URL, kakaoProperties.frontUri(), kakaoProperties.frontUri(), point, point * 0.95, | ||
bankName, accountNumber, name, kakaoProperties.frontUri(), kakaoProperties.frontUri() | ||
); | ||
|
||
|
||
String encodedTemplateObject = URLEncoder.encode(templateObject, StandardCharsets.UTF_8); | ||
|
||
RequestEntity<String> request = new RequestEntity<>( | ||
"template_object=" + encodedTemplateObject, | ||
headers, HttpMethod.POST, URI.create(KAKAO_SEND_ME_BASE_URL)); | ||
|
||
restTemplate.exchange(request, String.class); | ||
} | ||
|
||
public void sendPointWithdrawCompleteMessage(String email, int point, String name, String bankName, String accountNumber) { | ||
String accessToken = kakaoTokenService.getValidAccessTokenInServer(email); | ||
|
||
if (accessToken == null) { | ||
return; | ||
} | ||
|
||
HttpHeaders headers = new HttpHeaders(); | ||
headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE); | ||
headers.setBearerAuth(accessToken); | ||
|
||
String templateObject = String.format( | ||
"{" + | ||
"\"object_type\": \"feed\"," + | ||
"\"content\": {" + | ||
"\"title\": \"%s님의 포인트 인출 완료\"," + | ||
"\"description\": \"서비스를 이용해주셔서 감사합니다.\"," + | ||
"\"image_url\": \"%s\"," + | ||
"\"image_width\": 640," + | ||
"\"image_height\": 640," + | ||
"\"link\": {" + | ||
"\"web_url\": \"%s\"," + | ||
"\"mobile_web_url\": \"%s\"" + | ||
"}" + | ||
"}," + | ||
"\"item_content\": {" + | ||
"\"items\": [" + | ||
"{\"item\": \"인출 포인트\", \"item_op\": \"%d points\"}," + | ||
"{\"item\": \"인출 금액\", \"item_op\": \"%.0f 원\"}," + | ||
"{\"item\": \"은행\", \"item_op\": \"%s\"}," + | ||
"{\"item\": \"계좌번호\", \"item_op\": \"%s\"}," + | ||
"{\"item\": \"성명\", \"item_op\": \"%s\"}" + | ||
"]" + | ||
"}," + | ||
"\"buttons\": [" + | ||
"{" + | ||
"\"title\": \"서비스 이용하기\"," + | ||
"\"link\": {" + | ||
"\"web_url\": \"%s\"," + | ||
"\"mobile_web_url\": \"%s\"" + | ||
"}" + | ||
"}" + | ||
"]" + | ||
"}", | ||
name, SINITTO_IMAGE_URL, kakaoProperties.frontUri(), kakaoProperties.frontUri(), point, point * 0.95, | ||
bankName, accountNumber, name, kakaoProperties.frontUri(), kakaoProperties.frontUri() | ||
); | ||
|
||
String encodedTemplateObject = URLEncoder.encode(templateObject, StandardCharsets.UTF_8); | ||
|
||
RequestEntity<String> request = new RequestEntity<>( | ||
"template_object=" + encodedTemplateObject, | ||
headers, HttpMethod.POST, URI.create(KAKAO_SEND_ME_BASE_URL)); | ||
|
||
restTemplate.exchange(request, String.class); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.