簡體   English   中英

關於Binance Api簽名端點的Http響應400

[英]Http Response 400 on Binance Api Signed Endpoint

我試圖將GET請求發送到Binance上的User Account Endpoint。 雖然我仍然收到Http Response 400,但我在做什么錯呢? 這是我的代碼

public JSONObject getUserAccountData(String timeStamp ) {

    JSONObject json = null;
    try {
        String secret = apikey.get("secret");
        // https:///api.binance.com/api/v3/account
        String uri = ACCOUNT_URL_V3;
        String params = "recvWindow=" + DEFAULT_RECWINDOW + "&timestamp=" + timeStamp ;
        String fullUri = uri + "?" + params;
        map.put("signature", Encryptor.getHmacSha256(secret,params ));
        fullUri =fullUri+ "&signature="+ map.get("signature");

         String result = HTTPUtil.requestGet(fullUri , "application/json", map.get("X-MBX-APIKEY"));

        return json.getJSONObject("result");
    } catch (Exception ex) {
        logger.error("Failed getting user account data " + ex.getMessage());
    } finally {
        return json;
    }
}

我確實使用SHA256簽署了我的秘密密鑰

public static String getHmacSha256(String key, String data) {
    Mac sha256;
    String result = null;

    try {
        byte[] byteKey = key.getBytes("UTF-8");
        sha256 = Mac.getInstance(HMAC_SHA256);
        SecretKeySpec keySpec = new SecretKeySpec(byteKey, HMAC_SHA256);
        sha256.init(keySpec);
        byte[] macData = sha256.doFinal(data.getBytes("UTF-8"));
        result = bytesToHex(macData);
    }
    catch(Exception e) {
        e.printStackTrace();
    }
    return result;
}

這是GET實現(適用於Bitterex API調用)

public static String requestGet(String strUrl, String accept,String apiKeyForGet) throws Exception {
    URL url = new URL(strUrl);
    HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();

    conn.setDoOutput(true);
    conn.setRequestMethod("GET");
    conn.setRequestProperty("Accept", accept);
     conn.setRequestProperty("X-MBX-APIKEY", apiKeyForGet);
    conn.setConnectTimeout(5000);
    conn.connect();

    if(conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
         throw new Exception();
    }

    BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String inputLine;
    StringBuffer response = new StringBuffer();

    while ((inputLine = in.readLine()) != null) {
        response.append(inputLine);
    }
    in.close();

    return response.toString();
}

我得到的最終URI是:
https://api.binance.com/api/v3/account?recvWindow=5000&timestamp=1523987972841&signature=3125BEE36896E464122A1CA73EB6FFA18881CB33FDE6927CC3676C8F969EC2A0

將時間戳與以下幣安時間戳同步:

對我來說,這是格林尼治標准時間+ 2,所以我創建了使我的時間戳類似-(3600 * 2)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM