Skip to content

codef-io/codef-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

64 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

CODEF API - Java

Java sample for CODEF API

Documentation

๋ณธ ์ƒ˜ํ”Œ์€ CODEF API์˜ ์—ฐ๋™์„ ์œ„ํ•œ ๊ณตํ†ต ์ฝ”๋“œ๋ฅผ ํฌํ•จํ•˜๊ณ  ์žˆ์œผ๋ฉฐ, ์ง€์›ํ•˜๋Š” ๋ชจ๋“  API์˜ ์—”๋“œํฌ์ธํŠธ(์€ํ–‰, ์นด๋“œ, ๋ณดํ—˜, ์ฆ๊ถŒ, ๊ณต๊ณต, ๊ธฐํƒ€)๋Š” https://developer.codef.io ๋ฅผ ํ†ตํ•ด ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

CODEF API Env

CODEF API๋Š” ์›ํ™œํ•œ ๊ฐœ๋ฐœ์„ ์œ„ํ•ด ์ƒŒ๋“œ๋ฐ•์Šค, ๊ฐœ๋ฐœ, ์šด์˜ ํ™˜๊ฒฝ์„ ๊ฐ๊ฐ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

Getting Started

OAuth2.0

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"
  }
}

'connectedId' ๋ชฉ๋ก ์กฐํšŒ

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
  }
}

CODEF API(๋ฒ•์ธ ๋ณด์œ ๊ณ„์ขŒ์กฐํšŒ)

๋ฐœ๊ธ‰๋ฐ›์€ '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":{}}

Change Log

CODEF API์˜ ๋ณ€๊ฒฝ๋‚ด์„ CHANGELOG.md ์„ ํ†ตํ•ด ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

License

This project is licensed under the MIT License - see the LICENSE file for details

Releases

Packages

Used by

Contributors

Languages