cURLを使用してXMLペイロードをSMSサービスプロバイダーに送信するPHPスクリプトがあります。問題は、ユーザーが複数のSMSを受信していると不満を言っていることです(1日を通して50の場合もあります)。それが私のコードに問題があるのか、SMSサービスプロバイダーに問題があるのかわかりません。これを送信するフォームには、送信を2回以上押さない人だけがアクセスできます。
これは私のコードであり、誰かがそれをざっと見て、欠落している場合は複数のリクエストを送信する重要なオプションが欠落していないかどうかを確認できれば非常にありがたいです。
<?php
// the following code is only executed if there is no sms timestamp in the db for the user. sms timestamp is added to the db when $error != true;
$error = false;
define('XML_PAYLOAD', '<xml data...>');
define('XML_POST_URL', 'https://URLOFSERVICEPROVIDER');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, XML_POST_URL);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, XML_PAYLOAD);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8', 'Content-Length: '.strlen(XML_PAYLOAD) ));
$result = curl_exec($ch);
if ( curl_errno($ch) ) {
$error = true;
} else {
$returnCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
switch($returnCode){
case 200:
break;
default:
$error = true;
break;
}
}
curl_close($ch);
if($error == false){
// store that SMS was sent successfully
}
?>