1
jid = Jabber::JID.new('....@jabber.ru')  
  j = Jabber::Client.new(jid)  
  j.connect
  j.auth('12345')

如果我尝试通过传输发送消息,它会回复我

SENDING:
<message to='2....3@icq.proc.ru' xmlns='jabber:client'><body>hi!</body></message>
 => nil 
ruby-1.9.2-p290 :106 > RECEIVED:
<message from='2...3@icq.proc.ru' to='....@jabber.ru/38185266013242853702144' type='error'><error code='401' type='auth'><not-authorized xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/><text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>Error. You must log into the transport before sending messages.</text></error><body>hi!</body></message>
PROCESSING:
<message from='2....3@icq.proc.ru' to='do-not-replay.perekup.net@jabber.ru/38185266013242853702144' type='error' xmlns='jabber:client'><error code='401' type='auth'><not-authorized xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/><text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>Error. You must log into the transport before sending messages.</text></error><body>hi!</body></message> (Jabber::Message)

但:

  iq = Jabber::Iq.new(:set)  

  query = Jabber::IqQuery.new  
  query.add_namespace('jabber:iq:auth')  
  query.add(REXML::Element.new('username').add_text("6...6"))  
  query.add(REXML::Element.new('password').add_text('F...1'))  

  iq.add(query)  
  iq.to = 'icq.proc.ru'  
  iq

  j.send iq


SENDING:
<iq to='icq.proc.ru' type='set' xmlns='jabber:client'><query  xmlns='jabber:iq:authenticate'><username>6....6</username><password>F....1</password></query></iq>
=> nil 
ruby-1.9.2-p290 :105 > RECEIVED:
<iq from='icq.proc.ru' to='...@jabber.ru/38185266013242853702144' type='error'><error code='501' type='cancel'><feature-not-implemented/></error></iq>
PROCESSING:
<iq from='icq.proc.ru' to='...@jabber.ru/38185266013242853702144' type='error' xmlns='jabber:client'><error code='501' type='cancel'><feature-not-implemented/></error></iq> (Jabber::Iq)

我无法使用 Iq.new_authset_digest(jid, session_id, password) 因为我无法获取 session_id 参数我做错了什么?

4

1 回答 1

0
    jid = Jabber::JID.new('user')

    client = Jabber::Client.new(jid)

    client.connect('54.187.67.96',5222)
    client.auth('password')
    client.send(Jabber::Presence.new.set_show(:chat).set_status('Rails!'))
    puts "Hurray...!!  Connected..!!"


    # Send an Instant Message.
    body = 'Hello from Rails'
    to_jid = Jabber::JID.new('user')
    message = Jabber::Message::new(to_jid, body).set_type(:normal).set_id('1')
    client.send(message)
于 2014-07-09T05:51:45.127 回答