feat: 카카오 더즌 bill api call swagger 테스트 추가

dev
Jonguk. Lim 1 year ago
parent cb4766da85
commit 4f5bcbc3f7

@ -192,6 +192,15 @@ public class SpringDocConfig {
.build();
}
@Profile({"local", "prod", "dev"})
@Bean
public GroupedOpenApi doznApiDoc() {
return GroupedOpenApi.builder()
.group("카카오 더즌 페이 url")
.pathsToMatch("/api/kakao/pay/bill/dozn/url")
.build();
}
// @Bean
// public GroupedOpenApi adminApiDoc() {
// return GroupedOpenApi.builder()

@ -0,0 +1,107 @@
package cokr.xit.ens.modules.common.ctgy.intgrnbill.kko.presentation;
import java.nio.charset.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.http.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.util.*;
import cokr.xit.ens.core.utils.*;
import io.swagger.v3.oas.annotations.*;
import io.swagger.v3.oas.annotations.tags.*;
import lombok.extern.slf4j.*;
/**
* <pre>
* description :
* packageName : cokr.xit.ens.modules.common.ctgy.intgrnbill.kko.presentation
* fileName : DoznApiCallUrlBillerCodeController
* author : limju
* date : 2024 12 09
* ======================================================================
*
* ----------------------------------------------------------------------
* 2024 12 09 limju
*
* </pre>
*/
@Tag(name = "DoznApiCallUrlBillerCodeController", description = "Dozn call url")
@Slf4j
@RestController
public class DoznApiCallUrlBillerCodeController {
@Value("${contract.kakao.pay.bill.dozn.host}")
private String HOST;
@Value("${contract.kakao.pay.bill.dozn.api.url}")
private String API_URL;
@Operation(summary = "Dozn call url", description = "Dozn call url")
@RequestMapping(value = "/api/kakao/pay/bill/dozn/url", method = {RequestMethod.GET, RequestMethod.POST})
public ResponseEntity<String> url(
@Parameter(name = "billerCode", description = "billerCode", required = true, example = "??")
String billerCode,
@Parameter(name = "Authorization", description = "Authorization", required = true, example = "Bearer??")
String authorization,
@Parameter(name = "jsonStr", description = "jsonStr", required = true, example = "{}")
String jsonStr) {
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", authorization);
headers.setContentType(new MediaType(MediaType.APPLICATION_JSON, Charset.forName("utf-8")));
StringBuilder url = new StringBuilder();
url.append(this.HOST)
.append(this.API_URL.replace("{billerCode}", billerCode == null ? "" : billerCode));
ResponseEntity<String> resp = this.callApi(HttpMethod.POST, url.toString(), jsonStr, headers);
//String uuid = IdGenerator.getUUID();
//String data = "{\"res_code\":\"OK\",\"message\":\"성공\",\"data\":{\"url\":\"https://billgatesweb.kakao.com/r/platform/pages/paynow/search/" + uuid + "\"}}";
return ResponseEntity.ok(resp.getBody());
}
private ResponseEntity<String> callApi(HttpMethod method, String url, String body, HttpHeaders headers) {
StringBuffer sb = new StringBuffer();
ResponseEntity<String> responseEntity = ResponseEntity.ok("test");
try {
HttpEntity<?> entity = null;
UriComponents uri = null;
switch (method) {
case GET:
entity = new HttpEntity<>(headers);
uri = UriComponentsBuilder
.fromHttpUrl(String.format("%s?%s", url, body == null ? "" : body))
.build(false);
break;
case POST:
entity = new HttpEntity<>(body, headers);
uri = UriComponentsBuilder
.fromHttpUrl(url)
.encode(StandardCharsets.UTF_8)
.build();
break;
default:
break;
}
sb.append("\n url => " + uri.toString())
.append("\n method => " + method)
.append("\n headers => " + entity.getHeaders().toString())
.append("\n body => " + entity.getBody());
} catch (Exception e) {
log.error("call API 기타오류\n[ url ]: {} \n[ param ]: {} \n[ error ]: {}", url, body, CmmnUtil.printStackTraceToString(e));
} finally {
log.info("카카오페이 청구서 API\n[ REQUEST ]-----------------------------------------------------------------------\n{}\n[ RESPONSE ]-----------------------------------------------------------------------\n{}", sb.toString(), responseEntity.getBody());
}
return responseEntity;
}
}
Loading…
Cancel
Save