每个人都在这里使用 whispir API 吗?
我正在尝试使用他们的回调功能,但它不起作用。根据他们的文档http://developer.whispir.com/docs/read/Whispir_API_Callbacks回调是通过发送 http 请求触发的
HTTP 1.1 POST http://api.whispir.com/messages?apikey=<yourkey>
Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxx
Content-Type: application/vnd.whispir.message-v1+xml
请注意我使用的是 laravel 4.2
private static function curl_post($url, $username, $password, $curl_data)
{
$options = array(
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_AUTOREFERER => TRUE,
CURLOPT_CONNECTTIMEOUT => 90,
CURLOPT_TIMEOUT => 90,
CURLOPT_MAXREDIRS => 10,
CURLOPT_URL => $url,
CURLOPT_HEADER => false,
CURLOPT_HTTPHEADER => array(
'Authorization: Basic cGhwZGV2YWxwaGE6cGx1c3BsdXMxMjM=',
'Content-Type: application/vnd.whispir.message-v1+json'
),
CURLOPT_ENCODING => "",
CURLOPT_USERAGENT => "'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13')",
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $curl_data,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_VERBOSE => 1,
CURLOPT_USERPWD => $username . ":" . $password
);
$ch = curl_init();
curl_setopt_array($ch, $options);
$data = curl_exec($ch);
if(curl_errno($ch))
throw new Exception(curl_error($ch));
curl_close($ch);
return $data;
}
private static function sendMessage( $to, $subject, $body )
{
$host = $_ENV['SMS_HOST'];
$apikey = $_ENV['SMS_APIKEY'];
$username = $_ENV['SMS_USERNAME'];
$password = $_ENV['SMS_PASSWORD'];
$data = array(
"to" => $to,
"subject" => $subject,
"body" => $body,
"callbackId" => "callback"
);
$json = json_encode($data);
return Smscenter::curl_post( $host.$apikey, $username, $password, $json );
}
请发表评论以获得任何澄清。