Esempio n. 1
0
        public static bool Report(string type, string report_id, string report_abstract_content = "", string report_abstract_id = "", string report_content = "", string order_id = "")
        {
            bool   flag;
            string str = "&report_id=" + report_id;

            if (type.ToString() == "1")
            {
                str = str + "&order_id=" + order_id;
            }
            string json = HttpUtils.Post(MicroPrinter.App.AppContext.Instance.BaseURL + "/report/index/?type=" + type, ((str + "&report_abstract_content=" + report_abstract_content) + "&report_abstract_id=" + report_abstract_id) + "&report_content=" + report_content, "");

            try
            {
                JObject obj2 = JObject.Parse(json);
                if ((obj2 == null) || (obj2["data"].ToString() == "[]"))
                {
                    flag = false;
                }
                else
                {
                    MsgDisplay.ContentUpdate("抱歉:当前遇到问题,请换一台设备取件!");
                    flag = obj2["status"].ToString() == "1";
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine("Report:" + exception.Message);
                flag = false;
            }
            return(flag);
        }
Esempio n. 2
0
        public static string Get(string Url, string needMachineCode = "1")
        {
            string json = "";

            try
            {
                string   machineCode = MicroPrinter.App.AppContext.Instance.MachineCode;
                string[] textArray1  = new string[] { "GetStart ", Url, " MachineCode:", machineCode, "; needMachineCode: ", needMachineCode, "; GetEnd" };
                Console.WriteLine(string.Concat(textArray1));
                if (((needMachineCode != "1") || (machineCode == string.Empty)) && (needMachineCode != "-1"))
                {
                    Console.WriteLine("Get cannot send");
                    string[] textArray2 = new string[] { " Get 请求未发出 :机器码 不存在,接口且要求传机器码!!!" };
                    Console.WriteLine(string.Concat(textArray2));
                }
                else
                {
                    Console.WriteLine("Get can send");
                    string text1 = Url + MicroPrinter.App.AppContext.Instance.UrlCommon;
                    Url = text1;
                    try
                    {
                        Console.WriteLine("try to send Get request start");
                        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
                        request.Proxy                  = null;
                        request.KeepAlive              = false;
                        request.Method                 = "GET";
                        request.ContentType            = "application/json; charset=UTF-8";
                        request.AutomaticDecompression = DecompressionMethods.GZip;
                        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                        StreamReader    reader1  = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                        string          str3     = reader1.ReadToEnd();
                        reader1.Close();
                        Stream responseStream = response.GetResponseStream();
                        responseStream.Close();
                        if (response != null)
                        {
                            response.Close();
                        }
                        if (request != null)
                        {
                            request.Abort();
                        }
                        json = str3;
                        Console.WriteLine("try to send Get request end");
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine("Get 网络异常: " + exception.Message);
                        MsgDisplay.ContentUpdate("提示:网络异常,请检查网络连接");
                        json = null;
                    }
                    JObject obj2 = JObject.Parse(json);
                    Console.Write("当前时间:" + $"{DateTime.Now}");
                    Console.WriteLine(" Get 请求服务器 from : " + Url);
                    Console.Write("当前时间:" + $"{DateTime.Now}");
                    Console.WriteLine(" Get 服务器返回:" + obj2);
                    if (obj2["status"].ToString() != "1")
                    {
                        MsgDisplay.ContentUpdate("提示:" + obj2["msg"].ToString());
                    }
                }
            }
            catch (Exception exception2)
            {
                Console.WriteLine("Get Exception: " + exception2.Message);
                json = null;
            }
            return(json);
        }