我试图使用这个链接来获得描述的响应:
{
"session": {
"application_id": 2,
"created_at": "2012-04-03T07:34:48Z",
"device_id": null,
"id": 743,
"nonce": 1308205278,
"token": "0e7bc95d85c0eb2bf052be3d29d3df523081e87f",
"ts": 1333438438,
"updated_at": "2012-04-03T07:34:48Z",
"user_id": null
}
}但现在它说没有找到申请:
<?xml version="1.0" encoding="UTF-8"?>
<errors>
<error>No application found</error>
</errors>不能继续测试其他请求。这是一个shell脚本,用于获取curl请求:
timestamp=`date +%s`
body="application_id=HIDDENAPPLICATIONIDHERE&auth_key=HIDDENAUTHKEYHERE&nonce=2342546×tamp=$timestamp"
signature=`echo -n $body | openssl sha -hmac HIDDENSECRETHERE`
body=$body"&signature="$signature
#echo $body
#echo $signature
#exit 0
curl -X POST \
-H "QuickBlox-REST-API-Version: 0.1.0" \
-d $body \
https://api.quickblox.com/session.xml因此,这里有一些信息,可能是我以错误的方式创建了shell脚本:
HMAC-SHA函数的主体请求,带有一个键auth_secret.请求体是以排序(按字母顺序排序,而不是以字节的形式排序)通过增加字符串数组‘参数=值’而形成的,以符号"&“分隔。对于作为userid=123传递的参数,只使用这样一行userid=123
另外,我已经准备了一个Swift项目如何生成签名和获取会话,但是仍然有相同的错误,没有找到应用程序。
有什么建议吗?谢谢
发布于 2016-06-29 08:55:16
请验证应用程序ID参数,因为服务器返回:
<?xml version="1.0" encoding="UTF-8"?>
<errors>
<error>No application found</error>
</errors>例如,生成签名(Java):
Random random = new Random();
String nonce = Integer.toString(random.nextInt());
long time = System.currentTimeMillis() / 1000;
String timestamp = Long.toString(time);
String signature;
String str = "application_id=" + applicationId + "&" + "auth_key=" + authKey + "&" + "nonce="
+ nonce + "&" + "timestamp=" + timestamp + "&" + "user[login]=" + adminLogin + "&" + "user[password]="
+ adminPassword;
signature = UtilsMethods.calculateHMAC_SHA(str, authSecret);calculateHMAC_SHA:
private static final String HMAC_SHA1_ALGORITHM = "HmacSHA1";
public static String calculateHMAC_SHA(String data, String key) throws SignatureException {
String result = null;
try {
// get an hmac_sha1 key from the raw key bytes
SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), HMAC_SHA1_ALGORITHM);
// get an hmac_sha1 Mac instance and initialize with the signing key
Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
mac.init(signingKey);
byte[] digest = mac.doFinal(data.getBytes());
StringBuilder sb = new StringBuilder(digest.length * 2);
String s;
for (byte b : digest) {
s = Integer.toHexString(0xFF & b);
if (s.length() == 1) {
sb.append('0');
}
sb.append(s);
}
result = sb.toString();
} catch (Exception e) {
throw new SignatureException("Failed to generate HMAC : " + e.getMessage());
}
return result;
}https://stackoverflow.com/questions/37887048
复制相似问题