-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest.php
More file actions
36 lines (31 loc) · 1.02 KB
/
Copy pathrequest.php
File metadata and controls
36 lines (31 loc) · 1.02 KB
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
<?php
class APIRequest
{
private $baseUrl;
private $token;
function __construct($baseUrl, $token)
{
$this->baseUrl = $baseUrl;
$this->token = $token;
}
private function post($uri, $data)
{
$url = sprintf("http://%s/api/%s?token=%s", $this->baseUrl, $uri, $this->token);
$headers = ['Content-Type: application/json; charset=utf-8'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
function sendMessage($toUser, $content)
{
return $this->post("v1/chat/sendText", json_encode(["toUser" => $toUser, "content" => $content]));
}
}