3

Net::SMPPを使用して受信機と送信機として機能するPerlスクリプトを書いています。モバイル加入者がショートコード(たとえば123)にメッセージを送信すると、そのメッセージは私のSMPPアカウントに到達し、私のSMPPアプリケーションはメッセージを読み取り、ユーザーに確認応答を返します。たとえば、「メッセージを送信していただきありがとうございます。 "。ユーザーからSMPPアプリに送信されたメッセージをまったく問題なく受信します。問題は、SMSCに確認応答(delivery_sm_resp)を返送して、そのメッセージをストリームから削除し、他のユーザーが送信した次のメッセージを収集できるようにすることです。この関数を使用してみましたが、SMSCからESMEに受信したメッセージからmessage_idを取得する場所がわかりません。

私のコードはです。

my $transmitter = Net::SMPP->new_transmitter($host,port=> $port,system_id => '123',password  => '',) or die;

$receiver = Net::SMPP->new_receiver($host,system_id => '123',password => '',port => $port,)
    or die "Can't create server: $!";

while (1) {
    warn "Waiting for PDU";
    $pdu = $receiver->read_pdu() or die "$$: PDU not read. Closing connection";
    print "Received #$pdu->{seq} $pdu->{cmd}:". Net::SMPP::pdu_tab->{$pdu->{cmd}}{cmd} ."\n";
    warn Dumper($pdu);

    print "\n\n ** Hello ** " . $pdu->{message_id} . "\n ** now printing ** " . $pdu->{sm_default_msg_id};
    $transmitter->deliver_sm_resp( message_id => $pdu->{sm_default_msg_id}, seq => $pdu->{seq});
    $resp_pdu = $transmitter->submit_sm(
        destination_addr => $pdu->{source_addr},
        short_message    => "you sent a message with text " . $pdu->{short_message}
    ) or die "Response indicated error: " . $resp_pdu->explain_status();

}

SMSCからESMEに受信したメッセージの表示は次のとおりです。SMSCの確認に使用できるmessage_idを見つけて、そのメッセージをストリームから削除し、他のユーザーが送信した次のメッセージを楽しむことができるようにしてください。それ以外の場合、同じPDUを3回受信し、そのタイムアウトまで次のメッセージを楽しむことができません。

Waiting for PDU at s.pl line 23.
Received #2 5:deliver_sm
$VAR1 = bless( {
             'source_addr_ton' => 1,
             'known_pdu' => 1,
             'schedule_delivery_time' => '',
             'protocol_id' => 0,
             'status' => 0,
             'short_message' => 'A',
             'dest_addr_npi' => 0,
             'source_addr' => '44702601843',
             'validity_period' => '',
             'registered_delivery' => 0,
             'dest_addr_ton' => 0,
             'seq' => 2,
             'data_coding' => 1,
             'service_type' => '',
             'replace_if_present_flag' => 0,
             'cmd' => 5,
             'priority_flag' => 0,
             'data' => '44702601843420A',
             'destination_addr' => '420',
             'esm_class' => 0,
             'sm_default_msg_id' => 0,
             'source_addr_npi' => 0,
             'reserved' => undef
           }, 'Net::SMPP::PDU' );
4

2 に答える 2

3

回答:これを詳しく調べたところ、ESME-> SMSCから確認応答を送信するには、コードで次のコマンドを使用する必要があることがわかりました。いつか誰かに役立つことを願っています。:)

$receiver->data_sm_resp(message_id => $pdu->{sm_default_msg_id}, seq => $pdu->{seq});
于 2013-01-01T18:21:06.943 に答える
0

添付されているのは、SMS を受信できるコードです。

#!/usr/bin/perl
#
# Copyright (c) 2001 SymLABS <symlabs@symlabs.com>, All Rights Reserved.
# See README for license. NO WARRANTY.
#
# 10.7.2001, Sampo Kellomaki <sampo@symlabs.com>
# $Id: esme-rec.pl,v 1.4 2002/02/11 16:43:47 sampo Exp $
#
# ESME in receiver role.
#
# Test Net::SMPP in SMSC role
#
# Usage: ./esme-rec.pl *version*
#    version can be 4 or 3             #4

use Net::SMPP;
use Data::Dumper;

$trace = 1;
$sysid = "username";
$pw = "password";
$host = 'ip address';
$port = port;
$facil = 0x00010003;
($vers) = @ARGV;
$vers = $vers == 4 ? 0x40 : 0x34;   #4
$if_vers = 0x00;

