2017-11-15 6 views
0

smsgateway.meを使用してメッセージを送信するデフォルトのコードを使用しています。ただし、SMSが送信されない場合や、SMSが失敗した場合は、SMSをデータベースに保存したい場合があります。 これを行うには、$ result配列の値が必要だと思いますが、開始方法はわかりません。私は何の結果もなしに多くの異なるコードを試しました。smsgateway.meメッセージのステータスをPHP変数に保存します

どうすればいいのでしょうか?次のコードと変数に基づいて何か他のことをやってください。 ありがとう!

ドキュメントhereここ

は、メッセージを送信する(デフォルトの変数を持つ)のデフォルトのコードは次のとおりです。

<?php 
include "smsGateway.php"; 
$smsGateway = new SmsGateway('[email protected]', 'password'); 

$deviceID = 1; 
$number = '+44771232343'; 
$message = 'Hello World!'; 

$options = [ 
'send_at' => strtotime('+10 minutes'), // Send the message in 10 minutes 
'expires_at' => strtotime('+1 hour') // Cancel the message in 1 hour if the message is not yet sent 
]; 

//Please note options is no required and can be left out 
$result = $smsGateway->sendMessageToNumber($number, $message, $deviceID, $options); 
?> 

成功内容:

{ 
"success": true, 
"result": { 
"success": [ 
{ 
"id": "308", 
"device_id": "4", 
"message": "hello world!", 
"status": "pending", 
"send_at": "1414624856", 
"queued_at": "0", 
"sent_at": "0", 
"delivered_at": "0", 
"expires_at": "1414634856", 
"canceled_at": "0", 
"failed_at": "0", 
"received_at": "0", 
"error": "None", 
"created_at": "1414624856", 
"contact": { 
"id": "14", 
"name": "Phyllis Turner", 
"number": "+447791064713" 
} 
} 
], 
"fails": [ 
] 
} 
} 

エラー内容:

{ 
"success": true, 
"result": { 
"success": [ 
], 
"fails": [ 
"number": "+44771232343" 
"message": "hello world!", 
"device": 1 
"errors": { 
"device": ["The selected device is invalid"], 
} 
] 
} 
} 
+0

もしsizeof($ result ['result'] ['success'])== 0){echo'failed '} else {// success stuff} –

+0

こんにちはマイケル、すばやい返信をありがとう。 Thiseコードは常に失敗を示し、//私は//成功のものを変更して「成功」をエコーし​​ますが、常に成功すると失敗し、失敗しました。何か案は? –

+0

print_r($ result ['result'] ['success'])を試してみて、あなたが得たものを見ると、2つの成功キーがあり、1つは投稿の成功ステータス、もう1つはレスポンスの成功データです –

答えて

0

これが失敗した場合はトリックをした:これは成功に取り組んでいます

if (isset($result['response']['result']['fails'][0]['number']) === TRUE) { 
    echo 'failed'; 
else{ 
    echo 'success'; 
} 

if(isset($result['response']['result']['success'][0]['id']) === TRUE){ 
    echo 'success'; 
}else{ 
    echo 'failed'; 
} 

おかげでマイケル、お返事は、私はそれを少し変更し、それを把握するのに役立ちました!

関連する問題