Пример #1
0
		///参见文档:http://btcchina.org/api-trade-documentation-zh
		///1. 使用如下强制的参数创建签名字符串。将键值对使用“&”符号按照下面列表的顺序连接在一起。请注意连接顺序很重要。所有的键名必须添加,但是键值可以为空 (例如 params)。
		///tonce (以毫秒为单位的时间戳,请确保您的系统时间准确)
		///accesskey (访问密匙,您可以在您的账户管理页面申请)
		///method (HTTP 请求方法,目前仅支持“post”)
		///id (JSON-RPC 请求 id)
		///method method (JSON-RPC 方法名称)
		///params (JSON-RPC 方法参数)

		public string AuthQuery(string method, Dictionary<string, string> postDict)
		{
			string tonce = GetTonce();
			Dictionary<string, string> parameters = new Dictionary<string, string>() { 
				{ "tonce", tonce },
				{ "accesskey",AuthKey.PublicKey },
				{ "requestmethod", "post" },
				{ "id", "1" },
				{ "method", method }				
			};

			string paramText = "";
			foreach (var item in postDict)
			{
				paramText += item.Value;
				paramText += ",";
			}
			paramText = paramText.Trim(',');
			parameters.Add("params", paramText);

			// bug:如果用了UrlEncode,将params中的“,”翻译掉了!会导致授权不成功!           
			string post = AuthUtility.ToPost(parameters, false);
			string sign = GetSign(post, AuthKey.PrivateKey);
			string base64String = Convert.ToBase64String(Encoding.ASCII.GetBytes(AuthKey.PublicKey + ':' + sign));
			string postData = "{\"method\": \"" + method + "\", \"params\": [" + paramText + "], \"id\": 1}";

			HttpWebRequest webRequest = GetWebRequest(base64String, tonce, postData);
			string json = AuthUtility.GetResponseJson(webRequest);
			return json;
		}
Пример #2
0
        public string AuthQuery(string path, Dictionary <string, string> postDict)
        {
            string nonce = AuthUtility.GetNonceByTicks();

            postDict.Add("nonce", nonce);

            string post     = AuthUtility.ToPost(postDict, true);
            var    signText = path + Convert.ToChar(0) + post;
            string sign     = GetSign(signText, AuthKey.PrivateKey);

            HttpWebRequest webRequest = GetWebRequest(post, path, sign);
            string         json       = AuthUtility.GetResponseJson(webRequest);

            return(json);
        }
Пример #3
0
        public string AuthQuery(string method, Dictionary <string, string> postDict)
        {
            string nonce = AuthUtility.GetNonceByTicks();

            postDict.Add("nonce", nonce);
            postDict.Add("method", method);
            string post = AuthUtility.ToPost(postDict, true);
            var    sign = AuthUtility.GetSign(post, AuthKey.PrivateKey);

            byte[]         data       = Encoding.ASCII.GetBytes(post);
            HttpWebRequest webRequest = GetWebRequest(data, sign);

            string json = AuthUtility.GetResponseJson(webRequest);

            return(json);
        }
Пример #4
0
        public string AuthQuery(string path, Dictionary <string, string> postDict)
        {
            string nonce    = AuthUtility.GetNonceByTicks();
            string clientId = Setting.Singleton.Option.BitstampClientId;

            //被签名信息为nonce+clientId+secretKey,签名后需加入到postText中:
            string signMessage = nonce + clientId + AuthKey.PublicKey;
            string sign        = GetSign(signMessage, AuthKey.PrivateKey);

            postDict.Add("nonce", nonce.ToString());
            postDict.Add("key", AuthKey.PublicKey);
            postDict.Add("signature", sign);

            string postText = AuthUtility.ToPost(postDict, true);

            byte[] postBytes = Encoding.ASCII.GetBytes(postText);

            HttpWebRequest webRequest = GetWebRequest(postBytes, path, sign);
            string         json       = AuthUtility.GetResponseJson(webRequest);

            return(json);
        }