Esempio n. 1
0
        /// <summary>
        /// 生成包括Sig,Method,Api_key在内的全部的参数
        /// </summary>
        /// <param name="method_name"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public KeyValue[] Sign(string method_name, KeyValue[] parameters)
        {
            List <KeyValue> list = new List <KeyValue>(parameters);

            list.Add(KeyValue.Create("method", method_name));               //指定调用的方法名
            list.Add(KeyValue.Create("api_key", api_key));                  //api_key
            list.Add(KeyValue.Create("call_id", DateTools.GetNow().Ticks)); //以时间戳作为call_id参数值
            list.Sort();
            StringBuilder values = new StringBuilder();

            foreach (KeyValue param in list)
            {
                if (!string.IsNullOrEmpty(param.Value))
                {
                    values.Append(param.ToString());
                }
            }
            values.Append(secret);          //指定Secret
            //生成sig
            byte[]        md5_result  = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(values.ToString()));
            StringBuilder sig_builder = new StringBuilder();

            foreach (byte b in md5_result)
            {
                sig_builder.Append(b.ToString("x2"));
            }
            list.Add(KeyValue.Create("sig", sig_builder.ToString()));
            return(list.ToArray());
        }
Esempio n. 2
0
        /// <summary>
        /// 获取API提交的参数
        /// </summary>
        /// <param name="request">request对象</param>
        /// <returns>参数数组</returns>
        private KeyValue[] GetParamsFromRequest(HttpRequest request)
        {
            List <KeyValue> list = new List <KeyValue>();

            foreach (string key in request.QueryString.AllKeys)
            {
                list.Add(KeyValue.Create(key, request.QueryString[key]));
            }
            foreach (string key in request.Form.AllKeys)
            {
                list.Add(KeyValue.Create(key, request.Form[key]));
            }
            list.Sort();
            return(list.ToArray());
        }