

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# AWS SDK for PHP 버전 3을 사용하여 Amazon SNS에서 SMS 메시지 보내기
<a name="sns-examples-sending-sms"></a>

사용자는 Amazon Simple Notification Service (Amazon SNS)를 사용하여 SMS 수신 가능한 디바이스에 문자 메시지 또는 SMS 메시지를 전송할 수 있습니다. 전화번호로 메시지를 직접 전송할 수 있으며, 전화번호에서 주제를 구독하고 메시지를 주제로 전송하여 메시지를 여러 전화번호로 한 번에 전송할 수 있습니다.

Amazon SNS를 사용하여 전송을 최적화하는 방법(비용 또는 안정성 있는 전송), 월 지출 한도, 메시지 전송을 로깅하는 방법, 일일 SMS 사용 보고서를 구독하는지 여부 등 SMS 메시징에 대한 기본 설정을 지정합니다. 이러한 기본 설정은 검색되고 Amazon SNS의 SMS 속성으로 설정됩니다.

SMS 메시지를 전송할 때 E.164 형식을 사용하여 전화번호를 지정합니다. E.164는 국제 통신에 사용되는 전화번호 구조의 표준입니다. 이 형식을 따르는 전화번호는 최대 15자리 숫자를 사용할 수 있으며 더하기 문자(\$1) 및 국가 코드가 접두사로 추가됩니다. 예를 들어, E.164 형식의 미국 전화번호는 \$11001XXX5550100으로 표시될 수 있습니다.

