smsglobal php
v1.3.0
これは、SMS 機能を PHP アプリケーションに統合するための、SMSGlobal の REST API 用の PHP クライアント ライブラリです。
今すぐ無料の SMSGlobal アカウントにサインアップし、高度な SMS プラットフォームである MXT から API キーを取得してください。さらに、無制限の無料開発者サンドボックス テストを利用して、API をすべて試してみてください。
PHP クライアント ライブラリをプロジェクトにインストールするには、Composer の使用をお勧めします。
composer require smsglobal/smsglobal-php
examples
フォルダーをチェックアウトする
SMSを送信する
<?php
require_once __DIR__ . ' /vendor/autoload.php ' ;
// get your REST API keys from MXT https://mxt.smsglobal.com/integrations
SMSGlobal Credentials:: set ( ' YOUR_API_KEY ' , ' YOUR_SECRET_KEY ' );
$ sms = new SMSGlobal Resource Sms ();
try {
$ response = $ sms -> sendToOne ( ' DESTINATION_NUMBER ' , ' This is a test message. ' );
print_r ( $ response [ ' messages ' ]);
} catch ( Exception $ e ) {
echo $ e -> getMessage ();
}
OTPを送信する
<?php
require_once __DIR__ . ' /vendor/autoload.php ' ;
// get your REST API keys from MXT https://mxt.smsglobal.com/integrations
SMSGlobal Credentials:: set ( ' YOUR_API_KEY ' , ' YOUR_SECRET_KEY ' );
$ otp = new SMSGlobal Resource Otp ();
try {
$ response = $ otp -> send ( ' DESTINATION_NUMBER ' , ' {*code*} is your SMSGlobal verification code. ' );
print_r ( $ response );
} catch ( Exception $ e ) {
echo $ e -> getMessage ();
}
次の json 応答がサーバーから返されます。
{
"requestId" : " 404372541683674336263499 " ,
"validUnitlTimestamp" : " 2020-11-18 16:24:51 " ,
"createdTimestamp" : " 2020-11-18 16:22:51 " ,
"lastEventTimestamp" : " 2020-11-18 16:22:51 " ,
"destination" : " 61400000000 " ,
"status" : " Sent "
}
OTP を確認する
ユーザーが入力した OTP コードは、 requestId
またはdestination number
を使用して検証できます。それぞれの方法の例を次に示します。
<?php
require_once __DIR__ . ' /vendor/autoload.php ' ;
// get your REST API keys from MXT https://mxt.smsglobal.com/integrations
SMSGlobal Credentials:: set ( ' YOUR_API_KEY ' , ' YOUR_SECRET_KEY ' );
$ otp = new SMSGlobal Resource Otp ();
try {
$ response = $ otp -> verifyByRequestId ( ' request Id ' , ' OTP code enterted by your user. ' );
print_r ( $ response );
} catch ( Exception $ e ) {
echo $ e -> getMessage ();
}
<?php
require_once __DIR__ . ' /vendor/autoload.php ' ;
// get your REST API keys from MXT https://mxt.smsglobal.com/integrations
SMSGlobal Credentials:: set ( ' YOUR_API_KEY ' , ' YOUR_SECRET_KEY ' );
$ otp = new SMSGlobal Resource Otp ();
try {
$ response = $ otp -> verifyByDestination ( ' destination number ' , ' OTP code enterted by your user. ' );
print_r ( $ response );
} catch ( Exception $ e ) {
echo $ e -> getMessage ();
}
検証が成功すると、次の JSON 応答がサーバーから返されます。
{
"requestId" : " 404372541683674336263499 " ,
"validUnitlTimestamp" : " 2020-11-18 16:24:51 " ,
"createdTimestamp" : " 2020-11-18 16:22:51 " ,
"lastEventTimestamp" : " 2020-11-18 16:22:51 " ,
"destination" : " 61400000000 " ,
"status" : " Verified "
}
OTPをキャンセルする
OTP の有効期限が切れておらず、まだ検証されていない場合は、OTP リクエストをキャンセルできます。これは、 requestId
またはdestination number
を使用して実行できます。それぞれの方法の例を次に示します。
require_once __DIR__ . ' /vendor/autoload.php ' ;
// get your REST API keys from MXT https://mxt.smsglobal.com/integrations
SMSGlobal Credentials:: set ( ' YOUR_API_KEY ' , ' YOUR_SECRET_KEY ' );
$ otp = new SMSGlobal Resource Otp ();
try {
$ response = $ otp -> cancelByRequestId ( ' request Id ' );
print_r ( $ response );
} catch ( Exception $ e ) {
echo $ e -> getMessage ();
}
require_once __DIR__ . ' /vendor/autoload.php ' ;
// get your REST API keys from MXT https://mxt.smsglobal.com/integrations
SMSGlobal Credentials:: set ( ' YOUR_API_KEY ' , ' YOUR_SECRET_KEY ' );
$ otp = new SMSGlobal Resource Otp ();
try {
$ response = $ otp -> cancelByDestination ( ' destination number ' );
print_r ( $ response );
} catch ( Exception $ e ) {
echo $ e -> getMessage ();
}
キャンセルが成功すると、サーバーから次の JSON 応答が返されます。
{
"requestId" : " 404372541683674336263499 " ,
"validUnitlTimestamp" : " 2020-11-18 16:24:51 " ,
"createdTimestamp" : " 2020-11-18 16:22:51 " ,
"lastEventTimestamp" : " 2020-11-18 16:22:51 " ,
"destination" : " 61400000000 " ,
"status" : " Cancelled "
}
開発依存関係をインストールする
composer require smsglobal/smsglobal-php
単体テストを実行する
./vendor/bin/phpunit tests
カバレッジあり (拡張子 pcov または xdebug が必要)
./vendor/bin/phpunit --coverage-text tests
利用可能なリソースのリストについては、REST API ドキュメントを参照してください。
ご質問がございましたらお問い合わせください