Files
crm.clientright.ru/erv_ticket/sms-test.php
Fedor 9245768987 🚀 CRM Files Migration & Real-time Features
 Features:
- Migrated ALL files to new S3 structure (Projects, Contacts, Accounts, HelpDesk, Invoice, etc.)
- Added Nextcloud folder buttons to ALL modules
- Fixed Nextcloud editor integration
- WebSocket server for real-time updates
- Redis Pub/Sub integration
- File path manager for organized storage
- Redis caching for performance (Functions.php)

📁 New Structure:
Documents/Project/ProjectName_ID/file_docID.ext
Documents/Contacts/FirstName_LastName_ID/file_docID.ext
Documents/Accounts/AccountName_ID/file_docID.ext

🔧 Technical:
- FilePathManager for standardized paths
- S3StorageService integration
- WebSocket server (Node.js + Docker)
- Redis cache for getBasicModuleInfo()
- Predis library for Redis connectivity

📝 Scripts:
- Migration scripts for all modules
- Test pages for WebSocket/SSE/Polling
- Documentation (MIGRATION_*.md, REDIS_*.md)

🎯 Result: 15,000+ files migrated successfully!
2025-10-24 19:59:28 +03:00

205 lines
7.3 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* ============================================
* SMS-TEST.PHP - Отправка SMS через SigmaSMS API
* ============================================
*
* БЕЗОПАСНОСТЬ: Credentials загружаются из .env
*
* Обновлено: 23.10.2025
*/
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Загрузка конфигурации из .env
require_once __DIR__ . '/config.php';
/* SigmaSMS REST API
* https://online.sigmasms.ru/docs/#/api/HTTP-REST
*/
// Универсальная функция отправки
function apiRequest($first = false, $data = false, $url_path = false, $token = false, $file = false) {
global $token_filename;
$api_url = SMS_API_URL;
$login = SMS_LOGIN;
$pass = SMS_PASSWORD;
// Get Token
if ($first) {
$fields = array(
'username' => $login,
'password' => $pass,
'type' => 'local'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url.'login');
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json; charset=UTF-8"));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $fields ));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$response = curl_exec($ch);
curl_close($ch);
if (!$response) {
$response = json_encode(array('error' => 'true'));
} else {
file_put_contents($token_filename, $response);
}
} elseif ($url_path && $token) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url.$url_path);
if ($file) {
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: ".mime_content_type($data['file']), "Content-length: ".filesize($data['file']), "Authorization: ".$token));
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($data['file']));
} else {
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json;charset=UTF-8", "Accept: application/json", "Authorization: ".$token));
if ($data && is_array($data)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $data ));
}
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$response = curl_exec($ch);
curl_close($ch);
if (!$response) {
$response = json_encode(array('error' => 'true'));
}
}
header("Content-Type: application/json;charset=UTF-8");
return $response;
}
// Авторизация и получение токена
function apiAuth() {
// Название файла для сохранения токена
$token_filename = 'sigmatoken.txt';
// проверяем токен
if (file_exists($token_filename) && (date('Y-m-d H:i:s', filemtime($token_filename)) > date('Y-m-d H:i:s', strtotime('-23 hours')))) {
$result = file_get_contents($token_filename, true);
} else {
$result = apiRequest(true);
}
//
$unjes = json_decode($result);
if (isset($unjes->token) && !empty($unjes->token)) {
$token = (string) $unjes->token;
} else {
$token = null;
}
return $token;
}
//
function clear_phone($phone) {
$phone_number = preg_replace('/[() -]+/', '', $phone);
return $phone_number;
}
// Загрузка файла
function uploadFile($file_path) {
$token = apiAuth();
if ($token) {
$dataFile = array('file' => dirname(__FILE__).'/'.$file_path);
return apiRequest(false, $dataFile, 'storage', $token, true);
}
}
// Отправка одиночного сообщения
function sendOneMess($type, $recipient, $sender, $text, $button = null, $image = null) {
$token = apiAuth();
// Если не удалось получить токен через Auth, используем из .env
if (!$token) {
$token = SMS_TOKEN;
}
if ($token) {
$params = array(
"type" => $type,
"recipient" => clear_phone($recipient),
"payload" => array(
"sender" => $sender,
"text" => $text,
"button" => $button,
"image" => $image
)
);
return apiRequest(false, $params, 'sendings', $token);
}
}
// Отправка каскада
function sendCascade($data) {
$token = apiAuth();
if ($token) {
return apiRequest(false, $data, 'sendings', $token);
}
}
// Проверка статуса
function checkStatus($id) {
if ($id) {
$token = apiAuth();
if ($token) {
return apiRequest(false, false, 'sendings/'.$id, $token);
}
}
}
/* Тесты */
$myphone = $_POST['phonenumber'];
echo 'Тест СМС: '.PHP_EOL;
$sendSms = sendOneMess('sms', $myphone, SMS_SENDER, 'Код подтверждения: '.$_POST['smscode']);
var_dump($sendSms);
// echo PHP_EOL.'Проверка статуса сообщения: '.PHP_EOL;
// var_dump(checkStatus('6035fe28-2f60-4973-8681-jhjh887990087'));
// echo PHP_EOL.'Загрузка картинки: '.PHP_EOL;
// $upload_image = uploadFile('test.png');
// var_dump($upload_image);
// echo 'Проверить корректность загрузки можно по ссылке: https://online.sigmasms.ru/api/storage/{user_id}/{image_key}'.PHP_EOL;
// echo PHP_EOL.'Тест Viber: '.PHP_EOL;
// $msg_image = json_decode($upload_image);
// if (isset($msg_image->key)) {
// var_dump(sendOneMess('viber', $myphone, 'X-City', 'Тест сообщения Viber', array('text' => 'Текст кнопки', 'url' => 'https://google.ru'), $msg_image->key));
// }
// echo PHP_EOL.'Каскадная переотправка VK->Viber->SMS: '.PHP_EOL;
// $cascadeData = array(
// "type" => 'vk',
// "recipient" => clear_phone($myphone),
// "payload" => array(
// "sender" => 'sigmasmsru',
// "text" => 'Тест сообщения ВК',
// ),
// "fallbacks" => [
// array(
// "type" => 'viber',
// "payload" => array(
// "sender" => 'X-City',
// "text" => 'Тест сообщения Viber',
// "image" => $msg_image->key,
// "button" => array(
// "text" => "Текст кнопки",
// "url" => 'https://google.ru',
// ),
// ),
// '$options' => array(
// "onStatus" => ["failed"],
// "onTimeout" => array(
// "timeout" => 120,
// "except" => ["delivered", "seen"]
// )
// )
// ),
// array(
// "type" => "sms",
// "payload" => array(
// "sender" => "SigmaSMS",
// "text" => 'Тест сообщения СМС'
// ),
// '$options' => array(
// "onStatus" => ["failed"],
// "onTimeout" => array(
// "timeout" => 120,
// "except" => ["delivered", "seen"]
// )
// )
// )
// ]
// );
// var_dump(sendCascade($cascadeData));