我很难获得对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}×tamp=#{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/我得到完全相同的错误。非常令人沮丧。我究竟做错了什么?
尝试以下方法: signature_string = “APPLICATION_ID =#{APPLICATION_ID}&AUTH_KEY =#{AUTH_KEY}&随机数=#{随机数}&时间戳=#{时间戳}” 签名= HMAC :: SHA1.hexdigest(aUTH_SECRET,signature_string) – Darya