> For the complete documentation index, see [llms.txt](https://docs.contiple.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.contiple.com/api/open-api/data-connection.md).

# 고객 정보 연동

***

## **➊ API 인증 방법**

### **1-1. 암호화 키 (Security Key)**

* \[고객정보관리] → \[고객정보연동] → \[API 설정]에서 API 암호화 여부를 예로 설정합니다.
* 암호화 키가 자동 생성되며, 해당 키를 API 인증에 활용할 수 있습니다.

***

### **1-2. Authorization 문자열 생성 방법**

> 다음2가지 방법으로 문자열을 생성할 수 있습니다.

#### **① HmacSHA256로 암호화**

#### **② (request URI + 파라미터 값(json) + 현재 UTC시간 값)문자열에 대해 암호화**

* **Java 예시**

```java
String token= request.getHeader("Authorization");
String time = request.getHeader("X-TC-Timestamp");
if (!StringUtils.isNumeric(time)) {
    logger.error("X-TC-Timestamp is not numeric: " + time);
    throw new Exception("error.bad_request");
}
DateTime date = null;
date = new DateTime(Long.parseLong(time));
if (date.minusMinutes(5).isAfterNow() || date.plusMinutes(5).isBeforeNow()) {
    logger.error("X-TC-Timestamp is expired: " + time + ", now timestamp: " + Calendar.getInstance().getTimeInMillis());
    throw new Exception("error.bad_request");
}

String apiKey = "bf7769e5321448de88838cdb";
String content= new String(IOUtils.toByteArray(request.getInputStream()), StandardCharsets.UTF_8) + time;

SecretKeySpec signingKey = new SecretKeySpec(apiKey.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
Mac mac = Mac.getInstance(signingKey.getAlgorithm());
mac.init(signingKey);
byte[] rawHmac = mac.doFinal(content.getBytes(StandardCharsets.UTF_8));
String localAuthorization = new String(Base64.encodeBase64(rawHmac));
logger.debug("Local token: " + localAuthorization);
if (StringUtils.equals(token, localAuthorization)) {
    return true;
}  else {
        logger.info("Local sha2 token: " + localAuthorization);
        return false;
    }
}
```

***

## **➋ 고객정보연동 API**

**(1) 인터페이스 설명**

| 인터페이스 명    | 프로토콜  | 호출방향 | 인코딩   | 요청 파라미터 형식 | URL    | 접근제한 여부 |
| ---------- | ----- | ---- | ----- | ---------- | ------ | ------- |
| 고객정보연동 API | HTTPS | POST | UTF-8 | JSON       | 기본 URL | 공통 인증   |

***

#### **(2) 요청 파라미터 정의**

| 명칭        | 변수      | 데이터 타입 | 필수 | 설명 |
| --------- | ------- | ------ | -- | -- |
| 설정한 조회 항목 | callNum | String | O  |    |
|           | nation  | String |    |    |

***

#### **(3) Request Body**

```json
{ 
  "callNum":"1",
  "nation":"korea"
}
```

***

#### **(4) 결과 데이터**

<table><thead><tr><th width="213">명칭</th><th width="160">변수</th><th width="148">데이터 타입</th><th>필수</th><th>설명</th></tr></thead><tbody><tr><td>설정한 결과 항목</td><td>userName</td><td>String</td><td></td><td></td></tr><tr><td></td><td>id</td><td>String</td><td></td><td></td></tr></tbody></table>

***

#### **(5) Response Body**

```json
{
  "data": {
    "userName": "test",
    "id": "testId"
    }
}
```

***

## **➌ 리턴 결과**

**(1) 파라미터 정의**

<table><thead><tr><th width="175">명칭</th><th width="217">변수</th><th width="141">데이터 타입</th><th width="94">필수</th><th>설명</th></tr></thead><tbody><tr><td><strong>성공 시 리턴 결과</strong></td><td>data</td><td>JSON</td><td>O</td><td></td></tr><tr><td></td><td>OC에서의 결과 항목 설정값</td><td>String</td><td>O</td><td></td></tr></tbody></table>

<table><thead><tr><th width="175">명칭</th><th width="141">변수</th><th width="180">데이터 타입</th><th width="132">필수</th><th>설명</th></tr></thead><tbody><tr><td><strong>실패 시 리턴 결과</strong></td><td>error</td><td>JSON</td><td>O</td><td></td></tr><tr><td></td><td>code</td><td>String</td><td>O</td><td></td></tr><tr><td></td><td>message</td><td>String</td><td>O</td><td></td></tr><tr><td></td><td>detail</td><td>String</td><td>O</td><td></td></tr></tbody></table>

***

**(2) HTTP 상태 코드**

| 리턴 코드 정보             | Online Contact 표시 메시지 |
| -------------------- | --------------------- |
| 200 : SUCCESS        | 조회 성공                 |
| 400 : Bad Request    | 조회 결과가 없습니다.          |
| 403 : Forbidden      | 요청한 서버에 조회 권한이 없습니다.  |
| 404 : Not Data Found | 요청한 서버에 에러가 있습니다.     |
| 500 : Server Error   | 오류가 발생하였습니다.          |

***

**(3) 리턴 결과 예시**

```json
200 : OK
{
  "data": {
    "userNo": "0",
    "userId": "string",
    "gameCode": "string",
     "cashReal": "0",
     "cashBonus": "0",
     "cashTotal": "0"
    }
}

```

```json
Failure case : HTTP Status Code != 200 AND error object
{
  "error": {
    "code": 911,
    "message": "Not existing user.",
    "detail": null
  }
}
```
