-
Notifications
You must be signed in to change notification settings - Fork 0
/
Message.php
50 lines (44 loc) · 1.44 KB
/
Message.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
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* Created by Doniyor Mamatkulov.
* User: d.mamatkulov
* Date: 15.11.2018
* Time: 17:47
*/
class Message {
public $pm_login = "login";
public $pm_password = "password";
public $pm_url = "http://url:8083/broker-api/send";
public function sendMessage($recipient, $code) {
$data = [
'messages' => [
[
'recipient' => $recipient,
'message-id' => rand(1111111, 9999999),
'sms' => [
'originator' => '3700',
'content' => [
'text' => 'Your code is: '.$code,
]
]
],
]
];
$data_string = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$this->pm_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$this->pm_login:$this->pm_password");
curl_setopt($ch, CURLOPT_HTTPHEADER,
array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
}