-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfunc.class.php
129 lines (87 loc) · 1.92 KB
/
func.class.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/*
*
** @httd1 - t.me/httd1 (Telegram)
** https://github.com/httd1
*
*
*/
class Tlg {
function __construct ($token){
$this->tokenBot=$token;
}
public function chat_id (){
$chatID=@$this->data ()->message->chat->id;
return $chatID;
}
public function username (){
$username=@$this->data ()->message->from->username;
return $username;
}
public function name (){
$nome=@$this->data ()->message->from->first_name;
return $nome;
}
public function text (){
$texto=@$this->data ()->message->text;
return $texto;
}
public function lang ($lang=''){
if ($lang != ''){
return $lang;
}
$lang=@strtolower ($this->data ()->message->from->language_code);
if (isset ($lang)){
list ($language)=explode ('-', $lang);
return $language;
}else {
// Linguagem padrão se não existir "language_code"
return 'pt';
}
}
public function type (){
$chatType=@$this->data ()->message->chat->type;
return $chatType;
}
public function data (){
$data=file_get_contents ('php://input');
$json=json_decode ($data);
return $json;
}
/*
*
** Seta uma URL de Webhook na API do Telegram.
*
** @param $url (string)
*
** @return Retorna um Objeto JSON.
*/
public function SetWebhook ($url){
$url=strtolower (trim ($url));
$api=$this->APITelegram ('setWebhook', [
'url' => $url
]);
return json_decode ($api);
}
/*
*
** Envia requisição POST para a API do Telegram.
*
** @param $method (string)
** @param $param (array)
*
** @return Retorna um Objeto JSON.
*
*/
public function APITelegram ($method, $param){
$query=$param;
$api='https://api.telegram.org/bot'.$this->tokenBot.'/'.$method;
$cURL=curl_init ($api);
curl_setopt ($cURL, CURLOPT_POST,true);
curl_setopt ($cURL, CURLOPT_POSTFIELDS, ($query));
curl_setopt ($cURL, CURLOPT_RETURNTRANSFER,true);
$ret=curl_exec ($cURL);
curl_close ($cURL);
return json_decode ($ret);
}
}