Sending SMS from a Rented Number with Sinch in PHP

时间:2015-07-28 17:10:31

标签: php http sms authorization sinch

I have rented a number through sinch.com and while I am able to successfully send an SMS to my own verified telephone number, I am unable to send SMS to various other telephone numbers.

function sendSignInText($phone_number, $first_name)  {

$key = "xxxx-xxx-xxx-xxx-xxxxxxxx";    
$secret = "xxxxxxxx"; 
$message = $first_name . ', thanks you for signing in. We will text you when we\'re ready for you';
$phone   = $phone_number;

$body = json_encode(array('From' => $rented_number, 'Message'=>$message, ));
$timestamp = date("c");

$path                  = "/v1/sms/" . $phone;
$content_type          = "application/json";
$canonicalized_headers = "x-timestamp:" . $timestamp;

$content_md5 = base64_encode( md5( utf8_encode($body), true ));

$string_to_sign =
    "POST\n".
    $content_md5."\n".
    $content_type."\n".
    $canonicalized_headers."\n".
    $path;

$signature = base64_encode(hash_hmac("sha256", utf8_encode($string_to_sign), base64_decode($secret), true));
$authorization = "Application " . $key . ":" . $signature;

$service_url = 'https://messagingapi.sinch.com'.$path;
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'content-type: '.$content_type,
    'x-timestamp:' . $timestamp,
    'authorization:' . $authorization
));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$curl_response = curl_exec($curl);
// @todo: checking response / working with results
curl_close($curl);
}

It could be an issue with the number transferring from a sandbox version of the app. Sinch recommends you play in a sandbox before putting it out into production. So it was working as a sandbox version with my own personal telephone number and is still working as a production app with my own number but doesn't work with other, non-verified numbers. Any help would be greatly appreciated, thanks.

0 个答案:

没有答案