use constant reply_tab => {
    0x80000000 => { cmd => 'generic_nack', reply => undef, },
    0x00000001 => { cmd => 'bind_receiver',
            reply => sub { my ($me,$pdu) = @_;
                   $me->set_version(0x34);
                   $me->bind_receiver_resp(system_id => $sysid,
                               seq => $pdu->{seq});
                       }, },
    0x80000001 => { cmd => 'bind_receiver_resp', reply => undef, }, 
    0x00000002 => { cmd => 'bind_transmitter',
            reply => sub { my ($me, $pdu) = @_;
                   $me->set_version(0x34);
                   warn "Doing bind_tx_resp";
                   $me->bind_transmitter_resp(system_id => $sysid,
                               seq => $pdu->{seq});
                   }, },
    0x80000002 => { cmd => 'bind_transmitter_resp', reply => undef, }, 
    0x00000003 => { cmd => 'query_sm',
            reply => sub { my ($me, $pdu) = @_;
                   $me->query_sm_resp(message_id=>$pdu->{message_id},
                              final_date=>'010711135959000+',
                               seq => $pdu->{seq},
                              ) }, },
    0x80000003 => { cmd => 'query_sm_resp', reply => undef, },     
    0x00000004 => { cmd => 'submit_sm',
            reply => sub { my ($me, $pdu) = @_;
                   $me->submit_sm_resp(message_id=>'123456789',
                               seq => $pdu->{seq}) }, },
    0x80000004 => { cmd => 'submit_sm_resp', reply => undef, },   
    0x00000005 => { cmd => 'deliver_sm', reply => undef, },    # we originate this
    0x80000005 => { cmd => 'deliver_sm_resp', reply => undef, },  # *** need to handle this?
    0x00000006 => { cmd => 'unbind',
            reply => sub { my ($me, $pdu) = @_;
                   $me->unbind_resp(seq => $pdu->{seq});
                   warn "$$: Remote sent unbind. Dropping connection.";
                   exit;
                   }, },       
    0x80000006 => { cmd => 'unbind_resp',
            reply => sub { warn "$$: Remote replied to unbind. Dropping connection.";
                   exit;
                   }, },
    0x00000007 => { cmd => 'replace_sm',
            reply => sub { my ($me, $pdu) = @_;
                   $me->replace_sm_resp(seq => $pdu->{seq}) }, },
    0x80000007 => { cmd => 'replace_sm_resp', reply => undef, }, 
    0x00000008 => { cmd => 'cancel_sm', reply => sub { my ($me, $pdu) = @_;
                           $me->cancel_resp(seq => $pdu->{seq}) }, },
    0x80000008 => { cmd => 'cancel_sm_resp', reply => undef, },  
    0x00000009 => { cmd => 'bind_transceiver',
            reply => sub { my ($me, $pdu) = @_;
                   $me->set_version(0x34);
                   $me->bind_transceiver_resp(system_id => $sysid,
                                  seq => $pdu->{seq});
                   }, },
    0x80000009 => { cmd => 'bind_transceiver_resp', reply => undef, }, 
    0x0000000b => { cmd => 'outbind',
            reply => sub {  my ($me, $pdu) = @_;
                    $me->set_version(0x34);
                    $me->bind_receiver(system_id => $sysid,
                               password => $pw) }, },
    0x00000015 => { cmd => 'enquire_link',
            reply => sub { my ($me, $pdu) = @_;
                   $me->enquire_link_resp(seq => $pdu->{seq}) }, },      
    0x80000015 => { cmd => 'enquire_link_resp', reply => undef, }, 
    0x00000021 => { cmd => 'submit_multi',
            reply => sub { my ($me, $pdu) = @_;
                   $me->submit_multi_resp(message_id=>'123456789',
#                                 no_unsuccess=>0,
                              seq => $pdu->{seq} ) }, },
    0x80000021 => { cmd => 'submit_multi_resp', reply => undef, }, 
    0x00000102 => { cmd => 'alert_notification', reply => undef, },  # ***
    0x00000103 => { cmd => 'data_sm', reply => undef, },  # ***
    0x80000103 => { cmd => 'data_sm_resp', reply => undef, }, 

#4#cut

    # v4 codes

    0x80010000 => { cmd => 'generic_nack_v4', reply => undef, }, 
    0x00010001 => { cmd => 'bind_receiver_v4',
            reply => sub { my ($me, $pdu) = @_;
                   $me->set_version(0x40);
                   $me->bind_receiver_resp(system_id => $sysid,
                               facilities_mask => $facil,
                               seq => $pdu->{seq});
                   }, },
    0x80010001 => { cmd => 'bind_receiver_resp_v4', reply => undef, }, 
    0x00010002 => { cmd => 'bind_transmitter_v4',
            reply => sub { my ($me, $pdu) = @_;
                   $me->set_version(0x40);
                   $me->bind_transmitter_resp(system_id => $sysid,
                                  facilities_mask =>  $facil,
                                  seq => $pdu->{seq});
                   }, },
    0x80010002 => { cmd => 'bind_transmitter_resp_v4', reply => undef, }, 
    0x00010003 => { cmd => 'query_sm_v4',
            reply => sub { my ($me, $pdu) = @_;
                   $me->query_sm_resp(message_id=>$pdu->{message_id},
                              final_date=>'010711135959000+',
                              seq => $pdu->{seq}) }, },
    0x80010003 => { cmd => 'query_sm_resp_v4', reply => undef, },     
    0x00010004 => { cmd => 'submit_sm_v4',
            reply => sub { my ($me, $pdu) = @_;
                   $me->submit_sm_resp(message_id=>'123456789',
#                                  num_unsuccess=>0,
#                                  destination_addr=>$pdu->      {source_addr},
                               error_status_code => 0,
                               seq => $pdu->{seq} ) }, },
    0x80010004 => { cmd => 'submit_sm_resp_v4', reply => undef, },   
    0x00010005 => { cmd => 'deliver_sm_v4', reply => undef, },
    0x80010005 => { cmd => 'deliver_sm_resp_v4', reply => undef, },  # Need to handle this?
    0x00010006 => { cmd => 'unbind_v4',
            reply => sub { my ($me, $pdu) = @_;
                   $me->unbind_resp(seq => $pdu->{seq});
                   warn "$$: Remote sent unbind. Dropping connection.";
                   exit;
                   }, },       
    0x80010006 => { cmd => 'unbind_resp_v4',
            reply => sub { warn "$$: Remote replied to unbind. Dropping connection.";
                   exit;
                   }, },       
    0x00010007 => { cmd => 'replace_sm_v4',
            reply => sub { my ($me, $pdu) = @_;
                   $me->replace_sm_resp(seq => $pdu->{seq}) }, },
    0x80010007 => { cmd => 'replace_sm_resp_v4', reply => undef, }, 
    0x00010008 => { cmd => 'cancel_sm_v4',
            reply => sub { my ($me, $pdu) = @_;
                   $me->cancel_resp(seq => $pdu->{seq}) }, },      
    0x80010008 => { cmd => 'cancel_sm_resp_v4', reply => undef, },  
    0x00010009 => { cmd => 'delivery_receipt_v4',
            reply => sub { my ($me, $pdu) = @_;
                   $me->delivery_receipt_resp(seq => $pdu->{seq}) }, },
    0x80010009 => { cmd => 'delivery_receipt_resp_v4', reply => undef, },  
    0x0001000a => { cmd => 'enquire_link_v4',
            reply => sub { my ($me, $pdu) = @_;
                   $me->enquire_link_resp(seq => $pdu->{seq}) }, },
    0x8001000a => { cmd => 'enquire_link_resp_v4', reply => undef, },
    0x0001000b => { cmd => 'outbind_v4',
            reply => sub { my ($me, $pdu) = @_;
                   $me->set_version(0x34);
                   $me->bind_receiver(system_id => $sysid,
                              password => $pw,
                              facilities_mask => $facil,
                              seq => $pdu->{seq}) }, },
#4#end
};

