Notes
![]() ![]() Notes - notes.io |
if (!isset($_REQUEST)) {
return;
}
require 'api/vk_api.php';
function build_data_files($boundary, $fields, $files) {
$data = '';
$eol = "rn";
$delimiter = '-------------' . $boundary;
foreach ($fields as $name => $content) {
$data.= "--" . $delimiter . $eol . 'Content-Disposition: form-data; name="' . $name . """ . $eol . $eol . $content . $eol;
}
foreach ($files as $name => $content) {
$data.= "--" . $delimiter . $eol . 'Content-Disposition: form-data; name="' . $name . '"; filename="' . $name . '"' . $eol
//. 'Content-Type: image/png'.$eol
. 'Content-Transfer-Encoding: binary' . $eol;
$data.= $eol;
$data.= $content . $eol;
}
$data.= "--" . $delimiter . "--" . $eol;
return $data;
}
function _bot_uploadVoiceMessage($user_id, $file_name) {
$upload_server_response = vkApi_docsGetMessagesUploadServer($user_id, 'dpc');
$upload_response = vkApi_upload($upload_server_response['upload_url'], $file_name);
$file = $upload_response['file'];
$save_response = vkApi_docsSave($file, 'finansovy_plan.docx');
$doc = array_pop($save_response);
return $doc;
}
function bot_sendMessage($user_id) {
$users_get_response = vkApi_usersGet($user_id);
$user = array_pop($users_get_response);
$msg = "Привет, {$user['first_name']}!";
// $photo = _bot_uploadPhoto($user_id, BOT_IMAGES_DIRECTORY.'/cat.jpeg');
$voice_message_file_name = yandexApi_getVoice($msg);
$doc = _bot_uploadVoiceMessage($user_id, 'file/finansovy_plan.docx');
$attachments = array(
// 'photo'.$photo['owner_id'].'_'.$photo['id'],
'doc' . $doc['owner_id'] . '_' . $doc['id'],
);
vkApi_messagesSend($user_id, $msg, $attachments);
}
//Строка для подтверждения адреса сервера из настроек Callback API
$confirmationToken = '004eec27';
//Ключ доступа сообщества
$token = '4ee153d983e0a058276f2f52acc0141bae733cf835a9906b00ae54923594975e6044f15b505de4a06e233';
// Secret key
$secretKey = 'Pastarnak';
//Получаем и декодируем уведомление
$data = json_decode(file_get_contents('php://input'));
// проверяем secretKey
if (strcmp($data->secret, $secretKey) !== 0 && strcmp($data->type, 'confirmation') !== 0) return;
switch ($data->type) {
case 'confirmation':
echo $confirmationToken;
break;
case 'message_new':
$message = $data->object->body;
$phone_regex = '/^+{0,1}(d[s-]?)?[([s-]{0,2}?d{3}[)]s-]{0,2}?d{3}[s-]?d{4}$/i';
switch ($message) {
case 'Привет':
$reply = "Добрый день, я - Генадий, менеджер компании Росфризер, буду помогать вам при выборе оборудования и места для Вашего бизнеса!nn Напишите команду 'План' чтобы скачать финансовый план «Как окупить фризер за 2 дня!» nnНапишите команду 'Менеджер' для связи с менеджером";
break;
case 'План':
$reply = "Спасибо вам за обращение!";
$user_id = $data->object->user_id;
// $server = _vkApi_call('docs.getMessagesUploadServer', array('peer_id' => $user_id));
bot_sendMessage($user_id);
$reply = json_encode($server);
// $server = _vkApi_call('docs.getUploadServer', array('130910980'));
// $upload_url = $server->response->upload_url;
// $params = array("file" => realpath('file/finansovy_plan.php'));
// $reply = json_encode($params);
// $request = curl_init($upload_url);
// curl_setopt($request, CURLOPT_POST, true);
// curl_setopt($request,CURLOPT_POSTFIELDS,http_build_query($params));
// curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
// curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
// curl_exec($request);
// curl_close($request);
break;
case 'менеджер':
case 'Менеджер':
case ''менеджер'':
case ''Менеджер'':
case ""менеджер"":
case ""Менеджер"":
$reply = "Введите ваш телефон:";
$r = vkApi_Get();
var_dump($r);
break;
// default:
// if ( preg_match($phone_regex, $message) {
// $reply = 'Спасибо за обращение! мы с вами свяжемся в течении 10 минут.';
// $stmt = $pdo->prepare('SELECT username FROM telegram WHERE username = :name');
// $stmt->bindParam(':name', $name, PDO::PARAM_STR);
// $stmt->execute();
// $res = $stmt->fetch();
// if (empty($res)) {
// $stmt = $pdo->prepare('INSERT INTO telegram (username) VALUES (:name)');
// $stmt->bindParam(':name', $name);
// $stmt->execute();
// }
// }
// $reply = "Добрый день, я - Генадий, менеджер компании Росфризер, буду помогать вам при выборе оборудования и места для Вашего бизнеса!nnНапишите команду 'План' чтобы скачать финансовый план «Как окупить фризер за 2 дня!» nnНапишите команду 'Менеджер' для связи с менеджером";
// break;
}
//...получаем id его автора
$userId = $data->object->user_id;
//затем с помощью users.get получаем данные об авторе
$userInfo = json_decode(file_get_contents("https://api.vk.com/method/users.get?user_ids={$userId}&v=5.0"));
//и извлекаем из ответа его имя
$user_name = $userInfo->response[0]->first_name;
//С помощью messages.send и токена сообщества отправляем ответное сообщение
$request_params = array(
// 'message' => "{$user_name}, ваше сообщение зарегистрировано!<br>".
// "Мы постараемся ответить в ближайшее время.",
'message' => $reply,
'user_id' => $userId,
'access_token' => $token,
'v' => '5.0'
);
$get_params = http_build_query($request_params);
file_get_contents('https://api.vk.com/method/messages.send?' . $get_params);
//Возвращаем "ok" серверу Callback API
echo ('ok');
break;
// Если это уведомление о вступлении в группу
case 'group_join':
//...получаем id нового участника
$userId = $data->object->user_id;
//затем с помощью users.get получаем данные об авторе
$userInfo = json_decode(file_get_contents("https://api.vk.com/method/users.get?user_ids={$userId}&v=5.0"));
//и извлекаем из ответа его имя
$user_name = $userInfo->response[0]->first_name;
//С помощью messages.send и токена сообщества отправляем ответное сообщение
$request_params = array(
'message' => "Добро пожаловать в наше сообщество МГТУ им. Баумана ИУ5 2016, {$user_name}!<br>" . "Если у Вас возникнут вопросы, то вы всегда можете обратиться к администраторам сообщества.<br>" . "Их контакты можно найти в соответсвующем разделе группы.<br>" . "Успехов в учёбе!",
'user_id' => $userId,
'access_token' => $token,
'v' => '5.0'
);
$get_params = http_build_query($request_params);
file_get_contents('https://api.vk.com/method/messages.send?' . $get_params);
//Возвращаем "ok" серверу Callback API
echo ('ok');
break;
}
?>
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team