-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheitaa.php
56 lines (50 loc) · 1.73 KB
/
eitaa.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
51
52
53
54
55
56
<?php
// include constants
include "./constants.php";
// eitaa main class
class EitaaPHP {
// properties
public $token;
public $channel_id;
// methods
public function __construct($token, $channel_id) {
$this->token = $token;
$this->channel_id = $channel_id;
}
public function sendMessage($text, $other=[]) {
// send a message to channel
$url = "https://eitaayar.ir/api/$this->token/sendMessage";
$fields = array(
"chat_id" => $this->channel_id,
"text" => $text,
);
$fields += $other;
$request = curl_init($url);
curl_setopt($request, CURLOPT_POST, true);
curl_setopt($request, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($request, CURLOPT_POSTFIELDS, $fields);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($request);
curl_close($request);
return $output;
}
public function sendFile($file_path, $other=[]) {
// send a file to channel
$url = "https://eitaayar.ir/api/$this->token/sendFile";
$fields = array(
'file' => new \CurlFile(realpath($file_path)),
'chat_id' => $this->channel_id,
);
$fields += $other;
$request = curl_init($url);
curl_setopt($request, CURLOPT_POST, true);
curl_setopt($request, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($request, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($request, CURLOPT_POSTFIELDS, $fields);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($request);
curl_close($request);
return $output;
}
}