Ejemplo n.º 1
0
        /// <summary>
        /// 获取到所有的订单数据
        /// </summary>
        /// <returns></returns>
        public List <Order> GetOrders()
        {
            var nonce     = DataTransfer.GetNonce();
            var timestamp = DataTransfer.GetTimeStamp();
            var staffid   = "#9793932i82`/";
            //使用HttpClientHelper获取所有数据
            //singture参数是有时间戳+随机数+秘钥+数据
            string jsonStr = HttpClientHelper2.SendRequest("api/OrderAPI/GetOrders", "get", timestamp, nonce.ToString(), timestamp + nonce + staffid);

            //string jsonStr = HttpClientHelper.Send("get", "api/OrderAPI/GetOrders", null);
            //将json数据转化为list集合 并返回
            if (jsonStr != "未知原因,失败")
            {
                return(JsonConvert.DeserializeObject <List <Order> >(jsonStr));;
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        public void Edit(Order order)
        {
            //获取随机数
            var nonce = DataTransfer.GetNonce();
            //获取时间戳
            var timestamp = DataTransfer.GetTimeStamp();
            //秘钥
            var staffid = "#9793932i82`/";
            //data数据有时间戳+随机数+秘钥+传入数据
            var singture = timestamp + nonce + staffid;
            //反射获取传递的属性和值
            Type type = typeof(Order);

            //获取所有属性
            PropertyInfo[] pros = type.GetProperties();
            //定义一个有序字典
            SortedDictionary <string, string> pairs = new SortedDictionary <string, string>();

            //遍历属性
            foreach (var item in pros)
            {
                //将order属性和属性值放入字典
                pairs.Add(item.Name.ToString(), item.GetValue(order, null).ToString());
            }
            //进行有序排列
            foreach (var item in pairs.OrderBy(o => o.Key))
            {
                //data数据+到stigture
                singture += item.Key + item.Value.ToString();
            }
            //json序列化
            string str = JsonConvert.SerializeObject(order);
            //使用HttpClientHelper获取所有数据
            string jsonStr = HttpClientHelper2.SendRequest("api/OrderAPI/Upt", "put", timestamp, nonce.ToString(), singture, str);
            //string jsonStr = HttpClientHelper.Send("put", "api/OrderAPI/Upt", str);
        }