($smpp, $resp) = Net::SMPP->new_transceiver($host,
                  smpp_version => $vers,
                  interface_version => $if_vers,
                  system_id => $sysid,
                  password => $pw,
                  addr_ton => 0x01,
                  addr_npi => 0x01,
                  source_addr_ton => 0x01,
                  source_addr_npi => 0x01,
                  dest_addr_ton => 0x01,
                  dest_addr_npi => 0x01,
                  system_type => '',
                  facilities_mask => $facil,
                  port => $port,
#               timeout => 7,
                  )
    or die "Can't create server: $!";

warn Dumper $resp;

print "#### Connected: ###### \n smpp:$smpp, \n resp:$resp";


while (1) {
 warn "Waiting for PDU";
 $pdu = $smpp->read_pdu() or { $bind_fail = "yes" };

Net::SMPP::Pdu_tab->{$pdu->{cmd}}{cmd} ."\n";

### read in data
 $short_message = $pdu->{short_message};
 $source_addr = $pdu->{source_addr};
 $seq = $pdu->{seq};

print "\n ===> Bind failed=$bind_fail \n";

########### if bind failed above - try to reconnect
 if ($bind_fail eq "yes"){
 print "\n Reconnecting \n";
 ($smpp, $resp) = Net::SMPP->new_transceiver($host,
 smpp_version => $vers,
 interface_version => $if_vers,
 system_id => $sysid,
 password => $pw,
 addr_ton => 0x00,
 addr_npi => 0x01,
 source_addr_ton => 0x0,
 source_addr_npi => 0x1,
 dest_addr_ton => 0x0,
 dest_addr_npi => 0x1,
 system_type => '',
 facilities_mask => $facil,
 port => $port,
 # timeout => 7,
 )
 or die "Can't create server: $!";
 sleep 2;
 }#fi bind_fail

warn Dumper($pdu) if $trace;
 $mh_msg_id = "$pdu->{seq}";

 if (defined reply_tab->{$pdu->{cmd}}) {
 $smpp->deliver_sm_resp(message_id => $mh_msg_id, seq => $mh_msg_id) or die; ### we use pdu->    {seq} as message_id, as we cannot find message_id, fix later

warn "Replied";

} else {
 warn "Don't know to reply to $pdu->{cmd}";
 sleep 1;
 }
 }


#EOF
于 2013-02-27T20:14:59.563 に答える