Text Local SMS API 成功发送消息但发送失败

时间:2021-06-27 05:57:39

标签: php api sms textlocal

我正在使用Text Local 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;

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

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

我也尝试过使用用户名和哈希代替 api 密钥,但结果仍然相同。我还在本地主机和服务器中尝试了相同的脚本,但结果仍然相同。 谁能帮忙?

0 个答案:

没有答案