다음 예제에서는 다음과 같은 작업을 하는 방법을 보여줍니다.
+ [GetSMSAttributes](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-sns-2010-03-31.html#getsmsattributes)를 사용하여 계정에서 SMS 메시지 전송에 대한 기본 설정 검색
+ [SetSMSAttributes](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-sns-2010-03-31.html#setsmsattributes)를 사용하여 계정에서 SMS 메시지 전송에 대한 기본 설정 업데이트
+ [CheckIfPhoneNumberISOptedOut](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-sns-2010-03-31.html#checkifphonenumberisoptedout)을 사용하여 지정된 전화 번호 소유자가 사용자 계정에서 보내는 SMS 메시지 수신을 옵트아웃했는지 여부 확인
+ [ListPhoneNumberOptedOut](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-sns-2010-03-31.html#listphonenumbersoptedout)을 사용하여 소유자가 사용자 계정에서 보내는 SMS 메시지 수신을 옵트아웃한 전화 번호 나열
+ [Publish](https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-sns-2010-03-31.html#publish)를 사용하여 전화 번호로 직접 텍스트 메시지(SMS 메시지) 전송

Amazon SNS 사용에 대한 자세한 내용은 [휴대폰 번호가 구독자인 경우 사용자 알림에 Amazon SNS 사용(SMS 전송)](https://docs.aws.amazon.com/sns/latest/dg/sns-mobile-phone-number-as-subscriber.html)을 참조하세요.

AWS SDK for PHP에 대한 모든 예제 코드는 [GitHub](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/php/example_code)에서 사용할 수 있습니다.

## 보안 인증 정보
<a name="examplecredentials"></a>

예제 코드를 실행하기 전에 [AWS SDK for PHP 버전 3을 AWS 사용하여 로 인증](credentials.md)에 설명된 대로 AWS 보안 인증을 구성합니다. 그 다음 [AWS SDK for PHP 버전 3 설치](getting-started_installation.md)에 설명된 AWS SDK for PHP를 가져옵니다.

## SMS 속성 가져오기
<a name="get-sms-attributes"></a>

SMS 메시지의 기본 설정을 검색하려면 [GetSMSAttributes](https://docs.aws.amazon.com/sns/latest/api/API_GetSMSAttributes.html) 작업을 사용합니다.

다음 예제에서는 `DefaultSMSType` 속성을 가져옵니다. 이 속성은 SMS 메시지를 최소 비용이 발생하도록 메시지 전송 최적화하는 `Promotional`로 전송할지, 최고의 안정성을 달성하도록 메시지 전송을 최적화하는 `Transactional`로 전송할지 제어합니다.

 **가져옵니다**.

```
require 'vendor/autoload.php';

use Aws\Exception\AwsException;
use Aws\Sns\SnsClient;
```

 **샘플 코드** 

```
$SnSclient = new SnsClient([
    'profile' => 'default',
    'region' => 'us-east-1',
    'version' => '2010-03-31'
]);

try {
    $result = $SnSclient->getSMSAttributes([
        'attributes' => ['DefaultSMSType'],
    ]);
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    error_log($e->getMessage());
}
```

## SMS 속성 설정
<a name="set-sms-attributes"></a>

SMS 메시지의 기본 설정을 업데이트하려면 [SetSMSAttributes](https://docs.aws.amazon.com/sns/latest/api/API_SetSMSAttributes.html) 작업을 사용합니다.

다음 예제에서는 `DefaultSMSType` 속성을 `Transactional`로 설정하여 최고의 안정성을 달성하도록 메시지 전송을 최적화합니다.

 **가져옵니다**.

```
require 'vendor/autoload.php';

use Aws\Exception\AwsException;
use Aws\Sns\SnsClient;
```

 **샘플 코드** 

```
$SnSclient = new SnsClient([
    'profile' => 'default',
    'region' => 'us-east-1',
    'version' => '2010-03-31'
]);

try {
    $result = $SnSclient->SetSMSAttributes([
        'attributes' => [
            'DefaultSMSType' => 'Transactional',
        ],
    ]);
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    error_log($e->getMessage());
}
```

## 전화 번호가 옵트아웃되었는지 여부 확인
<a name="check-if-a-phone-number-has-opted-out"></a>

지정된 전화 번호 소유자가 사용자 계정에서 보내는 SMS 메시지 수신을 옵트아웃했는지 여부를 확인하려면 [CheckIfPhoneNumberIsOptedOut](https://docs.aws.amazon.com/sns/latest/api/API_CheckIfPhoneNumberIsOptedOut.html) 작업을 사용합니다.

다음 예제에서는 전화 번호가 국제 통신의 표준인 E.164 형식입니다.

 **가져옵니다**.

```
require 'vendor/autoload.php';

use Aws\Exception\AwsException;
use Aws\Sns\SnsClient;
```

 **샘플 코드** 

```
$SnSclient = new SnsClient([
    'profile' => 'default',
    'region' => 'us-east-1',
    'version' => '2010-03-31'
]);

$phone = '+1XXX5550100';

try {
    $result = $SnSclient->checkIfPhoneNumberIsOptedOut([
        'phoneNumber' => $phone,
    ]);
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    error_log($e->getMessage());
}
```

## 옵트아웃된 전화 번호 나열
<a name="list-opted-out-phone-numbers"></a>

소유자가 사용자 계정에서 보내는 SMS 메시지 수신을 옵트아웃한 전화 번호 목록을 검색하려면 [ListPhoneNumbersOptedOut](https://docs.aws.amazon.com/sns/latest/api/API_ListPhoneNumbersOptedOut.html) 작업을 사용합니다.

 **가져옵니다**.

```
require 'vendor/autoload.php';

use Aws\Exception\AwsException;
use Aws\Sns\SnsClient;
```

 **샘플 코드** 

```
$SnSclient = new SnsClient([
    'profile' => 'default',
    'region' => 'us-east-1',
    'version' => '2010-03-31'
]);

try {
    $result = $SnSclient->listPhoneNumbersOptedOut();
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    error_log($e->getMessage());
}
```

## 텍스트 메시지(SMS 메시지)에 게시
<a name="publish-to-a-text-message-sms-message"></a>

전화 번호로 직접 텍스트 메시지(SMS 메시지)를 전송하려면 [Publish](https://docs.aws.amazon.com/sns/latest/api/API_Publish.html) 작업을 사용합니다.

다음 예제에서는 전화 번호가 국제 통신의 표준인 E.164 형식입니다.

SMS 메시지는 최대 140바이트를 포함할 수 있습니다. 단일 SMS 게시 작업에 대한 크기 제한은 1,600바이트입니다.

SMS 메시지 전송에 대한 자세한 내용은 [SMS 메시지 전송](https://docs.aws.amazon.com/sns/latest/dg/sms_publish-to-phone.html)을 참조하십시오.

 **가져옵니다**.

```
require 'vendor/autoload.php';

use Aws\Exception\AwsException;
use Aws\Sns\SnsClient;
```

 **샘플 코드** 

```
$SnSclient = new SnsClient([
    'profile' => 'default',
    'region' => 'us-east-1',
    'version' => '2010-03-31'
]);

$message = 'This message is sent from a Amazon SNS code sample.';
$phone = '+1XXX5550100';

try {
    $result = $SnSclient->publish([
        'Message' => $message,
        'PhoneNumber' => $phone,
    ]);
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    error_log($e->getMessage());
}
```