gpt4 book ai didi

ios - Bittrex API 返回 APIKEY_NOT_PROVIDED

转载 作者:可可西里 更新时间:2023-11-01 05:25:17 26 4
gpt4 key购买 nike

我正在尝试在我的示例 iOS 应用程序中调用 Bittrex api。

我收到以下消息。

返回消息

SUCCESS: {
message = "APIKEY_NOT_PROVIDED";
result = "<null>";
success = 0;
}

我检查了 HTTP 请求,apikey 如下所示。

API 请求

$ curl -i \
-b "__cfduid=dea9a55b977dded0f94ad14f7158f03e91497078592" \
-H "Content-Type: application/json" \
-H "Accept-Language: en;q=1.0" \
-H "apisign: 41a5b3a98d7da9bee01ddb8ab72dee...." \
-H "User-Agent: SampleApp/1.0 (com.sampleapp.SampleApp; build:1; iOS 10.3.1) Alamofire/4.4.0" \
-H "Accept-Encoding: gzip;q=1.0, compress;q=0.5" \
-d "{\"apikey\":\"f23439b...\",\"nonce\":\"1497703898.0\"}" \
"https://bittrex.com/api/v1.1/account/getbalances"

我的代码如下。

代码

let timeInterval = NSDate().timeIntervalSince1970
let epochtime = String(floor(timeInterval))
let parameters = "apikey=" + "f23439b..." + "&" + "nonce=" + epochtime
let url = path + "getbalances" + "?" + parameters
let secretKey: String = "df8a62...".hmac(algorithm: CryptoAlgorithm.SHA512, key: url)

Alamofire.request(path + "getbalances",
method: .get,
parameters: ["apikey":"f23439b...", "nonce":epochtime],
encoding: JSONEncoding.default,
headers: ["apisign":secretKey])
.responseJSON(completionHandler: { response in
let json = response.result.value as! NSDictionary
let success = json["success"] as! CFBoolean
if (success == kCFBooleanTrue) {
//do something
print(json)
} else {
let reason = response.result.description as AnyObject
print(reason)
}
})

环境

  • macOS 塞拉利昂
  • XCode 8.3.3
  • swift 3
  • Alamofire 4.4

最佳答案


我相信您对新的 V1.1 API 有疑问,您需要使用 HMAC-SHA512 加密 Secret:

For this version, we use a standard HMAC-SHA512 signing. Append apikey and nonce to your request and calculate the HMAC hash and include it under an apisign header. Note: the nonce is not respected right now but will be enforced later.

不是 iOS 专家,但这可能对您有所帮助:

$apikey='xxx';
$apisecret='xxx';
$nonce=time();
$uri='https://bittrex.com/api/v1.1/market/getopenorders?apikey='.$apikey.'&nonce='.$nonce;
$sign=hash_hmac('sha512',$uri,$apisecret);
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('apisign:'.$sign));
$execResult = curl_exec($ch);
$obj = json_decode($execResult);

关于ios - Bittrex API 返回 APIKEY_NOT_PROVIDED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44610874/

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