Quickblox群聊聊天加入不起作用(Javascript SDK)

时间:2016-06-21 07:46:20

标签: javascript chat quickblox

我在使用quickblox JS SDK进行群聊时遇到了麻烦

QB.chat.muc.join(dlg.xmpp_room_jid, function(){
 console.log("Joined dialog " + dlg._id + " xmpp " + dlg.xmpp_room_jid);
})

这是来自Quickblox的示例代码。我检查了源代码,并与两个进行了比较,但我发现没有差异。 最后,我已经将app id,api key和一些凭据替换为了quickblox的示例代码。并意识到示例应用程序无法使用我的凭据。 QB帐户真的重要吗?

2 个答案:

答案 0 :(得分:2)

我已经想通了。 就我而言,原因来自您的会话创建API。 API文档说要使用[POST] /session.json,但使用此API的用户不能进行群聊。我使用/auth.json进行会话创建并使用注册RESTful api,现在它正在运行。 这不是帐户问题。 我认为他们应该检查API或更新文档。

这是/auth.json api。

的用法
function qbGenerateSession() {
    // Generate signature
    $nonce = rand();
    $timestamp = time(); // time() method must return current timestamp in UTC but seems like hi is return timestamp in current time zone
    $signature_string = "application_id=" . QB_APP_ID . "&auth_key=" . QB_AUTH_KEY . "&nonce=" . $nonce . "&timestamp=" . $timestamp;

    $signature = hash_hmac('sha1', $signature_string , QB_AUTH_SECRET);

    //echo $signature;
    //echo $timestamp;

    // Build post body
    $post_body = http_build_query( array(
        'application_id' => QB_APP_ID,
        'auth_key' => QB_AUTH_KEY,
        'timestamp' => $timestamp,
        'nonce' => $nonce,
        'signature' => $signature,
        ));

    // Configure cURL
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, 'https://api.quickblox.com/auth.json'); // Full path is - https://api.quickblox.com/auth.json
    curl_setopt($curl, CURLOPT_POST, true); // Use POST
    curl_setopt($curl, CURLOPT_POSTFIELDS, $post_body); // Setup post body
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Receive server response
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

    // Execute request and read response
    $response = curl_exec($curl);

    $token = null;

    try {
        $authInfo = json_decode($response);
        $token = $authInfo->session->token;
    }
    catch (Exception $e) {
        curl_close($curl);
        return null;
    }

    // Close connection
    curl_close($curl);

    return $token;
}

答案 1 :(得分:1)

是的,它是服务器端问题,所以在这里查看答案https://github.com/QuickBlox/quickblox-javascript-sdk/issues/102