Ejemplo n.º 1
0
        public override string PrinterRequest(PrintParameter parameter, Data.Printer printer)
        {
            string        orderinfo = GetRequsetContent(parameter, printer.PrintWay);
            string        order     = Uri.UnescapeDataString(orderinfo.ToString());
            StringBuilder postData  = new StringBuilder("sn=" + parameter.SN);

            postData.Append($"&content={order}");
            postData.Append($"&times={(string.IsNullOrEmpty(parameter.Times) || !int.TryParse(parameter.Times, out int times) ? 1 + "" : parameter.Times)}");
            // int itime = DateTimeToStamp(System.DateTime.Now);//时间戳秒数
            int    stime = PrintTools.GetTotalSeconds(DateTime.Now);
            string sig   = PrintTools.Sha1(USer, UKey, stime + "");

            postData.Append("&user="******"&stime=" + stime);
            postData.Append("&sig=" + sig);
            postData.Append("&apiname=Open_printMsg");
            string result = PrintRequest.RequestMethod(postData.ToString(), Url, Encoding.UTF8);

            return(result);
        }
Ejemplo n.º 2
0
        public void TestMethod1()
        {
            using (PrintDbContext printDb = TPrintDbFactory.MarkShopDb())
            {
                var parameter = new ZRui.Web.Core.Printer.PrintAPIArgsModel.AddPrinter()
                {
                    shopId      = 4,
                    sn          = "817513721",
                    skey        = "ew64m5j4",
                    printerType = PrinterType.FEIE
                };

                using (ShopDbContext shopDb = TShopDbContxtFactory.MarkShopDb())
                {
                    if (string.IsNullOrEmpty(parameter.sn))
                    {
                        Error("SnList(打印机#KEY)参数不能为空");
                    }
                    if (!parameter.shopId.HasValue)
                    {
                        Error("商铺ID不能为空");
                    }
                    if (!parameter.printerType.HasValue)
                    {
                        Error("打印机类型不能为空");
                    }
                    Shop shop = shopDb.GetSingle <Shop>(parameter.shopId.Value);
                    if (shop == null)
                    {
                        Error("商铺不存在");
                    }
                    //表示是否已经添加过
                    Data.Printer printer = printDb.Printer.FirstOrDefault(s => !s.IsDel && s.ShopID == parameter.shopId && s.SN == parameter.sn &&
                                                                          s.SKey == parameter.skey && s.IsSuccess);
                    bool IsExists = printer != null;
                    if (IsExists)
                    {
                        Error("设备已经添加过");
                    }
                    PrinterBase @base  = PrinterFactory.Create(parameter.printerType.Value);//)
                    string      result = @base.AddPrinter(new PrintParameter()
                    {
                        SnList = $"{parameter.sn}#{parameter.skey}#"
                    });
                    //添加之后保存到数据库中
                    Dictionary <string, object> tempdic = JsonConvert.DeserializeObject <Dictionary <string, object> >(result);
                    if (!tempdic.ContainsKey("data"))
                    {
                        Error("添加失败");
                    }

                    Data.Printer _printermodel = new Data.Printer();
                    #region 实体赋值
                    _printermodel.ShopID      = parameter.shopId.Value;
                    _printermodel.SN          = parameter.sn;
                    _printermodel.SKey        = parameter.skey;
                    _printermodel.AddTime     = DateTime.Now;
                    _printermodel.PrinterType = parameter.printerType.Value;
                    _printermodel.IsEnable    = true;
                    //_printermodel.Times = string.IsNullOrEmpty(parameter.Times) || int.TryParse(parameter.Times, out int t) ? 1 : t == 0 ? 1 : t;
                    Dictionary <string, object> datadic = JsonConvert.DeserializeObject <Dictionary <string, object> >(tempdic["data"].ToString());
                    JArray ok = datadic["ok"] as JArray;
                    JArray no = datadic["no"] as JArray;
                    //验证打印机是否在接口添加成功
                    //如果之前添加失败了, 将修改原来的数据,否则重新添加
                    #endregion

                    if (ok.Count > 0)
                    {
                    }
                    else
                    {
                        Error(no[0].Value <string>());
                    }
                }
            }

            void Error(string s)
            {
            };
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 打印方法
 /// </summary>
 /// <param name="parameter"></param>
 /// <returns></returns>
 public virtual string PrinterRequest(PrintParameter parameter, Data.Printer printer)
 {
     return("[{msg:未添加打印机品牌}]");
 }
Ejemplo n.º 4
0
        public APIResult AddPrinter([FromBody] AddPrinter parameter)
        {
            if (string.IsNullOrEmpty(parameter.PrinterName))
            {
                return(Error("打印机名称不能为空"));
            }
            if (string.IsNullOrEmpty(parameter.sn))
            {
                return(Error("SnList(打印机#KEY)参数不能为空"));
            }
            if (!parameter.shopId.HasValue)
            {
                return(Error("商铺ID不能为空"));
            }
            if (!parameter.printerType.HasValue)
            {
                return(Error("打印机类型不能为空"));
            }
            if (!parameter.printWay.HasValue)
            {
                return(Error("打印机方式不能为空"));
            }
            Shop shop = shopDb.GetSingle <Shop>(parameter.shopId.Value);

            if (shop == null)
            {
                return(Error("商铺不存在"));
            }
            //表示是否已经添加过
            Data.Printer printer = printDb.Printer.FirstOrDefault(s => !s.IsDel && s.SN == parameter.sn &&
                                                                  s.SKey == parameter.skey && s.PrinterType == parameter.printerType);
            bool IsExists = printer != null;

            if (IsExists)
            {
                if (printer.ShopID == shop.Id)
                {
                    return(Error("该设备已经添加过"));
                }
                else
                {
                    return(Error("该设备已经被别的商家添加过"));
                }
            }
            PrinterBase @base  = PrinterFactory.Create(parameter.printerType.Value);//)
            string      result = @base.AddPrinter(new PrintParameter()
            {
                SnList = $"{parameter.sn}#{parameter.skey}#"
            });
            //添加之后保存到数据库中
            Dictionary <string, object> tempdic = JsonConvert.DeserializeObject <Dictionary <string, object> >(result);

            if (!tempdic.ContainsKey("data"))
            {
                return(Error("添加失败"));
            }

            Data.Printer _printermodel = new Data.Printer();
            #region 实体赋值
            _printermodel.ShopID      = parameter.shopId.Value;
            _printermodel.SN          = parameter.sn;
            _printermodel.PrinterName = parameter.PrinterName;
            _printermodel.SKey        = parameter.skey;
            _printermodel.AddTime     = DateTime.Now;
            _printermodel.PrinterType = parameter.printerType.Value;
            _printermodel.PrintWay    = parameter.printWay.Value;
            _printermodel.IsEnable    = true;
            _printermodel.IsSuccess   = true;
            //_printermodel.Times = string.IsNullOrEmpty(parameter.Times) || int.TryParse(parameter.Times, out int t) ? 1 : t == 0 ? 1 : t;
            Dictionary <string, object> datadic = JsonConvert.DeserializeObject <Dictionary <string, object> >(tempdic["data"].ToString());
            JArray ok = datadic["ok"] as JArray;
            JArray no = datadic["no"] as JArray;
            //验证打印机是否在接口添加成功
            //如果之前添加失败了, 将修改原来的数据,否则重新添加
            #endregion

            if (ok.Count > 0)
            {
                printDb.AddTo(_printermodel);
                printDb.SaveChanges();
                return(Success(_printermodel));
            }
            else if (no.Count > 0)
            {
                string mes   = no[0].Value <string>();
                Regex  regex = new Regex(@".*添加过.*");
                if (regex.IsMatch(mes))
                {
                    printDb.AddTo(_printermodel);
                    printDb.SaveChanges();
                    return(Success(_printermodel));
                }
                else
                {
                    return(Error(mes));
                }
            }
            else
            {
                return(Error("添加打印机到供应商后台失败"));
            }
        }