Unicode を含む SMS の送信
Nexmo の SMS 用 API は、中国語、日本語、韓国語での通信時に必要となる Unicode 文字もサポートしています。
Unicode 文字を含む SMS を送信するには、以下の例の次の変数を置き換えます。
| キー | 説明 |
|---|---|
TO_NUMBER | SMS の送信先番号 (例: 447700900000)。 |
NEXMO_API_KEY | Nexmo Dashboard でご確認ください。 |
NEXMO_API_SECRET | Nexmo Dashboard でご確認ください。 |
Write the code
Add the following to send-an-sms-with-unicode.sh:
curl -X POST https://rest.nexmo.com/sms/json \
-u "$VONAGE_API_KEY:$VONAGE_API_SECRET" \
-d "from=${SMS_SENDER_ID}" \
-d "to=${SMS_TO_NUMBER}" \
-d 'text=こんにちは世界' \
-d 'type=unicode'
Run your code
Save this file to your machine and run it:
Prerequisites
npm install @vonage/server-sdkCreate a file named send-unicode-sms.js and add the following code:
const { Vonage } = require('@vonage/server-sdk');
const vonage = new Vonage({
apiKey: VONAGE_API_KEY,
apiSecret: VONAGE_API_SECRET,
});Write the code
Add the following to send-unicode-sms.js:
vonage.sms.send({
to: SMS_TO_NUMBER,
from: SMS_SENDER_ID,
text: 'こんにちは世界',
type: 'unicode',
})
.then((resp) => console.log(resp))
.catch((error) => console.error(error));Run your code
Save this file to your machine and run it:
Prerequisites
Add the following to build.gradle:
Create a class named SendUnicodeMessage and add the following code to the main method:
Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.sms with the package containing SendUnicodeMessage:
Prerequisites
Add the following to build.gradle:
Create a class named SendUnicodeMessage and add the following code to the main method:
VonageClient client = VonageClient.builder().apiKey(VONAGE_API_KEY).apiSecret(VONAGE_API_SECRET).build();Write the code
Add the following to the main method of the SendUnicodeMessage class:
TextMessage message = new TextMessage(SMS_SENDER_ID, SMS_TO_NUMBER, "Blue Öyster Cult \uD83E\uDD18", true);
SmsSubmissionResponse responses = client.getSmsClient().submitMessage(message);
for (SmsSubmissionResponseMessage responseMessage : responses.getMessages()) {
System.out.println(message);
}Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.sms with the package containing SendUnicodeMessage:
Prerequisites
Install-Package VonageCreate a file named SendSmsWithUnicode.cs and add the following code:
Add the following to SendSmsWithUnicode.cs:
Prerequisites
composer require vonage/clientCreate a file named send-unicode-sms.php and add the following code:
Run your code
Save this file to your machine and run it:
Prerequisites
pip install vonage python-dotenvRun your code
Save this file to your machine and run it:
Prerequisites
gem install vonageCreate a file named send-unicode-sms.rb and add the following code:
Write the code
Add the following to send-unicode-sms.rb:
client.sms.send(
from: SMS_SENDER_ID,
to: SMS_TO_NUMBER,
text: 'こんにちは世界',
type: "unicode"
)Run your code
Save this file to your machine and run it:
試行手順
上記例を実行すると、指定した携帯電話番号に Unicode 文字を含むメッセージが正常に送信されます。
Unicode メッセージの最大文字数は通常のメッセージの 160 でなく 70 であることにご注意ください。この点に関する詳細についてはヘルプページを参照してください