0
有沒有人在JSON foRMAT中使用TWILIO api進行響應?如何獲得以json格式發送短信響應twilio
如何使用twilio API捲曲
這裏是一個工作,但反應未格式化的文本代碼來獲取發送短信響應JSON格式的響應。
$AccountSid = "SANDBOX_ACC_ID";
$AuthToken = "SANDBOX_TOKEN";
$url = "https://api.twilio.com/2010-04-01/Accounts/$AccountSid/SMS/Messages";
$from = "+MAGICNUMBER";
$to = "+XXXXXXXXXX"; // twilio trial verified number
$body = "Sending test SMS using Twilio Api";
$data = array (
'From' => $from,
'To' => $to,
'Body' => $body,
);
$post = http_build_query($data);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "$AccountSid:$AuthToken");
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($curl);
curl_close($curl);
//var_dump($post);
echo "<pre>";
echo 'testing with curl '.$response;
echo "</pre>";
沒錯剛纔我發現,太https://www.twilio.com/docs/api/ rest/response#response-formats-json ...不管怎樣,感謝回覆:) – fedrick