无法发送群组消息 - 错误 400 - 修改 - BadRequest

Posted

技术标签:

【中文标题】无法发送群组消息 - 错误 400 - 修改 - BadRequest【英文标题】:Can't send a group message - Error 400 - Modify - BadRequest 【发布时间】:2014-03-07 23:29:05 【问题描述】:

用户在线,在房间内,可以收听但不能发送任何消息。 为什么?

我在 php 中使用 JAXL!

XML 消息:

<presence xmlns="jabber:client" id="3">
    <status>available!</status>
    <show>dnd</show>
    <priority>10</priority>
</presence>
<presence
    xmlns="jabber:client" 
    from="bot@peoplebus/jaxl#notificator" 
    to="rota_1@conference.peoplebus/bot" 
    id="4">
    <x xmlns="http://jabber.org/protocol/muc">
        <history maxstanzas="0" seconds="0"></history>
    </x>
</presence>
<message 
    xmlns="jabber:client" 
    type="groupchat" 
    to="rota_1@conference.peoplebus/bot" 
    from="bot@peoplebus/jaxl#notificator">
    <body>teste</body>
</message>

错误:

jaxl_socket_client:189 - 2014-03-07 23:09:59 - or"/></x></presence>
<presence from="rota_1@conference.peoplebus/bot" to="bot@peoplebus/jaxl#notificator" id="4">
  <x xmlns="http://jabber.org/protocol/muc#user">
    <item jid="bot@peoplebus/jaxl#notificator" affiliation="none" role="participant"/>
  </x>
</presence>
<message type="groupchat" from="rota_1@conference.peoplebus" to="bot@peoplebus/jaxl#notificator">
  <body>Esta sala permite anônimos.</body>
  <x xmlns="http://jabber.org/protocol/muc#user"><status code="100"/></x>
</message>
<message type="error" to="bot@peoplebus/jaxl#notificator" from="rota_1@conference.peoplebus/bot">
  <body>teste</body>
  <error code="400" type="modify">
    <bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
  </error>
</message>

这是调试的一部分(只是我认为重要的部分):

jaxl_socket_client:95 - 2014-03-07 23:09:59 - trying tcp://10.208.4.180:5222
jaxl_socket_client:104 - 2014-03-07 23:09:59 - connected to tcp://10.208.4.180:5222
jaxl_socket_client:188 - 2014-03-07 23:09:59 - read 182/182 of data
jaxl_socket_client:189 - 2014-03-07 23:09:59 - <?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="peoplebus" id="4453b273" xml:lang="en" version="1.0">
jaxl_socket_client:188 - 2014-03-07 23:09:59 - read 51/719 of data
jaxl_socket_client:189 - 2014-03-07 23:09:59 - <success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>
jaxl_socket_client:201 - 2014-03-07 23:09:59 - sent 178/440 of data
jaxl_socket_client:202 - 2014-03-07 23:09:59 - <stream:stream xmlns:stream="http://etherx.jabber.org/streams" version="1.0" to="peoplebus#" xmlns="jabber:client" xml:lang="en" xmlns:xml="http://www.w3.org/XML/1998/namespace">
jaxl_socket_client:188 - 2014-03-07 23:09:59 - read 411/1130 of data
jaxl_socket_client:189 - 2014-03-07 23:09:59 - <?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="peoplebus" id="4453b273" xml:lang="en" version="1.0"><stream:features><compression xmlns="http://jabber.org/features/compress"><method>zlib</method></compression><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></stream:features>
jaxl_socket_client:201 - 2014-03-07 23:09:59 - sent 140/580 of data
jaxl_socket_client:202 - 2014-03-07 23:09:59 - <iq xmlns="jabber:client" type="set" id="1"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><resource>jaxl#notificator</resource></bind></iq>
jaxl_socket_client:188 - 2014-03-07 23:09:59 - read 149/1279 of data
jaxl_socket_client:189 - 2014-03-07 23:09:59 - <iq type="result" id="1" to="peoplebus/4453b273"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>bot@peoplebus/jaxl#notificator</jid></bind></iq>
jaxl_socket_client:201 - 2014-03-07 23:09:59 - sent 112/692 of data
jaxl_socket_client:202 - 2014-03-07 23:09:59 - <iq xmlns="jabber:client" type="set" id="2"><session xmlns="urn:ietf:params:xml:ns:xmpp-session"></session></iq>
jaxl_socket_client:188 - 2014-03-07 23:09:59 - read 62/1341 of data
jaxl_socket_client:189 - 2014-03-07 23:09:59 - <iq type="result" id="2" to="bot@peoplebus/jaxl#notificator"/>
notificator:43 - 2014-03-07 23:09:59 - got on_auth_success cb, jid bot@peoplebus/jaxl#notificator
jaxl_exception:66 - 2014-03-07 23:09:59 - error handler called with 8, Undefined index: id, /var/www/jaxl/xmpp/xmpp_stanza.php, 81
jaxl_socket_client:201 - 2014-03-07 23:09:59 - sent 484/1176 of data
jaxl_socket_client:202 - 2014-03-07 23:09:59 - <presence xmlns="jabber:client" id="3"><status>available!</status><show>dnd</show><priority>10</priority></presence><presence xmlns="jabber:client" from="bot@peoplebus/jaxl#notificator" to="rota_1@conference.peoplebus/bot" id="4"><x xmlns="http://jabber.org/protocol/muc"><history maxstanzas="0" seconds="0"></history></x></presence><message xmlns="jabber:client" type="groupchat" to="rota_1@conference.peoplebus/bot" from="bot@peoplebus/jaxl#notificator"><body>teste</body></message>
jaxl_socket_client:188 - 2014-03-07 23:09:59 - read 168/1509 of data
jaxl_socket_client:189 - 2014-03-07 23:09:59 - <presence id="3" from="bot@peoplebus/jaxl#notificator" to="bot@peoplebus/jaxl#notificator"><status>available!</status><show>dnd</show><priority>10</priority></presence>
jaxl_socket_client:188 - 2014-03-07 23:09:59 - read 1024/2533 of data
jaxl_socket_client:189 - 2014-03-07 23:09:59 - <presence from="pidgin@peoplebus/fbaff75c" to="bot@peoplebus/jaxl#notificator"><priority>1</priority><c xmlns="http://jabber.org/protocol/caps" node="http://pidgin.im/" hash="sha-1" ver="I22W7CegORwdbnu0ZiQwGpxr0Go="/><x xmlns="vcard-temp:x:update"><photo/></x></presence><message to="bot@peoplebus/jaxl#notificator" from="pidgin@peoplebus" id="pidgin@peoplebus__bot@peoplebus__52D8K"><event xmlns="http://jabber.org/protocol/pubsub#event"><items node="http://jabber.org/protocol/tune"><item id="4ebd50d9-2c64-4c70-9fe5-45b8cffa5fda3"><tune xmlns="http://jabber.org/protocol/tune"/></item></items></event><delay xmlns="urn:xmpp:delay" stamp="2014-03-07T22:40:10.155Z"/></message><presence to="bot@peoplebus/jaxl#notificator" from="rota_1@conference.peoplebus/pidgin"><priority>1</priority><c xmlns="http://jabber.org/protocol/caps" node="http://pidgin.im/" hash="sha-1" ver="I22W7CegORwdbnu0ZiQwGpxr0Go="/><x xmlns="http://jabber.org/protocol/muc#user"> ...
jaxl_fsm:61 - 2014-03-07 23:09:59 - calling state handler 'logged_in' for incoming event 'stanza_cb'
jaxl_fsm:71 - 2014-03-07 23:09:59 - current state 'logged_in'
jaxl_socket_client:188 - 2014-03-07 23:09:59 - read 698/3231 of data
jaxl_socket_client:189 - 2014-03-07 23:09:59 - or"/></x></presence><presence from="rota_1@conference.peoplebus/bot" to="bot@peoplebus/jaxl#notificator" id="4"><x xmlns="http://jabber.org/protocol/muc#user"><item jid="bot@peoplebus/jaxl#notificator" affiliation="none" role="participant"/></x></presence><message type="groupchat" from="rota_1@conference.peoplebus" to="bot@peoplebus/jaxl#notificator"><body>Esta sala permite anônimos.</body><x xmlns="http://jabber.org/protocol/muc#user"><status code="100"/></x></message><message type="error" to="bot@peoplebus/jaxl#notificator" from="rota_1@conference.peoplebus/bot"><body>teste</body><error code="400" type="modify"><bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></message>
jaxl_fsm:61 - 2014-03-07 23:09:59 - calling state handler 'logged_in' for incoming event 'stanza_cb'
jaxl_exception:66 - 2014-03-07 23:09:59 - error handler called with 8, Undefined index: type, /var/www/jaxl/xmpp/xmpp_stanza.php, 81

