Python 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 ์ฌ์๋]
token_url = 'https://oauth.codef.io/oauth/token'
response_oauth = request_token(token_url, 'CODEF๋ก๋ถํฐ ๋ฐ๊ธ๋ฐ์ ํด๋ผ์ด์ธํธ ์์ด๋', 'CODEF๋ก๋ถํฐ ๋ฐ๊ธ๋ฐ์ ์ํฌ๋ฆฟ ํค')
if response_oauth.status_code == 200:
dict = json.loads(response_oauth.text)
# reissue_token
token = dict['access_token']
print('access_token = ' + token)
else:
print('ํ ํฐ๋ฐ๊ธ ์ค๋ฅ'){
"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
}> pip3 install pycrypto
> pip3 install urllib
> pip3 ...CODEF API๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์๋ ์๋์ ์ ๊ฐ ์ฌ์ฉํ๋ ๋์๊ธฐ๊ด์ ์ธ์ฆ์๋จ ๋ฑ๋ก์ด ํ์ํ๋ฉฐ, ์ด๋ฅผ ํตํด ์ฌ์ฉ์๋ง๋ค ์ ๋ํฌํ 'connectedId'๋ฅผ ๋ฐ๊ธ๋ฐ์ ์ ์์ต๋๋ค. ์ดํ์๋ ๋ณ๋์ ์ธ์ฆ์๋จ ์ ์ก ์์ด 'connectedId'๋ฅผ ํตํด์ ๋์๊ธฐ๊ด์ ๋ฐ์ดํฐ๋ฅผ ์ฐ๋ํ ์ ์์ต๋๋ค. 'connectedId' ๋ฐ๊ธ์ ์ต์ด ๊ณ์ ์์ฑ ์์ฒญ์์๋ง ๊ฐ๋ฅํ๋ฉฐ ์ดํ์ ์๋์ ์ ์ ์ธ์ฆ์๋จ ๊ด๋ฆฌ๋ ๊ณ์ ์ถ๊ฐ, ๊ณ์ ์์ , ๊ณ์ ์ญ์ ๊ฑฐ๋๋ฅผ ์ด์ฉํด์ผ ํฉ๋๋ค.
- ์ํ/์นด๋ ์ ๋ฌด์ ๊ฒฝ์ฐ ๋์ผํ ๊ธฐ๊ด์ ๋ฑ๋ก ๊ฐ๋ฅํ ์ธ์ฆ์๋จ์ ๊ฐ์ธ ๊ณ ๊ฐ/๊ธฐ์ ๊ณ ๊ฐ ๊ฐ๊ฐ 1๊ฑด์ ๋๋ค.
- API์๋ฒ๋ฅผ ํฅํ ๋ชจ๋ ์์ฒญ ํ๋ผ๋ฏธํฐ๋ URLEncoder๋ฅผ ํตํด UTF-8๋ก ์ธ์ฝ๋ฉ๋์ด์ผ ํฉ๋๋ค. (RegisterAccount.py ์ฐธ์กฐ)
- ๊ณ์ ์์ฑ ์ ํฌํจ๋๋ ๋ชจ๋ ๋น๋ฐ๋ฒํธ๋ API ํธ์ถ ์ ๋ฐ๊ธ๋ publicKey ๋ฅผ ํตํด ์ํธํ ํ ์ ์กํด์ผ ํฉ๋๋ค.
codef_account_create_url = 'https://api.codef.io/v1/account/create'
codef_account_create_body = {
'accountList':[ # ๊ณ์ ๋ชฉ๋ก
{
'countryCode':'KR', # ๊ตญ๊ฐ์ฝ๋
'businessType':'BK', # ๋น์ฆ๋์ค ๊ตฌ๋ถ
'clientType':'P', # ๊ณ ๊ฐ๊ตฌ๋ถ(P: ๊ฐ์ธ, B: ๊ธฐ์
)
'organization':'0003', # ๊ธฐ๊ด์ฝ๋
'loginType':'0', # ๋ก๊ทธ์ธํ์
(0: ์ธ์ฆ์, 1: ID/PW)
'password':publicEncRSA(pubKey, '1234'), # ์๋์ ์ ์ ์ธ์ฆ์ ๋น๋ฐ๋ฒํธ ์
๋ ฅ
'derFile':'MIIF...', # ์๋์ ์ ์ ์ธ์ฆ์ ์ธ์ฆ์ DerFile
'keyFile':'MIIF...' # ์๋์ ์ ์ ์ธ์ฆ์ ์ธ์ฆ์ KeyFile
},
{
'countryCode':'KR', # ๊ตญ๊ฐ์ฝ๋
'businessType':'BK', # ๋น์ฆ๋์ค ๊ตฌ๋ถ
'clientType':'P', # ๊ณ ๊ฐ๊ตฌ๋ถ(P: ๊ฐ์ธ, B: ๊ธฐ์
)
'organization':'0004', # ๊ธฐ๊ด์ฝ๋
'loginType':'0', # ๋ก๊ทธ์ธํ์
(0: ์ธ์ฆ์, 1: ID/PW)
'password':publicEncRSA(pubKey, '1234'), # ์๋์ ์ ์ ์ธ์ฆ์ ๋น๋ฐ๋ฒํธ ์
๋ ฅ
'derFile':'MIIF...', # ์๋์ ์ ์ ์ธ์ฆ์ ์ธ์ฆ์ DerFile
'keyFile':'MIIF...' # ์๋์ ์ ์ ์ธ์ฆ์ ์ธ์ฆ์ KeyFile
}
]
}
# CODEF API ํธ์ถ
response_account_create = http_sender(codef_account_create_url, token, codef_account_create_body)import base64
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5 as Cipher_PKCS1_v1_5
def publicEncRSA(publicKey, data):
keyDER = base64.b64decode(pubKey)
keyPub = RSA.importKey(keyDER)
cipher = Cipher_PKCS1_v1_5.new(keyPub)
cipher_text = cipher.encrypt(data.encode())
encryptedData = base64.b64encode(cipher_text)
print('encryptedData = ' + encryptedData)
return encryptedData{
"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๋ก ์ธ์ฝ๋ฉ๋์ด์ผ ํฉ๋๋ค. (RegisterAccount.py ์ฐธ์กฐ)
codef_account_add_url = 'https://api.codef.io/v1/account/add'
codef_account_add_body = {
'connectedId': '์๋์ ์ ์ ์ํ/์นด๋์ฌ ๊ณ์ ๋ฑ๋ก ํ ๋ฐ๊ธ๋ฐ์ ์ปค๋ฅํฐ๋์์ด๋ ์
๋ ฅ', # connectedId
'accountList':[ # ๊ณ์ ๋ชฉ๋ก
{
'countryCode':'KR', # ๊ตญ๊ฐ์ฝ๋
'businessType':'BK', # ๋น์ฆ๋์ค ๊ตฌ๋ถ
'clientType':'P', # ๊ณ ๊ฐ๊ตฌ๋ถ(P: ๊ฐ์ธ, B: ๊ธฐ์
)
'organization':'0020', # ๊ธฐ๊ด์ฝ๋
'loginType':'0', # ๋ก๊ทธ์ธํ์
(0: ์ธ์ฆ์, 1: ID/PW)
'password':publicEncRSA(pubKey, '1234'), # ์๋์ ์ ์ ์ธ์ฆ์ ๋น๋ฐ๋ฒํธ ์
๋ ฅ
'derFile':'MIIF...', # ์๋์ ์ ์ ์ธ์ฆ์ ์ธ์ฆ์ DerFile
'keyFile':'MIIF...' # ์๋์ ์ ์ ์ธ์ฆ์ ์ธ์ฆ์ KeyFile
}
]
}
# CODEF API ํธ์ถ
response_account_add = http_sender(codef_account_add_url, token, codef_account_add_body){
"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๋ก ์ธ์ฝ๋ฉ๋์ด์ผ ํฉ๋๋ค. (RegisterAccount.py ์ฐธ์กฐ)
codef_account_update_url = 'https://api.codef.io/v1/account/update'
codef_account_update_body = {
'connectedId': '๊ณ์ ์์ฑ ์ ๋ฐ๊ธ๋ฐ์ ์์ด๋', # connectedId
'accountList':[ # ๊ณ์ ๋ชฉ๋ก
{
'countryCode':'KR', # ๊ตญ๊ฐ์ฝ๋
'businessType':'BK', # ๋น์ฆ๋์ค ๊ตฌ๋ถ
'clientType':'P', # ๊ณ ๊ฐ๊ตฌ๋ถ(P: ๊ฐ์ธ, B: ๊ธฐ์
)
'organization':'0020', # ๊ธฐ๊ด์ฝ๋
'loginType':'0', # ๋ก๊ทธ์ธํ์
(0: ์ธ์ฆ์, 1: ID/PW)
'password':publicEncRSA(pubKey, '1234'), # ์๋์ ์ ์ ์ธ์ฆ์ ๋น๋ฐ๋ฒํธ ์
๋ ฅ
'derFile':'์ธ์ฆ์ DerFile', # Base64String
'keyFile':'์ธ์ฆ์ KeyFile' # Base64String
}
]
}
# CODEF API ํธ์ถ
response_account_update = http_sender(codef_account_update_url, token, codef_account_update_body){
"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๋ก ์ธ์ฝ๋ฉ๋์ด์ผ ํฉ๋๋ค. (RegisterAccount.py ์ฐธ์กฐ)
codef_account_delete_url = 'https://api.codef.io/v1/account/delete'
codef_account_delete_body = {
'connectedId': '๊ณ์ ์์ฑ ์ ๋ฐ๊ธ๋ฐ์ ์์ด๋', # connectedId
'accountList':[ # ๊ณ์ ๋ชฉ๋ก
{
'countryCode':'KR', # ๊ตญ๊ฐ์ฝ๋
'businessType':'BK', # ๋น์ฆ๋์ค ๊ตฌ๋ถ
'clientType':'P', # ๊ณ ๊ฐ๊ตฌ๋ถ(P: ๊ฐ์ธ, B: ๊ธฐ์
)
'organization':'0020', # ๊ธฐ๊ด์ฝ๋
'loginType':'0', # ๋ก๊ทธ์ธํ์
(0: ์ธ์ฆ์, 1: ID/PW)
}
]
}
# CODEF API ํธ์ถ
response_account_delete = http_sender(codef_account_delete_url, token, codef_account_delete_body){
"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๋ก ์ธ์ฝ๋ฉ๋์ด์ผ ํฉ๋๋ค. (AccountList.py ์ฐธ์กฐ)
codef_account_list_url = 'https://api.codef.io/v1/account/list'
codef_account_list_body = {
'connectedId':connectedId # ์๋์ ์ ์ ์ํ/์นด๋์ฌ ๊ณ์ ๋ฑ๋ก ํ ๋ฐ๊ธ๋ฐ์ ์ปค๋ฅํฐ๋์์ด๋ ์์
}
# CODEF API ํธ์ถ
response_account_list = http_sender(codef_account_list_url, token, codef_account_list_body){
"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๋ก ์ธ์ฝ๋ฉ๋์ด์ผ ํฉ๋๋ค. (ConnectedIdList.py ์ฐธ์กฐ)
codef_connectedId_list_url = 'https://api.codef.io/v1/account/connectedId-list'
codef_connectedId_list_body = {
'pageNo':'5' # ํ์ด์ง ๋ฒํธ(์๋ต ๊ฐ๋ฅ) ์๋ต์ 1ํ์ด์ง ๊ฐ(0) ์๋ ์ค์
}
# CODEF API ํธ์ถ
response_connectedId_list = http_sender(codef_connectedId_list_url, token, codef_connectedId_list_body){
"result" : {
"code" : "CF-00000",
"extraMessage" : "",
"message" : "์ฑ๊ณต"
},
"data" : {
"connectedIdList" : [ "6OOOZ58zAU.aX0pRRgzEBk", "bybF-S85kX998Trh23JUVb" ],
"pageNo" : 0,
"hasNext" : true,
"nextPageNo" : 1
}
}๋ฐ๊ธ๋ฐ์ 'connectedId' ๋ฅผ ํตํด ๋ฑ๋ก๋ ๊ธฐ๊ด์ ๋ณด์ ๊ณ์ข๋ฅผ ์กฐํํ ์ ์์ต๋๋ค.
- API์๋ฒ๋ฅผ ํฅํ ๋ชจ๋ ์์ฒญ ํ๋ผ๋ฏธํฐ๋ URLEncoder๋ฅผ ํตํด UTF-8๋ก ์ธ์ฝ๋ฉ๋์ด์ผ ํฉ๋๋ค. (TestKR_BK_1_B_001.py ์ฐธ์กฐ)
TestKR_BK_1_B_001.py
# CodefURL
codef_url = 'https://api.codef.io'
token_url = 'https://api.codef.io/oauth/token'
# ์ํ ๋ฒ์ธ ๋ณด์ ๊ณ์ข
account_list_path = '/v1/kr/bank/b/account/list'
# ๊ธฐ ๋ฐ๊ธ๋ ํ ํฐ
token ='' #access_token
# BodyData
body = {
'connectedId':'9LUm.uhVQbzaangazwI0tr',
'organization':'0011'
}
# CODEF API ์์ฒญ
response_codef_api = http_sender(codef_url + account_list_path, token, body)
# token error
if response_codef_api.status_code == 401:
dict = json.loads(response_codef_api.text)
# invalid_token
print('error = ' + dict['error'])
# Cannot convert access token to JSON
print('error_description = ' + dict['error_description'])
# reissue token
response_oauth = request_token(token_url, 'CODEF๋ก๋ถํฐ ๋ฐ๊ธ๋ฐ์ ํด๋ผ์ด์ธํธ ์์ด๋', 'CODEF๋ก๋ถํฐ ๋ฐ๊ธ๋ฐ์ ์ํฌ๋ฆฟ ํค');
if response_oauth.status_code == 200:
dict = json.loads(response_oauth.text)
# reissue_token
token = dict['access_token']
print('access_token = ' + token)
# request codef_api
response = http_sender(codef_url + account_list_path, token, body)
# codef_api ์๋ต ๊ฒฐ๊ณผ
print(response.status_code)
print(response.text)
else:
print('ํ ํฐ๋ฐ๊ธ ์ค๋ฅ')
else:
print('์ ์์ฒ๋ฆฌ'){
"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