-
Notifications
You must be signed in to change notification settings - Fork 2
/
sinchSMS.php
39 lines (32 loc) · 997 Bytes
/
sinchSMS.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
//Slack Details
$command = $_POST['command'];
$text = $_POST['text'];
//Parse
$pieces = explode(" ", $text, 2);
//Sinch API Details
$key = "your_app_key";
$secret = "your_app_secret";
//Query
$phone_number = $pieces[0];
$user = "application\\" . $key . ":" . $secret;
$message = array("message"=> $pieces[1]);
$data = json_encode($message);
$ch = curl_init('https://api.sinch.com/messaging/v1/sms/' . $phone_number);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD,$user);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
//Results
$result = curl_exec($ch);
if(curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
} else {
echo $result;
}
curl_close($ch);
//Final Output
echo "\n Your message was sent.";
?>