我有一个 PHP 脚本,它使用 cURL 将 XML 有效负载发送到 SMS 服务提供商。问题是用户抱怨他们收到多条短信(有时全天有 50 条),我不知道这是我的代码问题还是短信服务提供商的问题。只有不会多次按提交的人才能访问提交此表单的表单。
这是我的代码,如果有人可以快速查看它以查看我是否遗漏了一个重要选项,我将不胜感激,如果遗漏,将发送多个请求:
<?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
}
?>