# 2-3. 메시지 전송 종료 정보 발송

### HTTPS Parameters

메시지 기본 셋팅 및 해당 푸시 메시지를 받을 대상자 셋팅이 모두 끝나 메시지 전송을 종료하고 싶다면, 해당 메시지 IDX에 종료 파라미터를 실어 API Server에 전달합니다.

API Server로 전달해야 할 파라미터들은 아래 표를 참조해 주세요.

#### \[표 2.6] 다수 발송 메시지, 메시지 전송 종료 HTTPS, Parameters

<table><thead><tr><th width="150">파라미터명</th><th width="150">필수 여부</th><th width="150">Byte 수</th><th>설명</th></tr></thead><tbody><tr><td><mark style="color:red;">appkey</mark></td><td>필수</td><td>-</td><td>Application key</td></tr><tr><td><mark style="color:red;">appsecret</mark></td><td>필수</td><td>-</td><td>Application Secret</td></tr><tr><td><mark style="color:red;">customerkey</mark></td><td>필수</td><td>-</td><td>Customer key</td></tr><tr><td><mark style="color:red;">msgidx</mark></td><td>필수</td><td>-</td><td>메시지를 셋팅하고 돌려받은 메시지 idx 값</td></tr><tr><td><mark style="color:red;">isfinish</mark></td><td>필수</td><td>-</td><td>종료 플래그: 값을 Y로 셋팅 함</td></tr></tbody></table>

### Response JSON

API서버에서 전달받은 파라미터 처리 후 result가 200, processCode가 20003 이라면, 해당 메시지에 대해 원격 발송 절차가 완료된 것입니다.

```json
{"result" : "200", "msgIdx" :  "A1DS33DDSQ2321", "processCode" : "20003", "message" : "메시지 등록이 완료 되었습니다."}
```

JSON 형태로 제공되는 결과 값 및 각 데이터의 코드값에 대한 설명은 [\[표 2.3\] 발송 JSON 결과의 result code 유형](#2.3-json-result-code)과 [\[표 2.4\] JSON 결과의 processCode code 유형](#2.4-json-processcode-code)을 참조해 주시기 바랍니다.

또한, 이렇게 원격 발송 처리 완료된 사항은 핑거푸시 사이트의 푸시 발송이력 > 타겟팅 푸시 에서 발송 상태 및 현황을 확인 하실 수 있습니다.

### 샘플 소스 설명

다수의 대상자에게 메시지 보내기 세 번째 단계인 메시지 셋팅 완료 경우 기본 메시지 전달 후 수신 받은 메시지 IDX(msgidx)와 메시지 셋팅 종료 플래그인 isfinish 파라미터(값 ‘Y’)를 파라미터에 담아 API서버로 보내면 해당 내용에 대해 처리 후 결과 값을 반환합니다.

#### **JAVA Version**

Github에 올려져 있는 샘플 소스는 아래 설명된 내용 중 중복된 부분들을 method화 하여 처리하므로 약간의 차이가 있을 수 있으나, 기본 발송 방식의 설명이므로 해당 중복되는 부분을 풀어서 설명하도록 하겠습니다.

다수 발송의 첫 단계인 기본 메시지 발송의 부분은 앞서 설명한, 일괄 발송 및 단일 건 발송과 마찬가지로 필수값 및 메시지 부가 정보를 전송하는 것과 동일합니다.

1\) 파라미터를 담을 List 객체를 선언해 전달할 값들을 셋팅 합니다.

```java
List <BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
```

2\) 필수값들을 셋팅 합니다.

```java
List <BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); 

params.add (new BasicNameValuePair("appkey", 애플리케이션 키));           // (필수)	
params.add (new BasicNameValuePair("appsecret", 애플리케이션 시크릿));     // (필수)
params.add (new BasicNameValuePair("customerkey", 발급받은 커스터머키));   // (필수)
params.add (new BasicNameValuePair("isfinish", "Y"));                   // 푸시 메시지 종료(필수)
```

3\) 기존 HttpClient의 DefaultHttpClient를 이용한 원격 접속 방식이 deprecated 된    이유로 HttpsURLConnection을 이용하여 접속합니다. 물론 deprecated 되었다고 해서 DefaultHttpClient 방식이 동작하지 않는 것은 아닙니다. 해당 방식 역시 github에 올려져 있는 샘플 소스에 구현되어 있습니다.

* 예제: FingerpushDaoImpl.sendHttpsExe(String callUrl, List \<BasicNameValuePair> params))

전달하는 파라미터는 UTF-8로 인코딩 하여 전달해야 합니다.

* 예제: 샘플의 FingerpushDaoImpl.sendHttpsUrlConExe(String callUrl, List \<BasicNameValuePair> params)

```java
URL url = new URL(callUrl);
trustAllHosts();

HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
httpsURLConnection.setHostnameVerifier(new HostnameVerifier() {
    @Override
    public boolean verify(String s, SSLSession sslSession) {
        return true;
    }
});
HttpURLConnection connection = httpsURLConnection;

connection.setRequestMethod("POST");
connection.setUseCaches(false);           
connection.setDoInput(true);
connection.setDoOutput(true);

UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "utf-8");
OutputStream post = connection.getOutputStream();
entity.writeTo(post);
 
post.flush();
connection.connect();
```

4\) 받은 결과는 JSON 타입의 String 이므로 결과에 맞게 변환하여 사용하시는 UI에 적용하시면 됩니다.

