How to SEND/Retrieve SMS from GOIP

自古美人都是妖i 提交于 2019-12-08 02:58:30

问题


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.


回答1:


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);
?>



回答2:


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);
        }
    }
}


来源:https://stackoverflow.com/questions/28941059/how-to-send-retrieve-sms-from-goip

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!