Spade
Mini Shell
<?php
class telegram{
public function __construct(){
require_once __DIR__.'/db.php';
$this->database= new db();
$this ->token=
'5683832850:AAFf8h66ntdeKh0iYTyDFCzKVX7EdUVV5KM';
$update= file_get_contents('php://input');
$update= json_decode($update);
$this->define_msg_type($update);
$this->start();
// $filename = __DIR__ . "/log.txt";
//file_put_contents($filename, "update = " .
print_r($update, true)."\n", FILE_APPEND);
// file_put_contents($filename, "chatid = " .
print_r($this->chatid, true)."\n", FILE_APPEND);
// file_put_contents($filename, "text = " .
print_r($this->text, true)."\n", FILE_APPEND);
}
public function define_msg_type($update){
if (isset($update->message)){
$this->msg_type= 'message';
$this->chatid= $update->message->from->id;
$this->text= $update->message->text;
$this->value= explode('.', $this->text, 2)[1];
}
elseif(isset($update->edited_message)){
$this->msg_type= 'edited_message';
$this->chatid= $update->edited_message->from->id;
$this->text= $update->edited_message->text;
$this->value= explode('.', $this->text, 2)[1];
}
elseif(isset($update->callback_query)){
$this->msg_type= 'callback_query';
$this->chatid= $update->callback_query->from->id;
$this->text= $update->callback_query->data;
$this->value= explode('.', $this->text, 2)[1];
}
}
public function send($method, $data){
$url = "https://api.telegram.org/bot{$this->token}/".
$method;
if (!$curld = curl_init()) {
exit;
}
curl_setopt($curld, CURLOPT_POST, true);
curl_setopt($curld, CURLOPT_POSTFIELDS, $data);
curl_setopt($curld, CURLOPT_URL, $url);
curl_setopt($curld, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($curld);
curl_close($curld);
return $output;
}
public function send_params_1(){
$parameters =
array(
'chat_id' => $this->chatid,
'text' => "خوش آمدید
لطفا نام و نام خانوادگی خود را با فرمت
(*ن.نام و نام خانوادگی*) ارسال کنید
مثال : *ن.سید علیرضا یکتا*",
'parse_mode' => 'Markdown'
);
$parameters0 =
array(
'chat_id' => $this->chatid,
'text' => "توجه : در صورت
ارسال اطلاعات اشتباه ، مراحل تکمیل فرم را
تا انتها طی کرده و سپس برای تصحیح اشتباه
رخ داده گزینه (میخواهم فرم را مجدد پر کنم)
را بزنید و با پر کردن مجدد فرم اشتباه خود
را تصحیح نمایید"
);
$this->send('sendMessage', $parameters0);
$this->send('sendMessage', $parameters);
}
public function send_params_2(){
$res= $this->database->query(null,'ioru', null,
['chatid'=>$this->chatid, 'name'=>
$this->value]);
$keyboard = [
'inline_keyboard' => [
[
['text' => 'forward me to
groups', 'callback_data' => 'someString']
]
]
];
$encodedKeyboard = json_encode($keyboard);
$parameters =
array(
'chat_id' => $this->chatid,
'text' => "لطفا شماره تلفن
خود را با فرمت
(*ش.شماره*) ارسال کنید
مثال : *ش.09121234567*",
'parse_mode' => 'Markdown'
);
$this->send('sendMessage', $parameters);
}
public function send_params_3(){
$res= $this->database->query(null,'ioru', null,
['chatid'=>$this->chatid, 'mobile'=>
$this->value]);
$keyboard = [
'inline_keyboard' => [
[
['text' => 'forward me to
groups', 'callback_data' => 'someString']
]
]
];
$encodedKeyboard = json_encode($keyboard);
$parameters =
array(
'chat_id' => $this->chatid,
'text' => "اگر ایمیل دارید
آن را با فرمت
(*ایمیل.آدرس ایمیل*) ارسال کنید
مثال : *ایمیل.example@gmail.com*
و اگر ایمیل ندارید متنی با فرمت
(*ایمیل.ندارم*) ارسال کنید
مثال : *ایمیل.ندارم*",
'parse_mode' => 'Markdown'
);
$this->send('sendMessage', $parameters);
}
public function send_params_4(){
$res= $this->database->query(null,'ioru', null,
['chatid'=>$this->chatid, 'email'=>
$this->value]);
$keyboard = [
'inline_keyboard' => [
[
['text' => 'ندارم',
'callback_data' =>'ticket.0'],
['text' => 'دارم',
'callback_data' =>'ticket.1']
]
]
];
$encodedKeyboard = json_encode($keyboard);
$parameters =
array(
'chat_id' => $this->chatid,
'text' => "بلیط بازی
فوتبال",
'reply_markup' => $encodedKeyboard
);
$this->send('sendMessage', $parameters);
}
public function send_params_5(){
$res= $this->database->query(null,'ioru', null,
['chatid'=>$this->chatid, 'ticket'=>
(int)$this->value]);
$keyboard = [
'inline_keyboard' => [
[
['text' => 'رایزنی فرهنگی
جمهوری اسلامی ایران در قطر',
'callback_data' =>'receive.1']
],
[
['text' => 'سرپرست مدارس
ایرانیان در قطر', 'callback_data'
=>'receive.2']
],
[
['text' => 'سفارت جمهوری
اسلامی ایران', 'callback_data'
=>'receive.3']
]
]
];
$encodedKeyboard = json_encode($keyboard);
$parameters =
array(
'chat_id' => $this->chatid,
'text' => "محل دریافت بسته
فرهنگی",
'reply_markup' => $encodedKeyboard
);
$this->send('sendMessage', $parameters);
}
public function send_params_6(){
$this->database->query(null,'ioru', null,
['chatid'=>$this->chatid, 'receive'=>
$this->value]);
$sql= "select * from users where
chatid=".$this->chatid;
$res= $this->database->query($sql,'r',
'one');
$keyboard = [
'inline_keyboard' => [
[
['text' => 'تایید نهایی
اطلاعات', 'callback_data' =>'ok']
],
[
['text' => 'میخواهم فرم
را مجدد پر کنم', 'callback_data'
=>'/start']
]
]
];
$encodedKeyboard = json_encode($keyboard);
$ticket= [0=>'ندارم', 1=>
'دارم'];
$receive= [1=> 'رایزنی فرهنگی جمهوری
اسلامی ایران در قطر',2=> 'سرپرست
مدارس ایرانیان در قطر', 3=> 'سفارت
جمهوری اسلامی ایران'] ;
$text= "تایید نهایی اطلاعات
نام و نام خانوادگی : {$res['name']}
شماره تلفن : {$res['mobile']}
ایمیل : {$res['email']}
بلیط بازی فوتبال : {$ticket[$res['ticket']]}
محل دریافت بسته فرهنگی :
{$receive[$res['receive']]}";
$parameters =
array(
'chat_id' => $this->chatid,
'text' => $text,
'reply_markup' => $encodedKeyboard
);
$this->send('sendMessage', $parameters);
}
public function send_params_7(){
$parameters =
array(
'chat_id' => $this->chatid,
'text' => "اطلاعات شما با
موفقیت ثبت شد"
);
$this->send('sendMessage', $parameters);
$sql= "select * from users where
chatid=".$this->chatid;
$res= $this->database->query($sql,'r',
'one');
$ticket= [0=>'ندارم', 1=>
'دارم'];
$receive= [1=> 'رایزنی فرهنگی جمهوری
اسلامی ایران در قطر',2=> 'سرپرست
مدارس ایرانیان در قطر', 3=> 'سفارت
جمهوری اسلامی ایران'] ;
$text= "نام و نام خانوادگی :
{$res['name']}
شماره تلفن : {$res['mobile']}
ایمیل : {$res['email']}
بلیط بازی فوتبال : {$ticket[$res['ticket']]}
محل دریافت بسته فرهنگی :
{$receive[$res['receive']]}";
$parameters =
array(
'chat_id' => '@fsharmchannel',
'text' => $text
);
$this->send('sendMessage', $parameters);
}
public function def(){
$parameters =
array(
'chat_id' => $this->chatid,
'text' => "لطفا اطلاعات را
با فرمت خواسته شده وارد نمایید"
);
$this->send('sendMessage', $parameters);
}
public function start(){
switch( trim(explode(".",$this->text,2)[0]) ){
case '/start':
$this->send_params_1();
break;
case 'ن':
$this->send_params_2();
break;
case 'ش':
$this->send_params_3();
break;
case 'ایمیل':
$this->send_params_4();
break;
case 'ticket':
$this->send_params_5();
break;
case 'receive':
$this->send_params_6();
break;
case 'ok':
$this->send_params_7();
break;
default:
$this->def();
}
}
}
$obj= new telegram;
class db
{
public function __construct()
{
$servername = "localhost";
$username = "hanioir_fsharm";
$password = "j?sRP93MGS8P";
try {
$this->conn = new
PDO("mysql:host=$servername;dbname=hanioir_fsharm", $username,
$password);
// set the PDO error mode to exception
$this->conn->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
$this->conn->exec("set names utf8mb4");
//echo "Connected successfully";
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
}
public function query($sql, $type = 'r', $fetch =
'all', $data = null)
{
if ($type == 'r') {
$stmt = $this->conn->query($sql);
if ($fetch == 'all') {
return $stmt->fetchAll(PDO::FETCH_ASSOC);
} elseif ($fetch == 'one') {
return $stmt->fetch(PDO::FETCH_ASSOC);
}
} elseif ($type == 'ioru') {
$sql = 'select id from users where chatid=' .
$data['chatid'];
$res = $this->query($sql, 'r', 'one');
if (empty($res)) {
$sql = "INSERT INTO users (" .
array_keys($data)[0] . "," . array_keys($data)[1] . ")
VALUES (?,?)";
$stmt = $this->conn->prepare($sql);
return $stmt->execute(array_values($data));
} else {
$sql = "UPDATE users SET " . array_keys($data)[1]
. "=? WHERE chatid=?";
$stmt = $this->conn->prepare($sql);
return $stmt->execute([array_values($data)[1],
array_values($data)[0]]);
}
}
}
}
$a= array(
'chat_id' => $this->chatid,
'text' => "خوش آمدید
لطفا نام و نام خانوادگی خود را با فرمت
(*ن.نام و نام خانوادگی*) ارسال کنید
مثال : *ن.سید علیرضا یکتا*",
'parse_mode' => 'Markdown'
);
$b=array(
'chat_id' => $this->chatid,
'text' => "لطفا شماره تلفن خود را
با فرمت
(*ش.شماره*) ارسال کنید
مثال : *ش.09121234567*",
'parse_mode' => 'Markdown'
);
$c=array(
'chat_id' => $this->chatid,
'text' => "اگر ایمیل دارید آن را
با فرمت
(*ایمیل.آدرس ایمیل*) ارسال کنید
مثال : *ایمیل.example@gmail.com*
و اگر ایمیل ندارید متنی با فرمت
(*ایمیل.ندارم*) ارسال کنید
مثال : *ایمیل.ندارم*",
'parse_mode' => 'Markdown'
);
$keyboard = [
'inline_keyboard' => [
[
['text' => 'ندارم',
'callback_data' =>'football.0'],
['text' => 'دارم',
'callback_data' =>'football.1']
]
]
];
$keyboard2 = [
'inline_keyboard' => [
[
['text' => 'رایزنی فرهنگی
جمهوری اسلامی ایران در قطر',
'callback_data' =>'receive.1']
],
[
['text' => 'سرپرست مدارس
ایرانیان در قطر', 'callback_data'
=>'receive.2']
],
[
['text' => 'سفارت جمهوری
اسلامی ایران', 'callback_data'
=>'receive.3']
]
]
];
$keyboard3 = [
'inline_keyboard' => [
[
['text' => 'تایید نهایی
اطلاعات', 'callback_data' =>'ok']
],
[
['text' => 'میخواهم فرم را
مجدد پر کنم', 'callback_data'
=>'/start']
]
]
];
$keyboard4 = [
'inline_keyboard' => [
[
['text' => 'رایزنی فرهنگی
جمهوری اسلامی ایران در قطر',
'callback_data' =>'receive.1']
],
[
['text' => 'سرپرست مدارس
ایرانیان در قطر', 'callback_data'
=>'receive.2']
],
[
['text' => 'سفارت جمهوری
اسلامی ایران', 'callback_data'
=>'receive.3']
]
]
];
$ticket= [0=>'ندارم', 1=> 'دارم'];
$receive= [1=> 'رایزنی فرهنگی جمهوری اسلامی
ایران در قطر',2=> 'سرپرست مدارس
ایرانیان در قطر', 3=> 'سفارت جمهوری
اسلامی ایران'] ;
$text= "نام و نام خانوادگی : {$res['name']}
شماره تلفن : {$res['mobile']}
ایمیل : {$res['email']}
بلیط بازی فوتبال : {$ticket[$res['ticket']]}
محل دریافت بسته فرهنگی :
{$receive[$res['receive']]}";