Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to SEND/Retrieve SMS from GOIP

Is there a way for a PHP or VB.net to retrieve/send sms on GOIP (sms-gateway) without accessing it built in Web Manager?.

The said device is using UDP port 44444.

like image 490
reiwin462 Avatar asked Sep 06 '25 07:09

reiwin462


2 Answers

This script is only to send SMS via php on a GOIP VOIP GATEWAY

<?php
$rand = rand();
$url = 'http://goip-ip-adress-here/default/en_US/sms_info.html';
$line = '1'; // sim card to use in my case #1
$telnum = '1230000000'; // phone number to send sms
$smscontent = 'this is a test sms'; //your message
$username = "admin"; //goip username
$password = "1234"; //goip password

$fields = array(
'line' => urlencode($line),
'smskey' => urlencode($rand),
'action' => urlencode('sms'),
'telnum' => urlencode($telnum),
'smscontent' => urlencode($smscontent),
'send' => urlencode('send')
);

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_PORT, 80);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

//execute post
echo curl_exec($ch);
echo curl_getinfo($ch);

//close connection
curl_close($ch);
?>
like image 100
paisapimp Avatar answered Sep 10 '25 02:09

paisapimp


Premised on @paisapimp answer I wrote this class for sending SMS in PHP and it works. Only issue is returning a sent or failed response. I'll fix that and update this answer sometime.. soon I hope. Compliments of the season!

<?php

class GoIP{
    public $ip = 'http://your.server.ip/default/en_US/sms_info.html';
    public $uname = 'GoIPusername';
    public $pwd = 'GoIPpassword';

    function sendSMS($num, $msg, $line=1){
        $rand = rand();
        $fields = [
            'line' => urlencode($line),
            'smskey' => urlencode($rand),
            'action' => urlencode('sms'),
            'telnum' => urlencode($num),
            'smscontent' => urlencode($msg),
            'send' => urlencode('send')
        ];

        //url-ify the data for the POST
        $fields_string = "";
        foreach($fields as $key=>$value) { 
            $fields_string .= $key.'='.$value.'&'; 
        }
        rtrim($fields_string, '&');

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $this->ip);
        curl_setopt($ch, CURLOPT_USERPWD, "{$this->uname}:{$this->pwd}");
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($ch, CURLOPT_PORT, 80);
        curl_setopt($ch, CURLOPT_POST, count($fields));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);

        curl_exec($ch);
        curl_getinfo($ch);

        curl_close($ch);

    }

    function sendBulkSMS($nums=[], $msg, $line=1){
        foreach($nums as $i=>$num){
            self::sendSMS($num, $msg, $line);
        }
    }
}
like image 43
Sunday Ikpe Avatar answered Sep 10 '25 02:09

Sunday Ikpe