簡體   English   中英

使用CURL發送Twizo短信

[英]Twizo SMS sending using CURL

我一直在嘗試使用API​​說明發送短信: https//www.twizo.com/developers/documentation/

$data = array(
    'sender'=>'Me',
    'body'=>'Message',
    'recipients'=>'201*****0'
);

$string = http_build_query($data);
$ch = curl_init("https://twizo:API-KEY@api-asia-01.silverstreet.com/v1/sms/submitsimple");

curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close ($ch);
print_r($server_output);

代碼有效但返回錯誤信息:

{“validation_messages”:{“recipients”:{“noArraySupplied”:“此字段僅允許數組值”}},“type”:“ http://www.w3.org/Protocols/rfc2616/rfc2616-sec10 .html “,”title“:”不可處理的實體“,”狀態“:422,”詳細信息“:”驗證失敗“}

編輯2:上面的問題已修復,但現在我想讓這個工作:

send.php文件:

set_time_limit(0);
if(isset($_POST['submit'])){
$letter = $_POST['message'];
$recs = $_POST['rec'];
$mailist = $_POST['number'];
$from = $_POST["from"];
$message = $letter;
$line = 0;
$list = explode("\n",$_POST['number']);
foreach ($list as $number){ 
$line = $line+1;
}
?>
<H4>Total Number : <?php echo $line; ?> </H4>
<?php
$spamed = 0;
foreach ($list as $number){ 
$spamed = $spamed+1;
echo " ".$spamed."/".$line." ><b>".$number." => status :";
include "result.php";
}
}


result.php file :


sleep(0.7);
$message_array = array("https://silverstreet:API-KEY@api-asia-01.silverstreet.com/v1/sms/submitsimple");
$mssage = array_rand($message_array);
$url = $message_array[$mssage];
$data = array(
  'body' => $message,
  'sender' => $from,
  'recipients' =>array("$recs")
); 
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$js = json_decode($result);
curl_close($ch);
if($js->message == "ok"){echo "sent";echo "<br>";} else {
if (!isset($js->message)){echo $result;
echo "<br>";
echo $url;
}else  {
echo "not sent <br> message  =";
echo  $js->message;
echo "<br>";
echo $url;}

我認為你需要為收件人提供第二維數組。

$data = array(
    'sender'=>'Me',
    'body'=>'Message',
    'recipients'=>array('201*****0')
);

嘗試這個:

文檔說明需要通過HTTP頭發送API密鑰,錯誤代碼也表示相同:

$string = http_build_query($data);
$ch = curl_init("https://api-asia-01.silverstreet.com/v1/sms/submitsimple");

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'twizo: API-KEY'
));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close ($ch);
print_r($server_output);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM