gpt4 book ai didi

ios - Quick blox - 签名生成问题

转载 作者:行者123 更新时间:2023-11-29 11:58:54 26 4
gpt4 key购买 nike

我正在尝试使用这个 link获得描述的响应:

{
"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>

无法继续测试其他请求。这是我用来获取 curl 请求的 shell 脚本:

timestamp=`date +%s`

body="application_id=HIDDENAPPLICATIONIDHERE&auth_key=HIDDENAUTHKEYHERE&nonce=2342546&timestamp=$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 function of the body of the request, with a key auth_secret. Request body is formed as the sorted (sorting alphabetically, as symbols, not as bytes) by increase the string array 'parameter=value', separated with the symbol "&". For the parameters passed as a user[id]=123 is used just such a line of user[id]=123

我还准备了一个 Swift project如何生成签名和获取session,还是报同样的错误,没有找到应用。

有什么推荐吗?谢谢

最佳答案

请验证应用程序 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);

计算HMAC_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;
}

关于ios - Quick blox - 签名生成问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37887048/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com