2016-02-25 54 views
0

我很难获得对quickblox API的访问。根据他们的文档此代码应工作:Quickblox Rails签名

require 'base64' 
    require 'cgi' 
    require 'openssl' 
    require 'hmac-sha1' 

    # Application credentials 
    aPPLICATION_ID = 12345 
    aUTH_KEY = 'hidden' 
    aUTH_SECRET = 'hidden' 


    # Generate signature 
    timestamp = Time.now.in_time_zone('UTC').to_i 
    nonce = timestamp-425346 
    signature_string = "application_id=#{aPPLICATION_ID}&auth_key=#{aUTH_KEY}&nonce=#{nonce}&timestamp=#{timestamp}" 
    signature =Base64.encode64("#{ OpenSSL::HMAC.digest('sha1', signature_string, aUTH_SECRET) }") 

    # Post 
    http = Net::HTTP.new(uri.host, uri.port) 
    http.use_ssl = true 
    http.verify_mode = OpenSSL::SSL::VERIFY_PEER 
    request = Net::HTTP::Post.new("/session.json") 
    request.add_field('QuickBlox-REST-API-Version', '0.1.1') 
    request.add_field('Content-Type', 'application/json') 
    request.add_field('Accept', '*/*') 
    request.body = {"application_id" => aPPLICATION_ID, "auth_key" => aUTH_KEY, "nonce" => nonce, "timestamp" => timestamp, "signature" => signature }.to_json 

    response = http.request(request) 

不过,我不断收到错误:{“错误”:{“基地”:“意外的签名”]}}

即使在使用他们的投诉时, :http://hurl.quickblox.com/我得到完全相同的错误。非常令人沮丧。我究竟做错了什么?

+0

尝试以下方法: signature_string = “APPLICATION_ID =#{APPLICATION_ID}&AUTH_KEY =#{AUTH_KEY}&随机数=#{随机数}&时间戳=#{时间戳}” 签名= HMAC :: SHA1.hexdigest(aUTH_SECRET,signature_string) – Darya

回答

0

事实证明,它看起来像QuickBlox不接受红宝石出于某种原因产生的签名。 QuickBlox甚至删除了自己的红宝石宝石(其中也产生了相同的错误)。

现在,解决方案是先通过php脚本获取令牌,然后在ruby中进行通话。

0

检查my stackoverflow answer on this issue在这里。

这主要归结为以下两行:

signature_string = "application_id=#{aPPLICATION_ID}&auth_key=#{aUTH_KEY}&nonce=#{nonce}&timestamp=#{timestamp}" 

signature =Base64.encode64("#{ OpenSSL::HMAC.digest('sha1', signature_string, aUTH_SECRET) }") 

您可以检查此quickblox_api gem了。它对我很有帮助。