2016-06-21 153 views
1

我一直在使用quickblox煩惱JS SDK羣聊Quickblox羣聊加入不工作

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

這是Quickblox的示例代碼(使用Javascript SDK)。我檢查了源代碼,並與兩個比較,但我沒有發現任何區別。 最後,我已將app id,api key和一些憑據替換爲正在運行quickblox的示例代碼。並意識到示例應用程序不能使用我的憑據。 QB賬號真的很重要嗎?

回答

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; 
}