2013-03-27 14 views
1

Smpp를 통한 SMS 메시지 송수신, 등록 번호, 시스템 ID 및 비밀번호 수신이 필요하지만 연결에 실패했습니다. 프로젝트 젬 'ruby-smpp'에 연결하여 도망 this의 예를 사용하기 위해 systemID와 password 값만 변경했습니다. 로그에Ruby on Rails에서 Smpp 사용하기

:

<- (BindTransceiver) len = 37 cmd = 9 status = 0 seq = 1364360797 (<systemID><password>) 
Hex dump follows: 
<- 00000000: 0000 0025 0000 0009 0000 0000 5152 7e5d | ...% ........ QR ~] 
<- 00000010: 3531 3639 3030 0068 4649 6b4b 7d7d 7a00 | <systemID>.<password>. 
<- 00000020: 0034 0001 00 | .4 ... 

Starting enquire link timer (with 10s interval) 
Delegate: transceiver unbound 

콘솔에서 :

Connecting to SMSC ... 
MT: Disconnected. Reconnecting in 5 seconds .. 
MT: Disconnected. Reconnecting in 5 seconds .. 
MT: Disconnected. Reconnecting in 5 seconds .. 
MT: Disconnected. Reconnecting in 5 seconds .. 
MT: Disconnected. Reconnecting in 5 seconds .. 

, 나는 어쩌면 추가하거나 변경할 수있는 다른 뭔가로 설정에서,하지 마십시오, 말해? 내가 이해 SMPP 연결, 그것은 단지 특정 IP 주소와 함께 작동하지만, 서버 및 로컬 컴퓨터에 로그

require 'eventmachine' 
require 'smpp' 

LOGFILE = Rails.root + "log/sms_gateway.log" 
Smpp::Base.logger = Logger.new(LOGFILE) 

/스크립트 같은

class Gateway 
    include KeyboardHandler 

    # MT id counter. 
    @@mt_id = 0 

    # expose SMPP transceiver's send_mt method 
    def self.send_mt(*args) 
    @@mt_id += 1 
    @@tx.send_mt(@@mt_id, *args) 
    end 

    def logger 
    Smpp::Base.logger 
    end 

    def start(config) 
    # The transceiver sends MT messages to the SMSC. It needs a storage with Hash-like 
    # semantics to map SMSC message IDs to your own message IDs. 
    pdr_storage = {} 

    # Run EventMachine in loop so we can reconnect when the SMSC drops our connection. 
    puts "Connecting to SMSC..." 
    loop do 
     EventMachine::run do 
     @@tx = EventMachine::connect(
      config[:host], 
      config[:port], 
      Smpp::Transceiver, 
      config, 
      self # delegate that will receive callbacks on MOs and DRs and other events 
     ) 
     print "MT: " 
     $stdout.flush 

     # Start consuming MT messages (in this case, from the console) 
     # Normally, you'd hook this up to a message queue such as Starling 
     # or ActiveMQ via STOMP. 
     EventMachine::open_keyboard(KeyboardHandler) 
     end 
     puts "Disconnected. Reconnecting in 5 seconds.." 
     sleep 5 
    end 
    end 

    # ruby-smpp delegate methods 

    def mo_received(transceiver, pdu) 
    logger.info "Delegate: mo_received: from #{pdu.source_addr} to #{pdu.destination_addr}: #{pdu.short_message}" 
    end 

    def delivery_report_received(transceiver, pdu) 
    logger.info "Delegate: delivery_report_received: ref #{pdu.msg_reference} stat #{pdu.stat}" 
    end 

    def message_accepted(transceiver, mt_message_id, pdu) 
    logger.info "Delegate: message_accepted: id #{mt_message_id} smsc ref id: #{pdu.message_id}" 
    end 

    def message_rejected(transceiver, mt_message_id, pdu) 
    logger.info "Delegate: message_rejected: id #{mt_message_id} smsc ref id: #{pdu.message_id}" 
    end 

    def bound(transceiver) 
    logger.info "Delegate: transceiver bound" 
    end 

    def unbound(transceiver) 
    logger.info "Delegate: transceiver unbound" 
    EventMachine::stop_event_loop 
    end 

end 


module KeyboardHandler 
    include EventMachine::Protocols::LineText2 

    def receive_line(data) 
    sender, receiver, *body_parts = data.split 
    unless sender && receiver && body_parts.size > 0 
     puts "Syntax: <sender> <receiver> <message body>"  
    else 
     body = body_parts.join(' ') 
     puts "Sending MT from #{sender} to #{receiver}: #{body}" 
     SampleGateway.send_mt(sender, receiver, body) 
    end 
    prompt 
    end 

    def prompt 
    print "MT: " 
    $stdout.flush 
    end 
end 

/초기화됩니다 레일을 통해 실행되는 스크립트

puts "Starting SMS Gateway. Please check the log at #{LOGFILE}" 
config = { 
    :host => '127.0.0.1', 
    :port => 6000, 
    :system_id => <SystemID>, 
    :password => <Password>, 
    :system_type => '', # default given according to SMPP 3.4 Spec 
    :interface_version => 52, 
    :source_ton => 0, 
    :source_npi => 1, 
    :destination_ton => 1, 
    :destination_npi => 1, 
    :source_address_range => '', 
    :destination_address_range => '', 
    :enquire_link_delay_secs => 10 
} 
gw = Gateway.new 
gw.start(config) 

파일/

+0

체크 호스트 및 포트 설정에서 양식을 받으려면해야한다. 레일 응용 프로그램과 동일한 컴퓨터에 smsc가 있습니까? –

+0

아니, 내 실수는 smsc 개별 서비스를 제공하는 방법, 호스트 및 포트를 얻으려면 다시 시도하십시오 –

+0

올바른 IP 주소와 포트를 입력했지만 러시아 문자를 전송하는 데 문제가 있었고 '#coding : utf-8'이 추가되었습니다. 스크립트에서 및 gateway.rb,하지만 도움이되지 않았다 –

답변

1

문제가 해결 러너. 처음에는 smpp-server가 RoR 응용 프로그램과 동일한 시스템에 있지 않으므로 잘못 지정된 호스트 및 포트가있었습니다. 인코딩에 관해서는, 러시아어 레이아웃에 보내는

message = text.encode ("UTF-16BE"). force_encoding ("BINARY") 
Gateway.send_mt (sender, receiver, message, data_coding: 8) 

오른쪽

message = pdu.short_message.force_encoding ('UTF-16BE'). encode ('UTF-8') 
+0

안녕하세요, ussd에서 ruby-smpp을 사용하고 있습니다. UCS2로 인코딩 된 짧은 메시지를 보낼 때 읽을 수없는 기호가 나타납니다. –