예제 #1
0
        protected override object[] HttpCallAuth(HttpClient _http, string _method, ref string _url, object[] _keyValues)
        {
            Dictionary <string, string> _list = new Dictionary <string, string>();

            for (int i = 0; i < _keyValues.Length; i += 2)
            {
                _list.Add(_keyValues[i].ToString(), _keyValues[i + 1].ToString());
            }
            //string _time = DateTimePlus.DateTime2JSTime(DateTime.UtcNow.AddSeconds(-1)).ToString() + DateTime.UtcNow.Millisecond.ToString();
            //_list.Add("timestamp", _time);

            string _sign = "";

            foreach (var _item in _list)
            {
                _sign += $"{_item.Key}={_item.Value}&";
            }
            if (_sign != "")
            {
                _sign = _sign.Remove(_sign.Length - 1);
            }
            _list.Add("signature", SHA.EncodeHMACSHA256ToHex(_sign, base.Secret).ToLower());

            IList <string> _keyValueList = new List <string>();

            foreach (KeyValuePair <string, string> _item in _list)
            {
                _keyValueList.Add(_item.Key);
                _keyValueList.Add(_item.Value);
            }
            _http.Headers.Add("X-MBX-APIKEY", base.Key);
            _http.Headers.Add("MediaType", "application/x-www-form-urlencoded");

            return(_keyValueList.ToArray());
        }
예제 #2
0
        protected override object[] HttpCallAuth(HttpClient _http, string _method, ref string _url, object[] _keyValues)
        {
            string _query = "";

            for (int i = 0; i < _keyValues.Length; i += 2)
            {
                _query += _query == "" ? "?" : "&";
                _query += $"{_keyValues[i].ToString()}={_keyValues[i + 1].ToString()}";
            }

            _http.Headers.Add("ACCESS-KEY", base.Key);
            long   _nonce = DateTimePlus.DateTime2JSTime(DateTime.UtcNow);
            string _time  = _nonce.ToString() + DateTime.UtcNow.Millisecond.ToString();

            _http.Headers.Add("ACCESS-NONCE", _time);
            string _signData = _time + _url + _query;
            string _sign     = SHA.EncodeHMACSHA256ToHex(_signData, base.Secret);

            _http.Headers.Add("ACCESS-SIGNATURE", _sign);

            return(_keyValues);
        }
예제 #3
0
        protected override object[] HttpCallAuth(HttpClient _http, string _method, ref string _url, object[] _keyValues)
        {
            string  _query = "";
            JObject _json  = new JObject();

            for (int i = 0; i < _keyValues.Length - 1; i += 2)
            {
                _query += _query == "" ? "" : "&";
                _query += _keyValues[i] + "=" + System.Web.HttpUtility.UrlEncode(_keyValues[i + 1].ToString());

                Type _valueType = _keyValues[i + 1].GetType();
                if (_valueType == typeof(int))
                {
                    _json[_keyValues[i]] = (int)_keyValues[i + 1];
                }
                else if (_valueType == typeof(bool))
                {
                    _json[_keyValues[i]] = (bool)_keyValues[i + 1];
                }
                else if (_valueType == typeof(decimal))
                {
                    _json[_keyValues[i]] = (decimal)_keyValues[i + 1];
                }
                else if (_valueType == typeof(long))
                {
                    _json[_keyValues[i]] = (long)_keyValues[i + 1];
                }
                else if (_valueType == typeof(JArray))
                {
                    _json[_keyValues[i]] = (JArray)_keyValues[i + 1];
                }
                else
                {
                    _json[_keyValues[i]] = _keyValues[i + 1].ToString();
                }
            }

            string _nonce = DateTimePlus.DateTime2JSTime(DateTime.UtcNow.AddHours(1)).ToString();
            string _sign  = _method;

            if (_method == "GET")
            {
                _url  += _query == "" ? "" : "?";
                _url  += _query;
                _sign += _url + _nonce;
            }
            else
            {
                _sign += _url + _nonce + _json.ToString(Newtonsoft.Json.Formatting.None);
            }
            _sign = SHA.EncodeHMACSHA256ToHex(_sign, base.Secret).ToLower();

            _http.Headers.Add("accept", "application/json");
            _http.Headers.Add("api-key", base.Key);
            _http.Headers.Add("api-signature", _sign);
            _http.Headers.Add("api-expires", _nonce);
            if (_method == "POST")
            {
                _http.ContentType = "application/json";
            }

            return(_keyValues);
        }