2011-02-06 55 views
4

我试图发送邮件使用Net::SMPP模块SMPP消息,但它给下面的错误:如何在Perl中使用Net :: SMPP发送SMS?

Message state is 2 
Response indicated error: Message ID is invalid (ESME_RINVMSGID=0x0000000C) at send.pl line 28. 

#!/usr/bin/perl 
#use strict; 
#use warnings; 
use Net::SMPP; 

my $host = 'iphost'; 
my $port = 2345; 
my $smpp = Net::SMPP->new_transmitter(
    $host, 
    port  => $port, 
    system_id => 'username', 
    password => 'pass', 
) or die; 

$resp_pdu = $smpp->submit_sm(
    destination_addr => '+44206064379', 
    short_message => 'test message' 
) or die; 
die "Response indicated error: " . $resp_pdu->explain_status() 
if $resp_pdu->status; 
$msg_id = $resp_pdu->{message_id}; 

$resp_pdu = $smpp->query_sm(message_id => $msg_id) or die; 
die "Response indicated error: " . $resp_pdu->explain_status() 
if $resp_pdu->status; 
print "Message state is $resp_pdu->{message_state}\n"; 

$resp_pdu = $smpp->replace_sm(
    message_id => $msg_id, 
    short_message => 'another test' 
) or die; 
die "Response indicated error: " . $resp_pdu->explain_status() 
if $resp_pdu->status; 

$resp_pdu = $smpp->cancel_sm(message_id => $msg_id) or die; 
die "Response indicated error: " . $resp_pdu->explain_status() 
if $resp_pdu->status; 

回答

3

如果你试图发送一个消息,那么你成功。该消息使用submit_sm方法发送。

输出的第一行显示query_sm的结果,该结果返回消息的状态。状态2对应于DELIVERED状态(来自SMPP v3.4规范)。这意味着SMSC已将该消息传递给移动设备。

错误正在由replace_sm方法生成。 replace_sm方法将只替换仍在SMSC上的消息,即仍在等待交付。如果消息已经传递,SMSC将在响应PDU中返回一个错误。同样的事情适用于cancel_sm方法。它只适用于仍在等待交付的消息。