ios - Bittrex API 返回 APIKEY_NOT_PROVIDED

标签 ios rest alamofire

我正在尝试在我的示例 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/

相关文章:

api - REST API - 我的帖子应该返回什么

api - 给定一个 Youtube 视频 ID,检查它是否为有效视频的最快方法是什么?

ios - Alamofire 4 的状态码

ios - 从委托(delegate)函数 Swift 4 中提取值

objective-c - iOS 查找 View 是否有动画

用于复杂查询的 REST API

ios - 即使响应数据发生更改,调用 api 也会给出相同的响应

ios - Swift 翻译 UIView 坐标系中的坐标

iphone - 在 gamesalad 中, Actor 在 x 轴上移出屏幕

javascript - 从 [object HTMLCollection] 中检索 [String]