作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试在我的示例 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)
}
})
环境
最佳答案
我相信您对新的 V1.1 API 有疑问,您需要使用 HMAC-SHA512 加密 Secret:
For this version, we use a standard HMAC-SHA512 signing. Append
apikey
andnonce
to your request and calculate the HMAC hash and include it under anapisign
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/
我正在尝试在我的示例 iOS 应用程序中调用 Bittrex api。 我收到以下消息。 返回消息 SUCCESS: { message = "APIKEY_NOT_PROVIDED";
我是一名优秀的程序员,十分优秀!