java - Kucoin Api KC-API-PASSPHRASE 无效
问题描述
我试图调用“/api/v1/sub-accounts”端点来获取账户余额,但它有问题!这是我的代码:
public Observable<Response<String>> getBalance(){
long timestamp = Timestamp.from(Instant.now()).getTime() + localDelayTime;
return service.getBalance(
apiKey+"",
timestamp+"",
base64(encode(secKey,(timestamp+"GET"+"/api/v1/sub-accounts"+"")))+"",
base64(encode(secKey,passPhrase))+"",
"2")
.subscribeOn(Schedulers.io())
.unsubscribeOn(Schedulers.io())
.retry(2)
.timeout(10,TimeUnit.SECONDS);
}
我的加密方法是:
private String base64(String encode) {
try {
return Base64.getEncoder().encodeToString((encode).getBytes(StandardCharsets.UTF_8));
}catch (NullPointerException e){
return "";
}
}
和
public static String encode(String key, String data) {
Mac sha256;
try {
sha256 = Mac.getInstance("HmacSHA256");
SecretKeySpec secret_key = new SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA256");
sha256.init(secret_key);
return bytesToHex(sha256.doFinal(data.getBytes("UTF-8")));
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static String bytesToHex(byte[] bytes) {
char[] HEX_ARRAY = "0123456789abcdef".toCharArray();
char[] hexChars = new char[bytes.length * 2];
for (int j = 0; j < bytes.length; j++) {
int v = bytes[j] & 0xFF;
hexChars[j * 2] = HEX_ARRAY[v >>> 4];
hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
}
return new String(hexChars);
}
'apikey , secretKey , passPhrase' 的值也是时间戳的值,我用服务器检查过
解决方案
这也让我措手不及。密码是您账户的密码,而不是您使用的交易 6 位数代码。
推荐阅读
- c++ - AES/CTR 解密使用 Crypto++ 意外停止?
- react-hooks - 钩子回调中来自 useState 的变量被关闭
- python-3.x - 使用Python将新值插入SortedLinked List?
- java - 如何在另一个 LinkedList 的末尾分配一个 LinkedList 的一部分?
- r - 长到宽格式聚合 R tidyverse
- python - 如何在python中将字节转换为字符
- python - 在 PySpark RDD 上应用自定义文件解析器
- html - 如何将 div 与 img 对齐?
- powershell - 在 Windows Docker 容器中运行 Visual Studio C++ 2017 编译的可执行文件
- python - KeyError: 'image_url' Traceback (last recent call last) 烧瓶 api 响应错误