Java sample for CODEF API
๋ณธ ์ํ์ CODEF API์ ์ฐ๋์ ์ํ ๊ณตํต ์ฝ๋๋ฅผ ํฌํจํ๊ณ ์์ผ๋ฉฐ, ์ง์ํ๋ ๋ชจ๋ API์ ์๋ํฌ์ธํธ(์ํ, ์นด๋, ๋ณดํ, ์ฆ๊ถ, ๊ณต๊ณต, ๊ธฐํ)๋ https://developer.codef.io ๋ฅผ ํตํด ํ์ธํ ์ ์์ต๋๋ค.
CODEF API๋ ์ํํ ๊ฐ๋ฐ์ ์ํด ์๋๋ฐ์ค, ๊ฐ๋ฐ, ์ด์ ํ๊ฒฝ์ ๊ฐ๊ฐ ์ ๊ณตํฉ๋๋ค.
- ์๋๋ฐ์ค : https://sandbox.codef.io
- ๊ฐ๋ฐ : https://development.codef.io/
- ์ด์ : https://api.codef.io
CODEF API๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์๋ 'access_token' ๋ฐํ์ด ์ ํ๋์ด์ผ ํ๋ฉฐ, ๊ฑฐ๋ ์ Header ์ ํฌํจํ์ฌ ์์ฒญํฉ๋๋ค.
'access_token'์ ๋ฐ๊ธ ๋ฐ๊ธฐ ์ํ 'client_id' ๋ฐ 'client_secret'์ https://codef.io/#/account/keys ์์ ํ์ธํ ์ ์์ต๋๋ค.
๋ฐ๊ธ๋ฐ์ access_token์ ๋ชจ๋ CODEF API ํธ์ถ ์ Headers ์ ์ถ๊ฐ๋์ด์ผ ํฉ๋๋ค. ('Authorization': 'Bearer ' + access_token)
- access_token์ ์ผ์ฃผ์ผ๊ฐ ์ ํจํฉ๋๋ค. ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ ๊ธ๋ก๋ฒ ๋ณ์์ ์ ์ฅํ์ฌ ์ฌ์ฌ์ฉํ๋ ๊ฒ์ ๊ถ์ฅํฉ๋๋ค.
- CODEF API๋ฅผ ํธ์ถ ํ ๋๋ง๋ค access_token์ ์์ฒญํ๋ ๊ฒ์ ํผํฌ๋จผ์ค์ ๋ถ์ ์ ์ ๋๋ค.
- ๊ถ์ฅํ๋ ํ๋ฆ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. [1.ํ ํฐ ๋ฐ๊ธ -> 2.ํ ํฐ ์ ์ฅ -> 3.์ ์ฅ๋ ํ ํฐ์ ์ด์ฉํ์ฌ API ํธ์ถ -> 4.ํ ํฐ์ด ์ ํจํ์ง ์์๊ฒฝ์ฐ ํ ํฐ ์ฌ๋ฐ๊ธ -> 5.API ์ฌ์๋]
String token_url = 'https://oauth.codef.io/oauth/token';
String access_token = RequestToken.getToken("CODEF๋ก๋ถํฐ ๋ฐ๊ธ๋ฐ์ ํด๋ผ์ด์ธํธ ์์ด๋", "CODEF๋ก๋ถํฐ ๋ฐ๊ธ๋ฐ์ ์ํฌ๋ฆฟ ํค");
if (access_token != null){
System.out.println(access_token);
}
else{
System.out.println("ํ ํฐ ๋ฐ๊ธ ์ค๋ฅ");
} {
"access_token" : "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzZXJ2aWNlX3R5cGUiOiIwIiwic2NvcGUiOlsicmVhZCJdLCJzZXJ2aWNlX25vIjoiMDAwMDAwMDQyMDAxIiwiZXhwIjoxNTYzOTQ4NDQ2LCJhdXRob3JpdGllcyI6WyJJTlNVUkFOQ0UiLCJQVUJMSUMiLCJCQU5LIiwiRVRDIiwiU1RPQ0siLCJDQVJEIl0sImp0aSI6Ijc4NDUyMjY4LWFkNDctNGVhNS04ZjljLTQ5ZWI5Yjk1YmQxZCIsImNsaWVudF9pZCI6ImNvZGVmX21hc3RlciJ9.ddZ38ARfTIa4_E8by6gITeIadhQKeDDG4YoGQdGiu-n2sJ1iQ7z81dsMJtc9-YYV-ItIcEn5OXqnIZlGaeF8Ya6Jqy6XdrIb8ou5Sq-jYoB6UXyQRzQsV_1oIIXYSeQtQKalSpPbGGOgLaXsm61fBKimFnnCd1anhxtZAIHwCLMbvQCZlwOeTls1F1EEOvQ76qcdUcmsw-LHM_9I68DwjIwAjyOTe4WPMhsK6KD4MryCAfZRAmdRhG6BWVKk_8D1JPFy42qQmILAr9LXOMODqnVaNeGA-izmtfX5KqqdYxAR6XV_7B9muzYPyGnBL_l2pEcLq5kVSL7YGtczwqB-AA",
"scope" : "read",
"token_type" : "bearer",
"expires_in" : 604799
}CODEF API๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์๋ ์๋์ ์ ๊ฐ ์ฌ์ฉํ๋ ๋์๊ธฐ๊ด์ ์ธ์ฆ์๋จ ๋ฑ๋ก์ด ํ์ํ๋ฉฐ, ์ด๋ฅผ ํตํด ์ฌ์ฉ์๋ง๋ค ์ ๋ํฌํ 'connectedId'๋ฅผ ๋ฐ๊ธ๋ฐ์ ์ ์์ต๋๋ค. ์ดํ์๋ ๋ณ๋์ ์ธ์ฆ์๋จ ์ ์ก ์์ด 'connectedId'๋ฅผ ํตํด์ ๋์๊ธฐ๊ด์ ๋ฐ์ดํฐ๋ฅผ ์ฐ๋ํ ์ ์์ต๋๋ค. 'connectedId' ๋ฐ๊ธ์ ์ต์ด ๊ณ์ ์์ฑ ์์ฒญ์์๋ง ๊ฐ๋ฅํ๋ฉฐ ์ดํ์ ์๋์ ์ ์ ์ธ์ฆ์๋จ ๊ด๋ฆฌ๋ ๊ณ์ ์ถ๊ฐ, ๊ณ์ ์์ , ๊ณ์ ์ญ์ ๊ฑฐ๋๋ฅผ ์ด์ฉํด์ผ ํฉ๋๋ค.
- ์ํ/์นด๋ ์ ๋ฌด์ ๊ฒฝ์ฐ ๋์ผํ ๊ธฐ๊ด์ ๋ฑ๋ก ๊ฐ๋ฅํ ์ธ์ฆ์๋จ์ ๊ฐ์ธ ๊ณ ๊ฐ/๊ธฐ์ ๊ณ ๊ฐ ๊ฐ๊ฐ 1๊ฑด์ ๋๋ค.
- API์๋ฒ๋ฅผ ํฅํ ๋ชจ๋ ์์ฒญ ํ๋ผ๋ฏธํฐ๋ URLEncoder๋ฅผ ํตํด UTF-8๋ก ์ธ์ฝ๋ฉ๋์ด์ผ ํฉ๋๋ค. (ApiRequest.java ์ฐธ์กฐ)
- ๊ณ์ ์์ฑ ์ ํฌํจ๋๋ ๋ชจ๋ ๋น๋ฐ๋ฒํธ๋ API ํธ์ถ ์ ๋ฐ๊ธ๋ publicKey ๋ฅผ ํตํด ์ํธํ ํ ์ ์กํด์ผ ํฉ๋๋ค.
String urlPath = 'https://api.codef.io/v1/account/create';
HashMap<String, Object> bodyMap = new HashMap<String, Object>();
List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
HashMap<String, Object> accountMap1 = new HashMap<String, Object>();
accountMap1.put("countryCode", "KR"); // ๊ตญ๊ฐ์ฝ๋
accountMap1.put("businessType", "BK"); // ์
๋ฌด๊ตฌ๋ถ์ฝ๋
accountMap1.put("clientType", "P"); // ๊ณ ๊ฐ๊ตฌ๋ถ(P: ๊ฐ์ธ, B: ๊ธฐ์
)
accountMap1.put("organization", "0003");// ๊ธฐ๊ด์ฝ๋
accountMap1.put("loginType", "0"); // ๋ก๊ทธ์ธํ์
(0: ์ธ์ฆ์, 1: ID/PW)
String password1 = "์๋์ ์ ์ ์ธ์ฆ์ ๋น๋ฐ๋ฒํธ";
accountMap1.put("password", RSAUtil.encryptRSA(password1, CommonConstant.PUBLIC_KEY)); /** password RSA encrypt */
accountMap1.put("keyFile", "BASE64๋ก Encoding๋ ์๋์ ์ ์ ์ธ์ฆ์ keyํ์ผ ๋ฌธ์์ด");
accountMap1.put("derFile", "BASE64๋ก Encoding๋ ์๋์ ์ ์ ์ธ์ฆ์ derํ์ผ ๋ฌธ์์ด");
list.add(accountMap1);
HashMap<String, Object> accountMap2 = new HashMap<String, Object>();
accountMap2.put("countryCode", "KR");
accountMap2.put("businessType", "BK");
accountMap2.put("clientType", "P");
accountMap2.put("organization", "0004");
accountMap2.put("loginType", "1");
String password2 = "์๋์ ์ ์ ๊ธฐ๊ด ๋ก๊ทธ์ธ ๋น๋ฐ๋ฒํธ";
accountMap1.put("password", RSAUtil.encryptRSA(password2, CommonConstant.PUBLIC_KEY)); /** password RSA encrypt */
accountMap2.put("id", "์๋ ์ ์ ์ ๊ธฐ๊ด ๋ก๊ทธ์ธ ์์ด๋");
accountMap2.put("birthday", "YYMMDD");
list.add(accountMap2);
bodyMap.put("accountList", list);
# CODEF API ํธ์ถ
String result = ApiRequest.reqeust(urlPath, bodyMap);public static String encryptRSA(String plainText, String base64PublicKey)
throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException,
InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
byte[] bytePublicKey = Base64.getDecoder().decode(base64PublicKey);
KeyFactory keyFactory = KeyFactory.getInstance(ENCRYPT_TYPE_RSA);
PublicKey publicKey = keyFactory.generatePublic(new X509EncodedKeySpec(bytePublicKey));
Cipher cipher = Cipher.getInstance(ENCRYPT_TYPE_RSA);
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
byte[] bytePlain = cipher.doFinal(plainText.getBytes());
String encrypted = Base64.getEncoder().encodeToString(bytePlain);
return encrypted;
}{
"result" : {
"code" : "CF-00000",
"extraMessage" : "",
"message" : "์ ์"
},
"data" : {
"successList" : [ {
"clientType" : "P",
"code" : "CF-00000",
"loginType" : "0",
"countryCode" : "KR",
"organization" : "0003",
"businessType" : "BK",
"message" : "์ฑ๊ณต"
}, {
"clientType" : "P",
"code" : "CF-00000",
"loginType" : "1",
"countryCode" : "KR",
"organization" : "0004",
"businessType" : "BK",
"message" : "์ฑ๊ณต"
} ],
"errorList" : [ ],
"connectedId" : "45t4DJOD44M9uwH7zxSgBg"
}
} ๊ณ์ ์์ฑ์ ํตํด ๋ฐ๊ธ๋ฐ์ 'connectedId'์ ์ถ๊ฐ ๊ธฐ๊ด์ ์ธ์ฆ์๋จ์ ๋ฑ๋กํ ์ ์์ต๋๋ค. ์ถ๊ฐ ๋ฑ๋กํ ๊ธฐ๊ด์ ํฌํจํ์ฌ ์ดํ์๋ ๋ณ๋์ ์ธ์ฆ์๋จ ์ ์ก์์ด 'connectedId'๋ฅผ ํตํด์ ๋์๊ธฐ๊ด์ ๋ฐ์ดํฐ๋ฅผ ์ฐ๋ํ ์ ์์ต๋๋ค.
- ์ํ/์นด๋ ์ ๋ฌด์ ๊ฒฝ์ฐ ๋์ผํ ๊ธฐ๊ด์ ๋ฑ๋ก ๊ฐ๋ฅํ ์ธ์ฆ์๋จ์ ๊ฐ์ธ ๊ณ ๊ฐ/๊ธฐ์ ๊ณ ๊ฐ ๊ฐ๊ฐ 1๊ฑด์ ๋๋ค.
- API์๋ฒ๋ฅผ ํฅํ ๋ชจ๋ ์์ฒญ ํ๋ผ๋ฏธํฐ๋ URLEncoder๋ฅผ ํตํด UTF-8๋ก ์ธ์ฝ๋ฉ๋์ด์ผ ํฉ๋๋ค. (ApiRequest.java ์ฐธ์กฐ)
String urlPath = 'https://api.codef.io/v1/account/add';
HashMap<String, Object> bodyMap = new HashMap<String, Object>();
List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
HashMap<String, Object> accountMap1 = new HashMap<String, Object>();
accountMap1.put("countryCode", "KR"); // ๊ตญ๊ฐ์ฝ๋
accountMap1.put("businessType", "BK"); // ์
๋ฌด๊ตฌ๋ถ์ฝ๋
accountMap1.put("clientType", "P"); // ๊ณ ๊ฐ๊ตฌ๋ถ(P: ๊ฐ์ธ, B: ๊ธฐ์
)
accountMap1.put("organization", "0020");// ๊ธฐ๊ด์ฝ๋
accountMap1.put("loginType", "0"); // ๋ก๊ทธ์ธํ์
(0: ์ธ์ฆ์, 1: ID/PW)
String password1 = "์๋์ ์ ์ ์ธ์ฆ์ ๋น๋ฐ๋ฒํธ";
accountMap1.put("password", RSAUtil.encryptRSA(password1, CommonConstant.PUBLIC_KEY)); /** password RSA encrypt */
accountMap1.put("keyFile", "BASE64๋ก Encoding๋ ์๋์ ์ ์ ์ธ์ฆ์ keyํ์ผ ๋ฌธ์์ด");
accountMap1.put("derFile", "BASE64๋ก Encoding๋ ์๋์ ์ ์ ์ธ์ฆ์ derํ์ผ ๋ฌธ์์ด");
list.add(accountMap1);
bodyMap.put("accountList", list);
String connectedId = "์๋์ ์ ์ ์ํ/์นด๋์ฌ ๊ณ์ ๋ฑ๋ก ํ ๋ฐ๊ธ๋ฐ์ ์ปค๋ฅํฐ๋์์ด๋ ์
๋ ฅ";
bodyMap.put(CommonConstant.connectedId, connectedId);
# CODEF API ํธ์ถ
String result = ApiRequest.reqeust(urlPath, bodyMap);{
"result" : {
"code" : "CF-00000",
"extraMessage" : "",
"message" : "์ ์"
},
"data" : {
"successList" : [ {
"clientType" : "P",
"code" : "CF-00000",
"loginType" : "0",
"countryCode" : "KR",
"organization" : "0020",
"businessType" : "BK",
"message" : "์ฑ๊ณต"
} ],
"errorList" : [ ],
"connectedId" : "45t4DJOD44M9uwH7zxSgBg"
}
}๊ณ์ ์์ฑ์ ํตํด ๋ฐ๊ธ๋ฐ์ 'connectedId'์ ๋ฑ๋ก๋ ๊ธฐ๊ด์ ์ธ์ฆ์๋จ์ ๋ณ๊ฒฝํ ์ ์์ต๋๋ค. ๋ณ๊ฒฝ ์์ฒญํ ๊ธฐ๊ด์ ์ธ์ฆ ์๋จ์ ํธ์ถ ์ฆ์ ๋ณ๊ฒฝ๋๋ฉฐ, ์ด ํ 'connectedId'๋ฅผ ํตํด์ ๋์๊ธฐ๊ด์ ๋ฐ์ดํฐ๋ฅผ ์ฐ๋ํ ์ ์์ต๋๋ค.
- API์๋ฒ๋ฅผ ํฅํ ๋ชจ๋ ์์ฒญ ํ๋ผ๋ฏธํฐ๋ URLEncoder๋ฅผ ํตํด UTF-8๋ก ์ธ์ฝ๋ฉ๋์ด์ผ ํฉ๋๋ค. (ApiRequest.java ์ฐธ์กฐ)
String urlPath = 'https://api.codef.io/v1/account/update';
HashMap<String, Object> bodyMap = new HashMap<String, Object>();
List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
HashMap<String, Object> accountMap1 = new HashMap<String, Object>();
accountMap1.put("countryCode", "KR"); // ๊ตญ๊ฐ์ฝ๋
accountMap1.put("businessType", "BK"); // ์
๋ฌด๊ตฌ๋ถ์ฝ๋
accountMap1.put("clientType", "P"); // ๊ณ ๊ฐ๊ตฌ๋ถ(P: ๊ฐ์ธ, B: ๊ธฐ์
)
accountMap1.put("organization", "0020");// ๊ธฐ๊ด์ฝ๋
accountMap1.put("loginType", "0"); // ๋ก๊ทธ์ธํ์
(0: ์ธ์ฆ์, 1: ID/PW)
String password1 = "์๋์ ์ ์ ์ธ์ฆ์ ๋น๋ฐ๋ฒํธ";
accountMap1.put("password", RSAUtil.encryptRSA(password1, CommonConstant.PUBLIC_KEY)); /** password RSA encrypt */
accountMap1.put("keyFile", "BASE64๋ก Encoding๋ ์๋์ ์ ์ ์ธ์ฆ์ keyํ์ผ ๋ฌธ์์ด");
accountMap1.put("derFile", "BASE64๋ก Encoding๋ ์๋์ ์ ์ ์ธ์ฆ์ derํ์ผ ๋ฌธ์์ด");
list.add(accountMap1);
bodyMap.put("accountList", list);
String connectedId = "์๋์ ์ ์ ์ํ/์นด๋์ฌ ๊ณ์ ๋ฑ๋ก ํ ๋ฐ๊ธ๋ฐ์ ์ปค๋ฅํฐ๋์์ด๋ ์
๋ ฅ";
bodyMap.put(CommonConstant.connectedId, connectedId);
# CODEF API ํธ์ถ
String result = ApiRequest.reqeust(urlPath, bodyMap);{
"result" : {
"code" : "CF-00000",
"extraMessage" : "",
"message" : "์ ์"
},
"data" : {
"successList" : [ {
"clientType" : "P",
"code" : "CF-00000",
"loginType" : "0",
"countryCode" : "KR",
"organization" : "0020",
"businessType" : "BK",
"message" : "์ฑ๊ณต"
} ],
"errorList" : [ ],
"connectedId" : "45t4DJOD44M9uwH7zxSgBg"
}
}์๋์ ์ ๊ฐ ๋ฑ๋ก๋ ๊ณ์ ์ ์ญ์ ๋ฅผ ์์ฒญ ์ 'connectedId'์ ๋ฑ๋ก๋ ๊ธฐ๊ด์ ์ธ์ฆ์๋จ์ ์ฆ์ ์ญ์ ํ ์ ์์ต๋๋ค. ์์ฒญํ ๊ธฐ๊ด์ ์ธ์ฆ ์๋จ์ ํธ์ถ ์ฆ์ ์ญ์ ๋๋ฉฐ, ํด๋น ๋ฐ์ดํฐ๋ ๋ณต๊ตฌํ ์ ์์ต๋๋ค.
- API์๋ฒ๋ฅผ ํฅํ ๋ชจ๋ ์์ฒญ ํ๋ผ๋ฏธํฐ๋ URLEncoder๋ฅผ ํตํด UTF-8๋ก ์ธ์ฝ๋ฉ๋์ด์ผ ํฉ๋๋ค. (ApiRequest.java ์ฐธ์กฐ)
String urlPath = 'https://api.codef.io/v1/account/delete';
HashMap<String, Object> bodyMap = new HashMap<String, Object>();
List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
HashMap<String, Object> accountMap1 = new HashMap<String, Object>();
accountMap1.put("countryCode", "KR"); // ๊ตญ๊ฐ์ฝ๋
accountMap1.put("businessType", "BK"); // ์
๋ฌด๊ตฌ๋ถ์ฝ๋
accountMap1.put("clientType", "P"); // ๊ณ ๊ฐ๊ตฌ๋ถ(P: ๊ฐ์ธ, B: ๊ธฐ์
)
accountMap1.put("organization", "0020");// ๊ธฐ๊ด์ฝ๋
accountMap1.put("loginType", "0"); // ๋ก๊ทธ์ธํ์
(0: ์ธ์ฆ์, 1: ID/PW)
list.add(accountMap1);
bodyMap.put("accountList", list);
String connectedId = "์๋์ ์ ์ ์ํ/์นด๋์ฌ ๊ณ์ ๋ฑ๋ก ํ ๋ฐ๊ธ๋ฐ์ ์ปค๋ฅํฐ๋์์ด๋ ์
๋ ฅ";
bodyMap.put(CommonConstant.CONNECTED_ID, connectedId);
# CODEF API ํธ์ถ
String result = ApiRequest.reqeust(urlPath, bodyMap);{
"result" : {
"code" : "CF-00000",
"extraMessage" : "",
"message" : "์ ์"
},
"data" : {
"successList" : [ {
"clientType" : "P",
"loginType" : "0",
"countryCode" : "KR",
"organization" : "0020",
"businessType" : "BK"
} ],
"connectedId" : "45t4DJOD44M9uwH7zxSgBg"
}
}๊ณ์ ๋ฑ๋ก, ์ถ๊ฐ ๋ฑ์ ํตํด CODEF์ ๋ฑ๋ก๋ ์๋ ์ ์ ์ ์ธ์ฆ์๋จ ์ ๋ณด ๋ชฉ๋ก์ ๋ํ ์กฐํ๋ฅผ ์์ฒญํ ์ ์์ต๋๋ค. ์๋์ ์ ์ ๋ํ ์ ๋ํฌํ ์๋ณ๊ฐ์ธ 'connectedId'๋ฅผ ์์ฒญ ํ๋ผ๋ฏธํฐ๋ก ์ฌ์ฉํ๋ฉฐ ํด๋น 'connectedId'์ ์ฐ๊ฒฐ๋ ์ธ์ฆ์๋จ ์ ๋ณด ๋ชฉ๋ก์ ๋ฐํํฉ๋๋ค.
- API์๋ฒ๋ฅผ ํฅํ ๋ชจ๋ ์์ฒญ ํ๋ผ๋ฏธํฐ๋ URLEncoder๋ฅผ ํตํด UTF-8๋ก ์ธ์ฝ๋ฉ๋์ด์ผ ํฉ๋๋ค. (ApiRequest.java ์ฐธ์กฐ)
String urlPath = 'https://api.codef.io/v1/account/list';
HashMap<String, Object> bodyMap = new HashMap<String, Object>();
String connectedId = "์๋์ ์ ์ ์ํ/์นด๋์ฌ ๊ณ์ ๋ฑ๋ก ํ ๋ฐ๊ธ๋ฐ์ ์ปค๋ฅํฐ๋์์ด๋ ์
๋ ฅ";
bodyMap.put(CommonConstant.CONNECTED_ID, connectedId);
# CODEF API ํธ์ถ
String result = ApiRequest.reqeust(urlPath, bodyMap);{
"result" : {
"code" : "CF-00000",
"extraMessage" : "",
"message" : "์ฑ๊ณต"
},
"data" : {
"accountList" : [ {
"clientType" : "B",
"organizationCode" : "0003",
"loginType" : "0",
"countryCode" : "KR",
"businessType" : "BK"
}, {
"clientType" : "B",
"organizationCode" : "0004",
"loginType" : "0",
"countryCode" : "KR",
"businessType" : "BK"
}, {
"clientType" : "P",
"organizationCode" : "0004",
"loginType" : "0",
"countryCode" : "KR",
"businessType" : "BK"
}, {
"clientType" : "B",
"organizationCode" : "0011",
"loginType" : "0",
"countryCode" : "KR",
"businessType" : "BK"
}, {
"clientType" : "P",
"organizationCode" : "0020",
"loginType" : "1",
"countryCode" : "KR",
"businessType" : "BK"
}, {
"clientType" : "B",
"organizationCode" : "0301",
"loginType" : "0",
"countryCode" : "KR",
"businessType" : "CD"
}, {
"clientType" : "P",
"organizationCode" : "0302",
"loginType" : "0",
"countryCode" : "KR",
"businessType" : "CD"
}, {
"clientType" : "B",
"organizationCode" : "0309",
"loginType" : "0",
"countryCode" : "KR",
"businessType" : "CD"
}, {
"clientType" : "P",
"organizationCode" : "0309",
"loginType" : "0",
"countryCode" : "KR",
"businessType" : "CD"
} ],
"connectedId" : "bybF-S85kX998Trh23JUVb"
}
}CODEF๋ก๋ถํฐ ๋ฐ๊ธ๋ 'connectedId'์ ๋ชฉ๋ก์ ๋ํ ์กฐํ๋ฅผ ์์ฒญํ ์ ์์ต๋๋ค. ์์ฒญ ๊ฒฐ๊ณผ๋ ํ์ด์ง(5๋ง๊ฑด) ๋จ์๋ก ์ ์ก๋๋ฉฐ ๊ฒฐ๊ณผ ๊ฐ(hasNext == true)์ ๋ฐ๋ผ ๋ค์ ํ์ด์ง(nextPageNo)์ ๋ํ ์์ฒญ์ด ๊ฐ๋ฅํฉ๋๋ค.
- API์๋ฒ๋ฅผ ํฅํ ๋ชจ๋ ์์ฒญ ํ๋ผ๋ฏธํฐ๋ URLEncoder๋ฅผ ํตํด UTF-8๋ก ์ธ์ฝ๋ฉ๋์ด์ผ ํฉ๋๋ค. (ApiRequest.java ์ฐธ์กฐ)
String urlPath = 'https://api.codef.io/v1/account/connectedId-list';
HashMap<String, Object> bodyMap = new HashMap<String, Object>();
bodyMap.put(CommonConstant.PAGE_NO, 0); // ํ์ด์ง ๋ฒํธ. ์๋ต์ 1ํ์ด์ง ๊ฐ(0)์ผ๋ก ์ค์
# CODEF API ํธ์ถ
String result = ApiRequest.reqeust(urlPath, bodyMap);{
"result" : {
"code" : "CF-00000",
"extraMessage" : "",
"message" : "์ฑ๊ณต"
},
"data" : {
"connectedIdList" : [ "6OOOZ58zAU.aX0pRRgzEBk", "bybF-S85kX998Trh23JUVb" ],
"pageNo" : 0,
"hasNext" : true,
"nextPageNo" : 1
}
}๋ฐ๊ธ๋ฐ์ 'connectedId' ๋ฅผ ํตํด ๋ฑ๋ก๋ ๊ธฐ๊ด์ ๋ณด์ ๊ณ์ข๋ฅผ ์กฐํํ ์ ์์ต๋๋ค.
- API์๋ฒ๋ฅผ ํฅํ ๋ชจ๋ ์์ฒญ ํ๋ผ๋ฏธํฐ๋ URLEncoder๋ฅผ ํตํด UTF-8๋ก ์ธ์ฝ๋ฉ๋์ด์ผ ํฉ๋๋ค. (ApiRequest.java ์ฐธ์กฐ)
TestKR_BK_1_B_001.java
// ์์ฒญ URL ์ค์
String urlPath = CommonConstant.API_DOMAIN + CommonConstant.KR_BK_1_B_001;
// ์์ฒญ ํ๋ผ๋ฏธํฐ ์ค์ ์์
HashMap<String, Object> bodyMap = new HashMap<String, Object>();
bodyMap.put("connectedId", "9LUm.uhVQbzaangazwI0tr"); // ์๋์ ์ ์ ์ํ/์นด๋์ฌ ๊ณ์ ๋ฑ๋ก ํ ๋ฐ๊ธ๋ฐ์ ์ปค๋ฅํฐ๋์์ด๋ ์์
bodyMap.put("organization", "๊ธฐ๊ด์ฝ๋");
// ์์ฒญ ํ๋ผ๋ฏธํฐ ์ค์ ์ข
๋ฃ
// API ์์ฒญ
String result = ApiRequest.reqeust(urlPath, bodyMap);
// ์๋ต๊ฒฐ๊ณผ ํ์ธ
System.out.println(result);{
"result": {
"code": "CF-00000",
"extraMessage": "",
"message": "์ฑ๊ณต",
"transactionId": "aedb0cade44f44e48a5f3181c2fe9a96"
},
"data": {
"resAccountEndDate": "",
"resLoanLimitAmt": "",
"resWithdrawalAmt": "19615",
"resAccount": "05300000004040",
"resAccountStatus": "ํ๋",
"resLoanEndDate": "",
"commEndDate": "20190630",
"resInterestRate": "",
"resAccountName": "OO๊ธฐ์
์์ ์๊ธ",
"resAccountStartDate": "20130605",
"resAccountCurrency": "KRW",
"resAccountBalance": "19615",
"commStartDate": "20190401",
"resTrHistoryList": [
{
"resAccountTrTime": "095900",
"resAccountDesc4": "",
"resAccountDesc3": "๏ฝ๏ฝ๏ฝ๏ผฟ์ค์ ",
"resAccountDesc2": "์ธํฐ๋ท",
"resAccountDesc1": "๏ผ์ฃผ๏ผOO",
"resAccountTrDate": "20190628",
"resAccountOut": "1",
"resAfterTranBalance": "13634",
"resAccountIn": "0"
},
{
"resAccountTrTime": "174603",
"resAccountDesc4": "",
"resAccountDesc3": "rnd_์
๊ธํ์1",
"resAccountDesc2": "ํํ์ด์ฒด",
"resAccountDesc1": "OO๏ผ์ฃผ๏ผ",
"resAccountTrDate": "20190627",
"resAccountOut": "0",
"resAfterTranBalance": "13635",
"resAccountIn": "1"
},
{
"resAccountTrTime": "164618",
"resAccountDesc4": "",
"resAccountDesc3": "rnd_์
๊ธํ์1",
"resAccountDesc2": "ํํ์ด์ฒด",
"resAccountDesc1": "OO๏ผ์ฃผ๏ผ",
"resAccountTrDate": "20190627",
"resAccountOut": "0",
"resAfterTranBalance": "13634",
"resAccountIn": "1"
},
{
"resAccountTrTime": "092130",
"resAccountDesc4": "",
"resAccountDesc3": "๏ฝ๏ฝ๏ฝ๏ผฟ์ค์ ",
"resAccountDesc2": "์ธํฐ๋ท",
"resAccountDesc1": "๏ผ์ฃผ๏ผOO",
"resAccountTrDate": "20190627",
"resAccountOut": "1",
"resAfterTranBalance": "13633",
"resAccountIn": "0"
}
],
"resAccountHolder": "(์ฃผ)OO",
"resManagementBranch": "(0044)๋ถ์ํ๋",
"resLastTranDate": "20190711"
}
}CODEF API ์ค๋ฅ๋ HTTP status code ์ CODEF API ErrorCode๋ก ๋ถ๋ฅํฉ๋๋ค.
HTTP 401 - OAuth2.0 ํ ํฐ ๋ง๋ฃ
{"error":"invalid_token","error_description":"Cannot convert access token to JSON","code":"CF-99997","message":"OAUTH2.0 ํ ํฐ ์๋ฌ์
๋๋ค. ๋ฉ์์ง๋ฅผ ํ์ธํ์ธ์."}๊ทธ ์ธ ์ค๋ฅ HTTP 200 - CODEF ์ค๋ฅ ๋ณํ(CF-XXXXX)
{"result":{"code":"CF-94002","extraMessage":"","message":"์ฌ์ฉ์ ๊ณ์ ์ ๋ณด ์ค์ ์ ์คํจํ์ต๋๋ค."},"data":{}}CODEF API์ ๋ณ๊ฒฝ๋ด์ CHANGELOG.md ์ ํตํด ํ์ธํ ์ ์์ต๋๋ค.
This project is licensed under the MIT License - see the LICENSE file for details