Community discussions

 
botter911
just joined
Topic Author
Posts: 3
Joined: Sat Oct 06, 2012 9:08 pm

Simple PHP check

Sun Oct 07, 2012 12:25 pm

Hi guys, I cannot get this script to work. Can you please tell me where i went wrong?

<?php require_once("routeros_api.class.php");

/**** Function to send SMS via Mikrotik SMS Gateway ***/
function send_sms($number, $text) {

global $smsgw;
$API = new routeros_api();
if ($API->connect("192.168.88.1", "admin", "admin")) {


$API->comm("tool sms send usb2 channel=3 phone-number=1234 message=test");
} else {
echo "error";
return "could not connect to mikrotik gateway";
}


}

send_sms("1234", "test");

?>
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2411
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Simple PHP check

Mon Oct 08, 2012 7:30 pm

The API protocol uses a very different syntax from the shell.

Using the client from my signature, you can use a shell-like syntax... the main difference being that you must explicitly specify ALL argument names. In your case, that would be:
<?php
namespace PEAR2\Net\RouterOS;
require_once 'PEAR2_Net_RouterOS-1.0.0b3.phar';

/**** Function to send SMS via Mikrotik SMS Gateway ***/
function send_sms($number, $text) {
    global $smsgw;
    try {
        $API = new Client("192.168.88.1", "admin", "admin");

        $API->sendSync(new Request("/tool sms send port=usb2 channel=3 phone-number=1234 message=test"));
    } catch (Exception $e) {
        echo "error";
        return "could not connect to mikrotik gateway";
    }
}

send_sms("1234", "test"); 
And if you want to use your current client, you'll have to follow the API syntax, per the spec.

(Side note: On my RouterOS, the phone number is specified with the "dst" argument, not the "phone-number" argument... what RouterOS version are you using?)
PEAR2_Net_RouterOS(1.0.0b6) - My API client in PHP
(Rate my posts? If you want... no pressure...)
 
wencs
just joined
Posts: 10
Joined: Wed Mar 26, 2014 7:14 pm

Re: Simple PHP check

Mon Oct 31, 2016 12:23 pm

Hi guys, I cannot get this script to work. Can you please tell me where i went wrong?

yo lo e resuelto de la siguiente manera:

<?php
require(PATH_BASE.'/dist/api/mikrotik/routeros_api.class.php');
function send_sms($number, $text) {
global $smsgw;
$server = '192.168.1.1';
$loginname = 'user_admin';
$password = 'password';
$artv_puerto = 8728;
$modeom = array();
$API = new routeros_api();
$API->debug = false;
$API->port = $artv_puerto;
if ($API->connect($server, $loginname, $password)) {
$comandomk='/tool/sms/send';
$modeom['port']='usb3';
$modeom['channel']=2;
$modeom['phone-number']=$number;
$modeom['message']=$text." a las ".$time1;
}
$resultado=$API->comm($comandomk,$modeom);
if (is_array($resultado)) {
if (isset($resultado['!trap'][0]['message']) ) {
$message = $resultado['!trap'][0]['message'];
print "Error: ".$message;
}else{
print "<br/>mensaje enviado con exito";
}
}
$API->disconnect();
}
$numero= "+584142351570";
$Empresa ="Finandanzas Telecom, CA. ";
send_sms($numero, "Estimado cliente hemos recibido su pago por un monto de 3900,00 el recibo sera enviado a su correo ".$Empresa);
?>

Who is online

Users browsing this forum: MSN [Bot] and 22 guests