【问题讨论】:

【参考方案1】:

在这里发现问题:

<message 
    xmlns="jabber:client" 
    type="groupchat" 
    to="rota_1@conference.peoplebus/bot" 
    from="bot@peoplebus/jaxl#notificator">
    <body>teste</body>
</message>

如果我想向所有居住者发送消息:

<message
    from='hag66@shakespeare.lit/pda'
    id='hysf1v37'
    to='coven@chat.shakespeare.lit'
    type='groupchat'>
  <body>Harpier cries: 'tis time, 'tis time.</body>
</message>

我不应该使用to="rota_1@conference.peoplebus/bot"

正确的是:to="rota_1@conference.peoplebus"

根据:

http://www.xmpp.org/extensions/xep-0045.html#privatemessage

如果发送者试图向特定的住户发送“群聊”类型的私人消息,服务必须拒绝传递该消息(因为接收者的客户端会期望房间内消息的类型为“群聊” ") 并向发件人返回&lt;bad-request/&gt; 错误:

示例 48. 居住者尝试向特定居住者发送“群聊”类型的消息

<message
    from='wiccarocks@shakespeare.lit/laptop'
    id='bx71f29k'
    to='coven@chat.shakespeare.lit/firstwitch'
    type='groupchat'>
  <body>I'll give thee a wind.</body>
</message>

<message
    from='coven@chat.shakespeare.lit/firstwitch'
    id='bx71f29k'
    to='wiccarocks@shakespeare.lit/laptop'
    type='error'>
  <body>I'll give thee a wind.</body>
  <error by='coven@chat.shakespeare.lit' type='modify'>
    <bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
  </error>
</message>

【讨论】:

所以你基本上不得不取出资源?

以上是关于无法发送群组消息 - 错误 400 - 修改 - BadRequest的主要内容,如果未能解决你的问题,请参考以下文章

Android Smack MUC 400 错误请求发送群聊消息

如何防止用户向群组发送消息,但继续接收来自该群组的消息(只读)?

发送 gcm 消息的错误请求

skpy 向用户提及的群组发送消息

我如何向whatsapp群组发送消息?

向群组发送消息(通知) - Android