/** * Tests the `Client::sendMessage()` method. */ public function testSendMessage() { $client = new Client(['username' => '', 'password' => '']); $this->assertFalse($client->sendMessage('Hello World!')); $client = new Client(['username' => 'anonymous', 'password' => 'secret']); $this->assertFalse($client->sendMessage('')); if (is_string($username = getenv('FREEMOBILE_USERNAME')) && is_string($password = getenv('FREEMOBILE_PASSWORD'))) { $client = new Client(['username' => $username, 'password' => $password]); $this->assertTrue($client->sendMessage('Bonjour Cédric !')); } }
public function run() { $log = new Logging(); // $parenClass = new ParentClass(); // set path and name of log file (optional) $log->lfile('log.txt'); $json = file_get_contents('php://input'); $log->lwrite("post: " . $json); $update = new Update($json); $message = $update->getMessage(); $chat = $message->getChat(); $chat_id = $chat->getId(); $text = $message->getText(); $client = new Client(); $client->sendMessage($chat_id, $text, null, null, null); $client->sendLocation($chat_id, 53.480759, -2.242631, null, null); $client->sendPhoto($chat_id, 'pic.jpg', 'sweety', null, null); $log->lclose(); }
{ private $sockFile; private $socket; private $serverId; public function __construct($serverId) { $key = ftok(__DIR__ . '/queue', 'R'); $this->queue = msg_get_queue($key, 0777); $this->serverId = $serverId; } public function sendMessage($data) { //Generate a random ID for this request $id = rand(); $message = [$id, $data]; msg_send($this->queue, $this->serverId, $message, true, false); msg_receive($this->queue, $id, $msgtype, 1000000, $msg, true); foreach ($msg[0] as $header) { header($header); } return $msg[1]; } } session_start(); if (!isset($_SESSION['__appserverId'])) { $_SESSION['__appserverId'] = 100 + rand(0, 23); } $client = new Client($_SESSION['__appserverId']); session_write_close(); echo $client->sendMessage(['sessionId' => session_id(), 'get' => $_GET, 'post' => $_POST, 'server' => $_SERVER, 'files' => $_FILES, 'cookie' => $_COOKIE]);