使用VoIP网关GoIP和Yeastar发送和接收SMS消息



VoIP , . , . SMS — , .


GoIP Yeastar


, OpenVox, , . Dinstar, , .


GoIP




GSM GoIP , . GoIP 4 DBL, Hybertone, ,   .


▪ Web


SMS — , Send SMS, , , . , , . GET POST .


→ GET


GET :
http://192.168.1.190/default/en_US/send.html?u=admin&p=admin&l=1&n=89991234567&m=test


u=admin
p=admin
l=1 – ,     
n=89991234567 –   (    «8»,   «+7»  «7»  )
m=test –  

, : «ERROR, », : «Sending, L1 Send SMS to 89991234567; ID:55c489da». , : , , , , .


→ POST


POST — , web , , SMS, . POST USSD , .


perl Mojolicious:


#!/usr/bin/perl -w

use utf8;
use Mojo::UserAgent;

my $ua = Mojo::UserAgent->new;

$ua->post('http://admin:admin@192.168.1.190/default/en_US/sms_info.html?type=sms' 
                    => {Accept => '*/*'}
                    => form => {
                            line    => '1',
                            smskey  => '57867a25',
                            action  => 'SMS',
                            telnum  => '89991234567',
                            smscontent => '!',
                            send    => 'Send'
                        });

USSD :


$ua->post('http://admin:admin@192.168.1.190/default/en_US/sms_info.html?type=ussd' 
                => {Accept => '*/*'}
                => form => {
                        line1 => '1',
                        smskey => '57876006',
                        action => 'USSD',
                        telnum => '*100#',
                        send => 'Send'
                    });

GET .



, , , , . , GoIP USSD , .


:
http://192.168.1.190/default/en_US/send_status.xml?u=admin&p=admin


XML, , GoIP 4, , 8 , 4:


<?xml version="1.0" encoding="utf-8"?>
<send-sms-status>
    <id1>57867a25</id1>
    <status1>DONE</status1>
    <error1></error1>
    <id2>57867277</id2>
    <status2>ERRORDONE</status2>
    <error2>send, but provider not reply.</error2>
    <id3>57876006</id3>
    <status3>DONE</status3>
    <error3> : 57.2 .</error3>
    <id4></id4>
    <status4>DONE</status4>
    <error4></error4>
    <id5></id5>
    <status5></status5>
    <error5></error5>
    <id6></id6>
    <status6></status6>
    <error6></error6>
    <id7></id7>
    <status7></status7>
    <error7></error7>
    <id8></id8>
    <status8></status8>
    <error8></error8>
</send-sms-status>

▪ SMPP


SMPP (Short message peer-to-peer protocol) – , SMS USSD . , , «» . , web , , , .


配置SMPP



SMPP . , UTF-16BE. , , . (data_coding), , .


, destination_addr system_id, GoIP-, . . , . – system_id + 0 + , , , .


Net::SMPP:


#!/usr/bin/perl -w 

use utf8;
use strict;
use Net::SMPP;
use Encode;
use feature 'say';

my $smpp = Net::SMPP->new_transceiver('192.168.1.190',
                system_id => 'arttel', #        – arttel01,  – arttel02  ..
                password => 'arttel',
                port => '7777',
                smpp_version=> 0x34
) or die "Can't connect to SMSC: $!";

while (1) {
    my $pdu = $smpp->read_pdu();
    #    
    my $short_message =  Encode::decode("UTF-16BE", $pdu->{short_message});

    say $short_message;
}

, SMS SIM , id :


#!/usr/bin/perl -w 

use utf8;
use strict;
use Net::SMPP;

my $smpp = Net::SMPP->new_transceiver('192.168.4.107',
                system_id => 'arttel01',
                password => 'arttel',
                port => '7777',
                smpp_version=> 0x34
) or die "Can't connect to SMSC: $!";

&send_message('89991234567', '!!!');

sub send_message {
    my ($sm_dest_addr, $sm_message) = @_;
    my $result = eval {

        my $pru = $smpp->submit_sm(
            source_addr_ton => 0x05, #   
            source_addr_npi => 0x01, #    
            source_addr => '',
            dest_addr_ton => 0x01, #   
            dest_addr_npi => 0x01, #    
            destination_addr => $sm_dest_addr,
            data_coding => 0x01, #       
            short_message => $sm_message
        ) or return 1;

        return 0;
    };

    if ($result == 1){
        print "Can't send message: $!";
    }
}

#   SMSC
$smpp->unbind();

参量内容描述价值观
source_addr_ton0x00 — (Unknown)
0x01 — (International)
0x02 — (National)
0x03 — (Network Specific)
0x04 — (Subscriber Number)
0x05 — - (Alphanumeric)
0x06 — (Abbreviated)
source_addr_npi0x00 — Unknown 0x01 — ISDN (E163/E164)
0x02 — Data (X.121)
0x03 — Telex (F.69)
0x04 — Land Mobile (E.212)
0x05 — National
0x06 — Private
0x07 — ERMES
0x08 — Internet (IP)
0x09 — WAP Client Id ( WAP Forum)
dest_addr_ton0x01 — (International)
dest_addr_npi0x01 — ISDN (E163/E164) ( )
0x02 — National ( )
data_coding0x01 — IA5(CCITT T.50)/ASCII (ANSI X3.4) 7 1 160
0x07 — Latin/Hebrew(ISO-8859-8) 8 1 140
0x08 — UCS2(ISO/IEC-10646) (, ) 70

