<%@ WebHandler Language="C#" Class="DKService_ExHGS3QR_AddWorkInfoHGS3_QR" %> using System; using System.Web; using System.Web.SessionState; using Curtain.DataAccess; using DK.XuWei.WebMes; using Newtonsoft.Json.Linq; using Curtain.Log; using System.Collections; /// /// 给金马:扫码接口 /// xuwei fix 2022-05-28 增加try catch 增加容错 /// public class DKService_ExHGS3QR_AddWorkInfoHGS3_QR : IHttpHandler,IReadOnlySessionState { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //获取参数 string barcode = context.Request["barcode"] is object ? context.Request["barcode"] : ""; string procedure_no = context.Request["procedure_no"] is object ? context.Request["procedure_no"] : ""; string road_no = context.Request["road_no"] is object ? context.Request["road_no"] : "0"; string rack = context.Request["rack"] is object ? context.Request["rack"] : ""; string position = context.Request["position"] is object ? context.Request["position"] : ""; string procedure_in = context.Request["procedure_in"] is object ? context.Request["procedure_in"] : "1"; string jsonStr = ""; string apiResult = ""; bool apiStatus = false; try { //调用WCF接口 WCF wcf = new WCF(); wcf.Para.Add(new JProperty("barcode", barcode)); wcf.Para.Add(new JProperty("procedure_no", procedure_no)); wcf.Para.Add(new JProperty("road_no", road_no)); wcf.Para.Add(new JProperty("rack", rack)); wcf.Para.Add(new JProperty("position", position)); wcf.Para.Add(new JProperty("procedure_in", procedure_in)); jsonStr = wcf.Get("/DKService/ExHGS3QR/AddWorkInfoHGS3_QR"); //这个接口很小的机率会带出html标签=============================================== if (jsonStr.IndexOf("") > 0) jsonStr = jsonStr.Substring(0, jsonStr.IndexOf("")); //xuwei fix 2022-05-28 有时会带出 DOCTYPEhtml标签 jsonStr = jsonStr.Replace("",""); jsonStr = jsonStr.Replace("\\u000d\\u000a", "") .Replace("\\n","").Replace("\\","").Replace(" ","") .Replace("产品编码:"," 产品编码 ") .Replace("当前工序:"," 当前工序 ") .Replace("可到工序:"," 可到工序 ") .Replace("{\"d\":\"","") .Replace("\"}\"}","\"}") ; //处理输出结果 OK开头成功 NOK开头失败 JObject json = JObject.Parse(jsonStr); apiStatus = Convert.ToBoolean(json["success"]); } catch (Exception ex) { //输出错误日志文件 Logger.Error(ex, context.Request.UserHostAddress + "\r\n" + context.Request.Url + "\r\n" + jsonStr); } finally { //记录日志文件 Logger.Debug(context.Request.UserHostAddress + "\r\n" + context.Request.Url + "\r\n" +jsonStr); apiResult = jsonStr; context.Response.Write(apiResult); //记录接口调用日志 Hashtable ht = new Hashtable(); ht.Add("barcode", barcode); ht.Add("procedure_no", procedure_no); ht.Add("road_no", road_no); ht.Add("rack", rack); ht.Add("position", position); ht.Add("procedure_in", procedure_in); int apiId = Convert.ToInt32(procedure_no.Replace("_", "") + road_no + procedure_in); barcode = barcode.Replace("2c%", ","); int apiBarcodeCount = barcode.Split(',').Length; string apiUrl = "http://" + HttpContext.Current.Request.Url.Host + ":" + HttpContext.Current.Request.Url.Port.ToString() + "/api/DKService/ExHGS3QR/AddWorkInfoHGS3_QR/?" + JsonClient.ParaToString(ht); ApiLog.WriteApiLog("金马_扫码", apiUrl, apiStatus, apiResult, apiId, apiBarcodeCount); } } public bool IsReusable { get { return false; } } }