From 74d55eee10c24973d748c44680ed5feae7f026ef Mon Sep 17 00:00:00 2001 From: saparatayev Date: Thu, 23 Dec 2021 14:45:06 +0500 Subject: [PATCH] test sms 3 --- config/smpp.php | 10 +++ .../tps/birzha/classes/SmppTransmitter.php | 86 +++++++++++++++++++ plugins/tps/birzha/routes.php | 20 +++-- 3 files changed, 108 insertions(+), 8 deletions(-) create mode 100644 config/smpp.php create mode 100644 plugins/tps/birzha/classes/SmppTransmitter.php diff --git a/config/smpp.php b/config/smpp.php new file mode 100644 index 000000000..9e1c5130a --- /dev/null +++ b/config/smpp.php @@ -0,0 +1,10 @@ + env('SMPP_SERVICE'), + 'smpp_port' => env('SMPP_PORT'), + 'smpp_receiver_id' => env('SMPP_RECEIVER_ID'), + 'smpp_receiver_password' => env('SMPP_RECEIVER_PASSWORD'), + 'smpp_transmitter_id' => env('SMPP_TRANSMITTER_ID'), + 'smpp_transmitter_password' => env('SMPP_TRANSMITTER_PASSWORD'), +]; \ No newline at end of file diff --git a/plugins/tps/birzha/classes/SmppTransmitter.php b/plugins/tps/birzha/classes/SmppTransmitter.php new file mode 100644 index 000000000..0ecc4e8bf --- /dev/null +++ b/plugins/tps/birzha/classes/SmppTransmitter.php @@ -0,0 +1,86 @@ +connect(); + } + + protected function connect() { + // Create transport + $this->transport = new SocketTransport([config('smpp.smpp_service')], config('smpp.smpp_port')); + $this->transport->setRecvTimeout(30000); + $this->transport->setSendTimeout(30000); + + // Create client + $this->client = new SmppClient($this->transport); + + // Activate binary hex-output of server interaction + $this->client->debug = true; + $this->transport->debug = true; + + // Open the connection + $this->transport->open(); + + // Bind transmitter + $this->client->bindTransmitter(config('smpp.smpp_transmitter_id'), config('smpp.smpp_transmitter_password')); + } + + protected function disconnect() { + if (isset($this->transport) && $this->transport->isOpen()) { + if (isset($this->client)) { + try { + $this->client->close(); + } catch (\Exception $e) { + $this->transport->close(); + } + } else { + $this->transport->close(); + } + } + } + + public function keepAlive() + { + $this->client->enquireLink(); + $this->client->respondEnquireLink(); + } + + public function respond() + { + $this->client->respondEnquireLink(); + } + + public function sendSms($message, $from, $to) { + // Check if all parameters present + if (!isset($message) || !isset($from) || !isset($to)) { + // Handle missing parameters + } + + // Encode parameters + $encodedMessage = GsmEncoder::utf8_to_gsm0338($message); + $fromAddress = new SmppAddress($from, SMPP::TON_ALPHANUMERIC); + $toAddress = new SmppAddress($to, SMPP::TON_INTERNATIONAL, SMPP::NPI_E164); + + // Try to send message and catch exception + try { + $this->client->sendSMS($fromAddress, $toAddress, $encodedMessage); + return; + } catch (\Exception $e) { + Log::error($e); + Log::error($e->getMessage()); + // Handle failed message send + } + } +} \ No newline at end of file diff --git a/plugins/tps/birzha/routes.php b/plugins/tps/birzha/routes.php index e5c521859..6175ba5a2 100644 --- a/plugins/tps/birzha/routes.php +++ b/plugins/tps/birzha/routes.php @@ -1,5 +1,7 @@ group(function () { // Route::get('bank_result/{payment_id}', ['as'=>'paymentReturn','uses'=>'...@checkPayment'] ); Route::get('check-sms', function() { + $transmitter = new SmppTransmitter(); + $transmitter->sendSms('Hello from transmitter :)', '0773', '+99365611968'); // $response = \Http::withHeaders([ // 'Content-Type' => 'application/json' @@ -40,29 +44,29 @@ Route::get('check-sms', function() { // dd($client->send()); - - $response = \Http::post('http://217.174.228.218:5019/auth/jwt/create', function($http){ + + // $response = \Http::post('http://217.174.228.218:5019/auth/jwt/create', function($http){ // Sets a HTTP header - $http->header('Content-Type', 'application/json'); + // $http->header('Content-Type', 'application/json'); // Use basic authentication - $http->auth('birja', 'Birj@1'); + // $http->auth('birja', 'Birj@1'); // Sends data with the request // $http->data('foo', 'bar'); // $http->data(['key' => 'value', ...]); // Sets the timeout duration - $http->timeout(3600); + // $http->timeout(3600); // Sets a cURL option manually // $http->setOption(CURLOPT_SSL_VERIFYHOST, false); - })->throw()->json(); + // })->throw()->json(); - $accessToken = $response['access']; + // $accessToken = $response['access']; - dd($accessToken); + // dd($accessToken); });