test sms 3

This commit is contained in:
saparatayev 2021-12-23 14:45:06 +05:00
parent aa76a665f3
commit 74d55eee10
3 changed files with 108 additions and 8 deletions

10
config/smpp.php Normal file
View File

@ -0,0 +1,10 @@
<?php
return [
'smpp_service' => 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'),
];

View File

@ -0,0 +1,86 @@
<?php
namespace TPS\Birzha\Classes;
use GsmEncoder;
use Illuminate\Support\Facades\Log;
use SMPP;
use SmppAddress;
use SmppClient;
use SocketTransport;
class SmppTransmitter
{
protected $transport, $client, $credentialTransmitter;
public function __construct()
{
$this->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
}
}
}

View File

@ -1,5 +1,7 @@
<?php
use Illuminate\Support\Facades\Route;
use TPS\Birzha\Classes\SmppTransmitter;
// use October\Rain\Network\Http;
// use October\Rain\Support\Facades\Http as FacadesHttp;
// use Http;
@ -16,6 +18,8 @@ Route::namespace('TPS\Birzha\Controllers')->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);
});