C#Coinbase api返回错误“:[{” id“:” authentication_error“,”消息“:”无效签名“}]}

时间:2018-11-06 18:25:28

标签: coinbase-api

我尝试执行BTC命令,但收到无效的访问错误。 我在后面使用的代码。

public string Transfer()
        {
            unixTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
            TransferInput data = new TransferInput();
            data.to = "3d64cd26-9c1e-5b24-8a6a-242cbb48a40a";
            data.amount = "0.00000001";
            data.type = "transfer";
            data.currency = "BTC";
            string body = Newtonsoft.Json.JsonConvert.SerializeObject(data);
            string message = unixTimestamp.ToString() + "POST" + "/v2/accounts/5ebedea2-b646-5fda-9409-8b1d9f1add1c/transactions" + body;
            string signature = GetSignature(message);
            var _client = new RestClient("https://api.coinbase.com/v2/");
            var request = new RestRequest("accounts/5ebedea2-b646-5fda-9409-8b1d9f1add1c/transactions", Method.POST);
            request.AddHeader("Content-Type", "application/json");
            request.AddHeader("CB-ACCESS-KEY", ApiKey);
            request.AddHeader("CB-ACCESS-SIGN", signature);
            request.AddHeader("CB-ACCESS-TIMESTAMP", unixTimestamp.ToString());
            request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; resp.Content = body; };
            var response = _client.Execute(request);
            string a= _client.Execute(request).Content;
            return a;
        }

还有

public string GetSignature(string message)
        {
            byte[] secretKey = Encoding.UTF8.GetBytes(ApiSecret);
            HMACSHA256 hmac = new HMACSHA256(secretKey);
            hmac.Initialize();
            byte[] bytes = Encoding.UTF8.GetBytes(message);
            byte[] rawHmac = hmac.ComputeHash(bytes);
            string signature = rawHmac.ByteArrayToHexString();
            return signature;
        }

抛出错误:[{“ id”:“ authentication_error”,“消息”:“无效签名”}]}}

请帮助我!非常感谢!

0 个答案:

没有答案