JSON 형태로 제공되는 결과 값 및 각 데이터의 코드 값에 대한 설명은 [\[표 2.2\] 발송 JSON 결과](#2.2-json)와 [\[표 2.3\] 발송 JSON 결과의 result code 유형](#2.3-json-result-code)을 참조해 주시기 바랍니다.

```java
StringBuilder responseStringBuilder = new StringBuilder();
logger.debug("contentType : "+connection.getContentType());
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK){
        
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
        for (;;){
                String stringLine = bufferedReader.readLine();
                if (stringLine == null ) break;
                responseStringBuilder.append(stringLine + '\n');
        }
        bufferedReader.close();
}

connection.disconnect();

jsonString = responseStringBuilder.toString(); 
```

&#x20;5\) 해당 jsonString을 파싱하여 result 값이 200, processCode 값이 20003 인 경우 발송 관련 처리는 모두 완료된 것입니다.

#### ※ JAVA Version 다수 건 발송 샘플

<table data-header-hidden><thead><tr><th width="150"></th><th></th></tr></thead><tbody><tr><td>소스 주소</td><td><a href="https://github.com/kissoft/FingerPushSTSinJava">https://github.com/kissoft/FingerPushSTSinJava</a></td></tr><tr><td>class</td><td><p>com.fingerpush.push.FingerpushDao</p><p>com.fingerpush.push.FingerpushDaoImpl</p><p>com.fingerpush.push.PushVO</p></td></tr><tr><td>jsp</td><td>JSP/sendTargetMore.jsp</td></tr></tbody></table>

#### **PHP Version**

Github에 올려져 있는 샘플 소스는 아래 설명된 내용 중 중복된 부분들을 method화 하여 처리하므로 약간의 차이가 있을 수 있으나, 기본 발송 방식의 설명이므로 해당 중복되는 부분을 풀어서 설명하도록 하겠습니다.

다수 발송의 첫 단계인 기본 메시지 발송의 부분은 앞서 설명한, 일괄 발송 및 단일 건 발송과 마찬가지로 필수값 및 메시지 부가 정보를 전송하는 것과 동일합니다.

&#x20;1\) 기본 앱 정보를 세팅합니다.

```php
// 공통 필수 
$key = array(
    'appkey'            => '[발급받은 appkey]',
    'appsecret'         => '[발급받은 appsecret]',
    'customerkey'       => '[발급받은 customerkey]',
);
```

2\) 필수값을 세팅합니다.\
이때 메시지 기본 정보 발송에서 통신으로 받은 결과값 중 msgidx를 포함시킵니다. \
[\[표 2.2\] 발송 JSON 결과](#2.2-json) 참조. 또한 전송 종료임을 알리는 isfinish도 포함시킵니다.

```php
$option = array(
	"msgidx" 		=> $msgidx, 	// (1) 번 메시지 등록시 반환된 msgIdx 값 (필수)
	"isfinish" 		=> "Y",		// 푸시 메시지 종료 (필수)
);
```

3\) 앱 기본정보와 옵션값을 URL 인코드 한 쿼리 문자열로 생성합니다.

```php
$data = array_merge($key, $option);
$param = http_build_query($data);
```

4\) PHP cURL 라이브러리를 이용하여 핑거푸시 API와 통신합니다.

* PHP cURL 라이브러리: <https://www.php.net/manual/en/book.curl.php>
* 다수에게 메시지 발송 API URL: [https://api-v2.fingerpush.com/rest/sts/v4/setSTSPushs.jsp](https://api-v2.fingerpush.com/rest/sts/v3/setSTSPushs.jsp)

cURL을 아래와 같이 HTTPS통신으로 세팅합니다.

<pre class="language-php"><code class="lang-php">$url = ' https://api-v2.fingerpush.com/rest/sts/v4/setSTSPushs.jsp'; // 핑거푸시 다수에게 메시지 발송 API URL
$ch = curl_init (); 			                // cURL 선언
curl_setopt ( $ch, CURLOPT_URL, $url ); 		// URL 세팅
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false ); 	// 인증서 체크
curl_setopt ( $ch, CURLOPT_SSLVERSION, 1 ); 		// SSL 버전 -> 1만 된다.
curl_setopt ( $ch, CURLOPT_HEADER, 0 ); 		// 헤더 출력 여부
curl_setopt ( $ch, CURLOPT_POST, 1 ); 			// POST, GET 접속 여부
curl_setopt ( $ch, CURLOPT_TIMEOUT, 30 ); 		// Time Out 세팅
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );         // 결과값 리턴 여부
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $param ); 	// parameter
$res = curl_exec ( $ch ); 				// cURL 실행하고 결과 저장

/* cURL 에러검출 */
$cErrno = curl_errno($ch);

if ($cErrno == 0) $response = $res;
else $response = exit;
<strong>curl_close ( $ch );					// cURL을 닫고 자원 반환
</strong></code></pre>

5\) 전달 받은 JSON 문자열 결과값을 PHP 변수로 변환합니다.

```php
// 1. json 처리시
echo $response;

// 2. object 처리시
$result = json_decode ( $response, true );                // 결과값 JSON 디코드
print_r($result);                                        // 결과 값 출력
```

6\) 해당 결과로 받은 내용을 JSON형식으로 받아 파싱한 결과가 result: 200, processCode: 20003인 경우 발송 관련 처리는 모두 완료된 것입니다.

* [\[표 2.2\] 발송 JSON 결과](https://developers.fingerpush.com/app-push/sdk-manual/s2s/many/pages/Xva7XCvo61p5BdwM7Jyg#id-2.2-json)와 [\[표 2.3\] 발송 JSON 결과의 result code 유형](https://developers.fingerpush.com/app-push/sdk-manual/s2s/many/pages/Xva7XCvo61p5BdwM7Jyg#id-2.3-json-result-code) 참조


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.fingerpush.com/app-push/sdk-manual/s2s/many/2-3..md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
