forked from coucounco/salto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
207 additions
and
111 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# Changelog | ||
|
||
All notable changes to `:package_name` will be documented in this file | ||
All notable changes to `rohsyl/salto` will be documented in this file | ||
|
||
## 1.0.0 - 201X-XX-XX | ||
## 1.0.0 - 2022-11-10 | ||
|
||
- initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace rohsyl\Salto\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use rohsyl\Salto\Message\EncodeMobileMessage; | ||
use rohsyl\Salto\SaltoClient; | ||
use Carbon\Carbon; | ||
|
||
class SaltoClientCommand extends Command | ||
{ | ||
|
||
protected $signature = 'salto:client'; | ||
|
||
public function handle() { | ||
|
||
$this->info('Salto Socket Client [Started]'); | ||
|
||
$client = new SaltoClient('127.0.0.1', 10001); | ||
$client->openSocketConnection(); | ||
|
||
if(!$client->isReady()) return; // TODO wait if not ready ? | ||
echo "ready\n"; | ||
|
||
$message = (new EncodeMobileMessage()) | ||
->phone('+41774539943') // #1 | ||
->for('101'); // #2 | ||
|
||
echo "Message : " . $message->toString() . "\n"; | ||
|
||
$response = $client->sendMessage( | ||
$message | ||
); | ||
|
||
// ... do something with | ||
// $response ... | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace rohsyl\Salto\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
|
||
class SaltoServerCommand extends Command | ||
{ | ||
|
||
protected $signature = 'salto:server'; | ||
|
||
public function handle() { | ||
|
||
$this->info('Salto Socket Server [Started]'); | ||
|
||
error_reporting(E_ALL); | ||
|
||
/* Allow the script to hang around waiting for connections. */ | ||
set_time_limit(0); | ||
|
||
/* Turn on implicit output flushing so we see what we're getting | ||
* as it comes in. */ | ||
ob_implicit_flush(); | ||
|
||
$address = '127.0.0.1'; | ||
$port = 10001; | ||
|
||
if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) { | ||
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n"; | ||
} | ||
|
||
if (socket_bind($sock, $address, $port) === false) { | ||
echo "socket_bind() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n"; | ||
} | ||
|
||
if (socket_listen($sock, 5) === false) { | ||
echo "socket_listen() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n"; | ||
} | ||
|
||
do { | ||
if (($msgsock = socket_accept($sock)) === false) { | ||
echo "socket_accept() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n"; | ||
break; | ||
} | ||
/* Send instructions. | ||
$msg = "\nWelcome to the PHP Test Server. \n" . | ||
"To quit, type 'quit'. To shut down the server type 'shutdown'.\n"; | ||
socket_write($msgsock, $msg, strlen($msg));*/ | ||
|
||
do { | ||
if (false === ($buf = socket_read($msgsock, 2048, PHP_NORMAL_READ))) { | ||
echo "socket_read() failed: reason: " . socket_strerror(socket_last_error($msgsock)) . "\n"; | ||
break 2; | ||
} | ||
if (!$buf = trim($buf)) { | ||
continue; | ||
} | ||
if ($buf == 0x05) { | ||
socket_write($msgsock, 0x06); | ||
} | ||
if($buf[0] == 0x02) { | ||
|
||
echo 'STX' . "\n"; | ||
|
||
socket_write($msgsock, 0x06); | ||
|
||
socket_write($msgsock, join(0xB3, [ | ||
0x02, 'CNM', '+41774539943', '101', 0x03 | ||
])); | ||
} | ||
if ($buf == 'shutdown') { | ||
socket_close($msgsock); | ||
break 2; | ||
} | ||
//$talkback = "PHP: You said '$buf'.\n"; | ||
//socket_write($msgsock, $talkback, strlen($talkback)); | ||
echo "$buf\n"; | ||
} while (true); | ||
} while (true); | ||
|
||
socket_close($sock); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace rohsyl\Salto\Response; | ||
|
||
use rohsyl\Salto\Salto; | ||
use rohsyl\Salto\SaltoClient; | ||
|
||
class Response | ||
{ | ||
public static function Ack() { | ||
return new self(SaltoClient::ACK); | ||
} | ||
|
||
public static function Nak() { | ||
return new self(SaltoClient::NAK); | ||
} | ||
|
||
protected $rawResponse; | ||
protected $checksum; | ||
|
||
public function __construct($rawResponse, $checksum = null) | ||
{ | ||
$this->rawResponse = $rawResponse; | ||
$this->checksum = $checksum; | ||
} | ||
|
||
public function isAck() { | ||
return $this->rawResponse === SaltoClient::ACK; | ||
} | ||
|
||
public function isNak() { | ||
return $this->rawResponse === SaltoClient::NAK; | ||
} | ||
|
||
public function isMessage() { | ||
return $this->rawResponse[0] === SaltoClient::STX; | ||
} | ||
|
||
public function raw() { | ||
return $this->rawResponse; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.