0

我正在使用文本本地 SMS API 并在 PHP 中回显响应,虽然“响应”说成功,但文本本地 api 的报告面板中的传递状态显示状态无效。这是我的代码: 我在这里隐藏了 api、发件人和电话号码。

$OTP = rand(1000,9999);
$apiKey = urlencode('My API');

// Message details
$var= $OTP;

//10 digit phone number with country code 91
$numbers = array(911234567890);
$sender = urlencode('XXXXXX');
$message = rawurlencode("Dear User, your OTP login is ".$var." . This OTP is valid only for 24 hours.");

$numbers = implode(',', $numbers);

// Prepare data for POST request
$data = array('apikey' => $apiKey, 'numbers' => $numbers, "sender" => $sender, "message" => $message);

// Send the POST request with cURL
$ch = curl_init('https://api.textlocal.in/send/');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;

执行后我得到的输出是:

{"balance":988,"batch_id":1834685178,"cost":1,"num_messages":1,"message":{"num_parts":1,"sender":"xxxxxx","content":"Dear User, your OTP login is 8836 . This OTP is valid only for 24 hours."},"receipt_url":"","custom":"","messages":[{"id":"12565543282","recipient":911234567890}],"status":"success"} 

我尝试使用消息 ID 来检查传递状态。这是代码。

// Account details
$apiKey = urlencode('My API');

// Message Details
$message_id = '12565543282';

// Prepare data for POST request
$data = array('apikey' => $apiKey, 'message_id' => $message_id);

// Send the POST request with cURL
$ch = curl_init('https://api.textlocal.in/status_message/');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

// Process your response here
echo $response;

以下是交货状态的响应。根据 Text Local 的文档,状态“I”表示无效的交付状态。

{"message":{"id":12565543282,"recipient":911234567890,"type":"sms","status":"I","date":"2021-06-27 11:00:45"},"status":"success"}

我也尝试过使用用户名和哈希而不是 api 键,但结果仍然相同。我还在本地主机和服务器中尝试了相同的脚本,但结果仍然相同。有人可以帮忙吗??

4

0 回答 0