如何从GOIP发送/检索短信

时间:2015-03-09 11:36:30

标签: sms sms-gateway

PHP或VB.net是否有办法在GOIP(sms-gateway)上检索/发送短信而无需访问内置在Web Manager中的短信?

所述设备使用的是UDP端口44444.

4 个答案:

答案 0 :(得分:4)

此脚本仅用于在GOIP VOIP GATEWAY上通过php发送短信

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

答案 1 :(得分:1)

以@paisapimp为例进行回答我写了这个用PHP发送短信的课程,它有效。唯一的问题是返回已发送或失败的响应。我会解决这个问题并在某个时候更新这个答案..很快我希望。赞美赛季!

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

答案 2 :(得分:1)

发送短信http://192.168.0.31/default/en_US/send.html?u=admin&p=passssssss&l=2&n=911&m=messagebody

从GOIP检索短信:https://github.com/cjzamora/goip-sms-gateway

状态并读取usd:http://192.168.0.31/default/en_US/send_status.xml?u=admin&p=passssssss

发送美元:

file_get_contents('http://'.$goip4_user.':'.$goip4_pass.'@192.168.0.31/default/en_US/ussd_info.html', false, stream_context_create([
    'http' => [
        'method' => 'POST',
        'header'  => "Content-type: application/x-www-form-urlencoded",
        'content' => http_build_query([
            'line2' => '1', 'smskey' => '57872222', 'action' => 'USSD', 'telnum' => '*111#', 'send' => 'Send'
        ])
    ]
]));

'smskey',您可以发明自己的/

阅读答案ussd:http://192.168.0.31/default/en_US/send_status.xml?u=admin&p=passssssss

其他信息:https://github.com/dudumiquim/GOIP-PHP/blob/master/doc/goip_sms_Interface_en.pdf

答案 3 :(得分:0)

对于我的案例,我在我的自托管服务器上设置了 GO-IP 服务器和硬件。我用 Elixir 编写的程序如下:

#! /usr/bin/env elixir
# +-------------+------------------+--+-----------------+-------------------------------------+
# |   channel:  |        "1"       |  |      auth:      |       "the password"                |
# +-------------+------------------+--+-----------------+-------------------------------------+
# |   action:   |       "sms"      |  |     accept:     |                "*/*"                |
# +-------------+------------------+--+-----------------+-------------------------------------+
# |   telnum:   | "#{user_define}" |  |  content-type:  | "application/x-www-form-urlencoded" |
# +-------------+------------------+--+-----------------+-------------------------------------+
# | smscontent: | "#{user_define}" |  | content-length: |                "125"                |
# +-------------+------------------+--+-----------------+-------------------------------------+
# |   smskey:   |#{user Define}    |  |                 |                                     |
# +-------------+------------------+--+-----------------+-------------------------------------+
# defmodule SMS Send OTP SMS to Phone Number Specified
defmodule SMS do
  require Logger

  def send do
    # Virtual Code Generate By Random
    vcode = Enum.random(1_00000..9_99999)
    # Host of the SMS Gateway
    host = "127.0.0.1"
    # Port of the Gateway
    port = 80
    # Line Channel number
    line = "1"
    # Action service
    action = "sms"
    # Get User Telephone Number
    telnum = IO.gets("Enter your phone number: ") |> String.trim()
    # my OTP Message with Generated Code
    smscontent = "APPNAME Your Account Verification Code is #{vcode}"

    # HTTP "POST" REQUEST
    {:ok, conn} = Mint.HTTP1.connect(:http, "#{host}", 80)

    {:ok, conn, request_ref} =
      Mint.HTTP1.request(
        conn,
        "POST",
        "/default/en_US/sms_info.html?",
        [
          {"Authorization", "Basic YWRtaW46YWRtaW4="},
          {"Accept", "*/*"},
          {"Content-Type", "application/x-www-form-urlencoded"},
          {"Content-Length", "125"}
        ],
        "line=1&action=#{action}&telnum=#{telnum}&smscontent=#{smscontent}&smskey=${userdefine}"
      )

    # Checks wether it work
    if conn == nil do
      Logger.info("Connection to #{host} at #{port} {:failed}")
    else
      Logger.info("Connected to #{host} at #{port} {:success}")
    end

    # On Receiving Responses, IO print out Reponse
    receive do
      message ->
        {:ok, conn, responses} = Mint.HTTP1.stream(conn, message)

     
        # Checks is there such Files &&  Write File and Append
        dir_log = "log/something.log"
        file_existence = File.exists?(dir_log)
        today = Date.utc_today()

        if file_existence == true do
          Logger.debug("File Requested Do Exist, append to file now ")

          my_server_writer = fn filename, data ->
            File.open(filename, [:append])
            |> elem(1)
            |> IO.binwrite(data)
            |> to_string()
          end

          Enum.each(0..0, fn x ->
            ## {dir_log}_#{DateTime.utc_now}
            my_server_writer.(
              "#{dir_log}",
              "For #{telnum} Received \"#{smscontent} \" at #{today} : #{
                DateTime.to_unix(DateTime.utc_now())
              } \n"
            )
          end)
        else
          Logger.debug("File Requested Do not Exist \n Creating file...")

          my_server_writer = fn filename, data ->
            File.open(filename, [:append])
            |> elem(1)
            |> IO.binwrite(data)
            |> to_string()
          end

          Enum.each(0..0, fn x ->
            my_server_writer.(
              "#{dir_log}",
              "For #{telnum} Received \"#{smscontent} \" at #{today} : #{
                DateTime.to_unix(DateTime.utc_now())
              } \n"
            )
          end)
        end
    end

    {:ok, conn} = Mint.HTTP.close(conn)
  end
end