Yeastar




Yeastar, GoIP – , , , Yeastar , . , . . , , , .


▪ Web


web , , . Yeastar web — «» Inbox Outbox . , , GoIP, , . , , , datasheet .


→ GET


, GET , , . , Yeastar .


SMS USSD . «API Settings», , « AMI» ( ?). , , , , .


设置API设置


SMS USSD :


http://192.168.5.150/cgi/WebCGI?1500101=account=arttel&password=arttel&port=1&destination=89991234567&content=test


Response: Success
Message: Commit successfully!

http://192.168.5.150/cgi/WebCGI?1500102=account=arttel&password=arttel&port=1&content=%2A100%23


Request: 1,*100#
Response: Success
Message:  :
36.3 .

:


account=arttel –        API Settings
password=arttel –   API Settings
port=1 – ,     
destination=89991234567 –  ,     SMS
content=test –    USSD 

GoIP: SMS Yeastar , . USSD , . . . , plain text, : JSON XML.


▪ Asterisk Managment Interface


Yeastar Asterisk ( IP- Digium), SMPP . Asterisk'a AMI, .


:


#!/usr/bin/perl -w

use utf8;
use strict;
use warnings;
use AnyEvent::Impl::Perl;
use Asterisk::AMI;
use Data::Dumper;
use URI::Escape;
use feature 'say';

#   AMI
my $astman = Asterisk::AMI->new(
            PeerAddr => '192.168.5.150', #  
            Username => 'arttel', #    API Settings
            Secret  => 'arttel', #   API Settings
            Events  => 'on',
            Handlers => { 
                ReceivedSMS => \&received_sms #    
            },
            Keepalive => 60,
            on_error => sub { print "Error occured on socket\r\n"; exit; },
            on_timeout => sub { print "Connection to asterisk timed out\r\n"; exit; }
        );

die "Unable to connect to asterisk" unless ($astman);

sub received_sms {
    my ($asterisk, $event) = @_;

    say Dumper($event);
    #     
    say uri_unescape($event->{'Content'}) if ($event->{'Content'});

    return 1;
}

AnyEvent::Impl::Perl::loop;

=result 
$VAR1 = {
          'Total' => '1',
          'Recvtime' => '2016-07-15 17:49:55',
          'ID' => '',
          'Event' => 'ReceivedSMS',
          'Privilege' => 'all,smscommand',
          'Index' => '1',
          'GsmSpan' => '4',
          'Sender' => '+79991234567',
          'Smsc' => '+79997456321',
          '--END SMS EVENT--' => undef,
          'Content' => '%EF%BB%BF%D0%9A%D1%83-%D0%BA%D1%83'
        };

-
=end

, . , «GsmSpan». , 0, 0 1, 2, + 1, GsmSpan 2.


AMI SMS USSD :


#!/usr/bin/perl -w

use strict;
use warnings;
use Asterisk::AMI;
use Data::Dumper;
use URI::Escape;
use Encode;
use feature 'say';

# Connect to asterisk
my $astman = Asterisk::AMI->new(
            PeerAddr => '192.168.5.150',
            Username => 'arttel',
            Secret  => 'arttel',
            Timeout => 30, #    ,   USSD   
            Keepalive => 60,
            on_error => sub { print "Error occured on socket\r\n"; exit; },
            on_timeout => sub { print "Connection to asterisk timed out\r\n"; exit; }
        );

die "Unable to connect to asterisk" unless ($astman);

#  USSD 
my %action = (
    Action => 'smscommand',
    Command => 'gsm send ussd 2 "*100#"'
);
my $actionid = $astman->send_action(\%action);
my $response = $astman->get_response($actionid);

my @cmd = @{$response->{CMD}};
my $i = 0;
while ($i <= $#cmd) {
    if ($cmd[$i] =~ /USSD Message: (.+)/) {
        #   ,     
        my $decodedHex = pack('H*', $1);
        say decode("UCS-2BE", $decodedHex);
    }

    $i++;
}

#  SMS
%action = (
    Action => 'smscommand',
    Command => 'gsm send sms 2 89991234567 "" 11111'
);
$actionid = $astman->send_action(\%action);
$response = $astman->get_response($actionid);

USSD , , . SMS : , . , . , , . - :


$VAR1 = {
          'ID' => '11111',
          'Event' => 'UpdateSMSSend',
          '--END SMS EVENT--' => undef,
          'Status' => '1',
          'Privilege' => 'all,smscommand',
          'Smsc' => '+79991234567'
        };

Status = 1 , , 0. , UpdateSMSSend, , SMS.



Yeastar TG400 AMI. , - GoIP. : SMS , GoIP PHP, Apache MySQL, Yeastar – Windows. , - . , . - , .

Source: https://habr.com/ru/post/zh-CN395947/


All Articles