I use the SMPP protocol to send messages in a Laravel project, as you can see in this code, I manage to establish the socket with the server, but I cannot authenticate myself on the server, while my information is correct.
I need your help to authenticate me on the server.
Here is the response from the server:
Authentication failed. Server response: �
previously it gave me this message
Server response:\x00\x00\x00\x10€\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00"
I use the php-smpp library
Here is the controller in question which allows the creation of the socket and the authentication on the server. I would like to be able to authenticate myself on the server.
<?php
namespace App\Http\Controllers;
use SMPP;
use Exception;
use GsmEncoder;
use SmppClient;
use SmppAddress;
use SocketTransport;
use Illuminate\Support\Facades\Log;
class apiSmsSmppController extends Controller {
function sendSmsSmpp($message, $to) {
$host = 'xxx.xxx.xx.xx';
$port = xxxx;
$from = "Net4Work";
$systemId = "xxxxxx";
$password = "xxxxxx";
// Création de la socket
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
// Gestion de l'erreur
$error = socket_strerror(socket_last_error());
die("Failed to create socket: $error");
}
// Connexion à la socket du serveur
$result = socket_connect($socket, $host, $port);
if ($result === false) {
// Gestion de l'erreur
$error = socket_strerror(socket_last_error($socket));
die("Failed to connect to $host:$port: $error");
}
// La connexion a réussi
//echo "Connected to $host:$port";
// Envoi des informations d'authentification au serveur
$authData = pack('a'.strlen($systemId).'ca'.strlen($password).'ca1', $systemId, 0x02, $password, 0x00, 0x00);
$result = socket_write($socket, $authData, strlen($authData));
if ($result === false) {
// Gestion de l'erreur
$error = socket_strerror(socket_last_error($socket));
die("Failed to send authentication data: $error");
}
// Réception de la réponse du serveur
$response = socket_read($socket, 1024);
if ($response === false) {
// Gestion de l'erreur
$error = socket_strerror(socket_last_error($socket));
die("Failed to receive server response: $error");
}
// Vérification de la réponse du serveur pour confirmer l'authentification
$commandStatus = unpack('N', substr($response, 4, 4))[1];
if ($commandStatus !== 0x00000000) {
// L'authentification a échoué
die("Authentication failed. Server response: $response");
}
// L'authentification a réussi
dd("Authentication successful. Server response: $response");
}
}
I can't comment for now (not enough reputation), Why don't you use kannel to connect you to SMPP server and then just use CURL to call the endpoint kannel gaves you for sending SMS? That seems much much easier and that is what I do