获取会话的 Quickblox 收到“意外签名"错误 [英] Quickblox getting a session receives "Unexpected signature" error

查看:65
本文介绍了获取会话的 Quickblox 收到“意外签名"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在获取会话时,我收到意外错误".

When getting a session, I get an "unexpected error".

这是我获取签名的代码(修改自 这个 因为该代码没有一些导入,特别是使用 hmac.new() 而不是 hmac() 因为该代码对我不起作用.

Here is my code to get the signature (modified from this since that code is without some imports and notably hmac.new() is used instead of hmac() since that code doesn't work for me.

import sys
import json
import time
import random
import hashlib
import hmac
import urllib
import httplib

application_id = '3427'
auth_key = 'PLYHedAmxwdvt59'
auth_secret = '*some secret key*'


nonce = str(random.randint(1, 10000))
timestamp = str(int(time.time()))

signature_raw_body = ("application_id=" + application_id + "&auth_key=" + auth_key +
            "&nonce=" + nonce + "&timestamp=" + timestamp)

signature = hmac.new(auth_secret, signature_raw_body, hashlib.sha1).hexdigest()

params = urllib.urlencode({'application_id': application_id,
                           'auth_key': auth_key,
                           'timestamp': timestamp, 'nonce' : nonce,
                           'signature' : signature})

conn = httplib.HTTPSConnection("api.quickblox.com")
conn.request("POST", "/session", params, {})
response = conn.getresponse()

print response.read()
print "signature = '%s'" % signature

输出:

<?xml version="1.0" encoding="UTF-8"?>
<session>
  <application-id type="integer">3427</application-id>
  <created-at type="datetime">2013-08-04T12:19:10Z</created-at>
  <device-id type="integer" nil="true"/>
  <id type="integer">3552056</id>
  <nonce type="integer">5855</nonce>
  <token>686840081c18c7dd0e0a779c233e0d9605bcb567</token>
  <ts type="integer">1375618748</ts>
  <updated-at type="datetime">2013-08-04T12:19:10Z</updated-at>
  <user-id type="integer" nil="true"/>
</session>

signature = 'f08b68b645184619bbe59bac217506e66a840425'

接下来我使用 curl 来尝试创建一个会话:

Next I use curl to attempt to create a session:

curl -X POST -H "Content-Type: application/json" -HQuickBlox-REST-API-版本:0.1.0"-d'{"application_id":"3427","auth_key":"PLYHedAmxwdvt59","nonce":"33432","timestamp":"1375619372","签名":"f08b68b645184619bbe5804'http://api.quickblox.com/session.json

curl -X POST -H "Content-Type: application/json" -H "QuickBlox-REST-API-Version: 0.1.0" -d '{"application_id":"3427","auth_key":"PLYHedAmxwdvt59","nonce":"33432","timestamp":"1375619372","signature":"f08b68b645184619bbe59bac217506e66a840425"}' http://api.quickblox.com/session.json

我得到了这个结果:{"errors":{"base":["意外签名"]}}

I get this as a result: {"errors":{"base":["Unexpected signature"]}}

出了什么问题?

推荐答案

这是我的例子:

curl -X POST -H "Content-Type: application/json" -H "QuickBlox-REST-API-Version: 0.1.0" -d '{"application_id":"92","auth_key":"wJHdOcQSxXQGWx5","nonce":"315","timestamp":"1375624737","signature":"f36336b8bc8449b8252edbc0ee441cdb5856112c"}' http://api.quickblox.com/session.json

结果:

{"session":{"application_id":92,"created_at":"2013-08-04T13:59:50Z","device_id":null,"id":3553701,"nonce":315,"token":"1d423b6633e2fc82f81d88b65f3e26198853c84c","ts":1375624737,"updated_at":"2013-08-04T13:59:50Z","user_id":null}}

您应该检查生成签名的代码

You should check code which generates your signature

这篇关于获取会话的 Quickblox 收到“意外签名"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