Преглед на файлове

添加调用服务端注册接口

callm преди 2 седмици
родител
ревизия
0b116a8609

+ 7 - 0
UAS_MES_YDCY/.workbuddy/memory/2026-11-09.md

@@ -0,0 +1,7 @@
+# 2026-11-09
+
+## Query_LoadMan:人员编号格式卡控
+- `DoEmCode()` 空值判断之后加:
+  `if (emcode.Length != 7 || !emcode.StartsWith("500"))` → 红字「xxx 人员编号格式错误,必须为500开头的7位编号」+ `em_code.Clear()` + Focus + return。
+- 上/下线两个入口共用(同一方法),放大镜选线别不受影响。
+- 未设 `MaxLength`(避免粘贴被截断误导),靠提示拦截。

+ 17 - 0
UAS_MES_YDCY/.workbuddy/memory/2026-11-10.md

@@ -0,0 +1,17 @@
+# 2026-11-10
+
+## LogicHandler:新增 EIS dllMain 接口公用方法
+- `PublicMethod/LogicHandler.cs` 末尾加 `#region EIS dllMain 接口`:
+  - `PostEisHelper(iType, iDetail, out iErrorMessage)`:POST JSON 到 `http://192.168.0.85:8099/EIS/MES/helper/dllMain`,头 Accesskey=CYZZ / Requestid=每次新GUID / AccessSecret=aqwe@1143erggG / Signature / Timestamp=毫秒;body `{"type":iType,"detail":iDetail}`,JavaScriptSerializer 序列化(项目已引用 System.Web.Extensions)。
+  - `GetEisSignature(timestamp)`:**签名算法未确认**,占位实现 MD5(Accesskey+AccessSecret+Timestamp) 大写;已用样例值碰撞 MD5/SHA1/SHA256 各拼接组合均不匹配 Postman 里的 Signature=13BCF1A25749A52C23A2F8ED91BBA20E,联调不过要改这里。
+  - `CheckMDMRegistration(iSN,iMakeCode,iSourceCode,iUserCode,out err)`:封装 type=CheckMDMRegistration,detail 四字段 iSN/iMakeCode/iSourceCode/iUserCode。
+- 新增 using:System.IO / System.Net / System.Web.Script.Serialization。
+
+## CheckMDMRegistration 改为 bool(拿到返回报文后)
+- 报文格式:`{"code":"0","message":"success","requestId":"...","data":{"oErrMessage":"..."}}`
+- `CheckMDMRegistration(...) → bool`:`code` 非 "0" → false(带 message);再取 `data.oErrMessage`,空 → true,非空 → false 并把 oErrMessage 作为错误信息。
+- 解析用 JavaScriptSerializer 转 `Dictionary<string,object>`(嵌套 data 也是字典),配 `GetJsonValue(dict,key)` 私有方法取值(键缺失/null 返回空串)。
+- `PostEisHelper` 保持不变,仍返回响应原文供其它 type 复用。
+- 注意:`System.DateTime` 是用户手工改的(未回退),保留。
+- 用户强调报文只是示例:所有错误提示必须取自实际响应,不得硬编码示例值。已改为 code!=0 显示 message(空则原文)、解析失败/结构异常拼上接口原文;全库确认无 "not_found"/"No enrolled device" 字样。
+

+ 1 - 1
UAS_MES_YDCY/FunctionCode/Make/Make_Repair67F.cs

@@ -586,7 +586,7 @@ namespace UAS_MES_NEW.Make
             sql.Append("spr_regex,max(pr_detail)pr_detail,max(substr(pr_detail,0,20))pr_spec from stepproductrep left join product on pr_code=spr_fsoncode where ");
             sql.Append("spr_bomversion='" + ma_bomversion + "' and spr_craftcode='" + cr_code.Text + "' and instr('" + ms_paststep + "',spr_stepcode)>0 ");
             sql.Append("And spr_mothercode ='" + ms_prodcode.Text + "' and spr_tracekind=1  and  nvl(pr_prodtype,' ')<>'包装物料' group by spr_fsoncode,spr_id,spr_spid ");
-            sql.Append(") group by case when spr_isreplace=-1 then to_char(spr_isreplace) else sp_fsoncode end,sp_id order by sp_id) where  not exists(select 1 from craftmaterial where cm_sncode in (select '" + firstsn + "' from dual union select sn from makesnrelation where firstsn='" + firstsn + "') and cm_makecode='" + ms_makecode.Text + "'and instr(sp_fsoncode,cm_fsoncode)>0 and cm_status=0)");
+            sql.Append(") group by case when spr_isreplace=-1 then to_char(spr_isreplace) else sp_fsoncode end,sp_id order by sp_id) where  not exists(select 1 from craftmaterial where cm_sncode in (select '" + firstsn + "' from dual union select sn from makesnrelation where firstsn='" + firstsn + "') and cm_makecode='" + ms_makecode.Text + "'and instr(sp_soncode,cm_soncode)>0 and cm_status=0)");
             dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
             ////如果含有序列号物料有被拆解过
             if (dt.Rows.Count > 0)

+ 8 - 0
UAS_MES_YDCY/FunctionCode/Query/Query_LoadMan.cs

@@ -114,6 +114,14 @@ namespace UAS_MES_NEW.Query
                 OperateResult.AppendText("<<人员工号不能为空\n", Color.Red, em_code);
                 return;
             }
+            //人员编号格式卡控:必须是以 500 开头的 7 位编号
+            if (emcode.Length != 7 || !emcode.StartsWith("500"))
+            {
+                OperateResult.AppendText("<<" + emcode + " 人员编号格式错误,必须为500开头的7位编号\n", Color.Red);
+                em_code.Clear();
+                em_code.Focus();
+                return;
+            }
             //线别卡控(上/下线均适用):必须先选线别,且线别必须在登录人长线范围内
             if (linecode == "")
             {

+ 158 - 0
UAS_MES_YDCY/PublicMethod/LogicHandler.cs

@@ -6,7 +6,10 @@ using System;
 using System.Collections.Generic;
 using System.Data;
 using System.Drawing;
+using System.IO;
+using System.Net;
 using System.Text;
+using System.Web.Script.Serialization;
 using System.Windows;
 using System.Windows.Forms;
 using UAS_MES_NEW.DataOperate;
@@ -2127,5 +2130,160 @@ namespace UAS_MES_NEW.PublicMethod
                 return false;
             }
         }
+
+        #region EIS dllMain 接口
+
+        //EIS 接口地址与鉴权信息
+        private const string EIS_URL = "http://192.168.0.85:8099/EIS/MES/helper/dllMain";
+        private const string EIS_ACCESSKEY = "CYZZ";
+        private const string EIS_ACCESSSECRET = "aqwe@1143erggG";
+
+        /// <summary>
+        /// 通用调用 EIS/MES/helper/dllMain 接口(POST JSON)
+        /// 请求体: {"type":"<iType>","detail":{...}}
+        /// 请求头: Accesskey / Requestid / AccessSecret / Signature / Timestamp
+        /// 返回接口响应原文;请求失败返回 null 并给出 iErrorMessage
+        /// </summary>
+        public static string PostEisHelper(string iType, Dictionary<string, object> iDetail, out string iErrorMessage)
+        {
+            iErrorMessage = "";
+            try
+            {
+                //毫秒级时间戳
+                string timestamp = ((long)(System.DateTime.UtcNow - new System.DateTime(1970, 1, 1)).TotalMilliseconds).ToString();
+                //每次请求生成一个 GUID 作为请求标识
+                string requestId = Guid.NewGuid().ToString().ToUpper();
+                string signature = GetEisSignature(timestamp);
+                //组装请求体 {"type":"...","detail":{...}}
+                Dictionary<string, object> body = new Dictionary<string, object>();
+                body.Add("type", iType);
+                body.Add("detail", iDetail);
+                JavaScriptSerializer jss = new JavaScriptSerializer();
+                string postData = jss.Serialize(body);
+
+                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(EIS_URL);
+                request.Method = "POST";
+                request.ContentType = "application/json";
+                request.Timeout = 30 * 1000;
+                request.Headers.Add("Accesskey", EIS_ACCESSKEY);
+                request.Headers.Add("Requestid", requestId);
+                request.Headers.Add("AccessSecret", EIS_ACCESSSECRET);
+                request.Headers.Add("Signature", signature);
+                request.Headers.Add("Timestamp", timestamp);
+                byte[] data = Encoding.UTF8.GetBytes(postData);
+                request.ContentLength = data.Length;
+                using (Stream rs = request.GetRequestStream())
+                {
+                    rs.Write(data, 0, data.Length);
+                }
+                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
+                using (StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
+                {
+                    return sr.ReadToEnd();
+                }
+            }
+            catch (Exception ex)
+            {
+                iErrorMessage = "请求EIS接口失败:" + ex.Message;
+                return null;
+            }
+        }
+
+        /// <summary>
+        /// 计算 EIS 接口 Signature
+        /// 注意:签名算法未在接口文档中确认,当前按 MD5(Accesskey + AccessSecret + Timestamp) 大写实现,
+        /// 与 Postman 样例值不一致,若联调返回签名错误,请按接口方规则修改本方法
+        /// </summary>
+        private static string GetEisSignature(string timestamp)
+        {
+            string source = EIS_ACCESSKEY + EIS_ACCESSSECRET + timestamp;
+            using (var md5 = System.Security.Cryptography.MD5.Create())
+            {
+                byte[] bytes = md5.ComputeHash(Encoding.UTF8.GetBytes(source));
+                StringBuilder sb = new StringBuilder();
+                for (int i = 0; i < bytes.Length; i++)
+                {
+                    sb.Append(bytes[i].ToString("X2"));
+                }
+                return sb.ToString();
+            }
+        }
+
+        /// <summary>
+        /// 校验 MDM 注册:调用 EIS 接口 type=CheckMDMRegistration
+        /// 返回报文结构:code/message/requestId/data,业务结果字段为 data.oErrMessage
+        /// 所有提示信息均取自接口实际返回内容(不做硬编码),oErrMessage 为空视为校验通过
+        /// </summary>
+        public static bool CheckMDMRegistration(string iSN, string iMakeCode, string iSourceCode, string iUserCode, out string iErrorMessage)
+        {
+            iErrorMessage = "";
+            Dictionary<string, object> detail = new Dictionary<string, object>();
+            detail.Add("iSN", iSN);
+            detail.Add("iMakeCode", iMakeCode);
+            detail.Add("iSourceCode", iSourceCode);
+            detail.Add("iUserCode", iUserCode);
+            string response = PostEisHelper("CheckMDMRegistration", detail, out iErrorMessage);
+            //请求本身失败(网络/超时等),PostEisHelper 已带出错误信息
+            if (response == null)
+            {
+                if (iErrorMessage == "")
+                {
+                    iErrorMessage = "MDM注册校验请求失败";
+                }
+                return false;
+            }
+            try
+            {
+                JavaScriptSerializer jss = new JavaScriptSerializer();
+                Dictionary<string, object> root = jss.Deserialize<Dictionary<string, object>>(response);
+                if (root == null)
+                {
+                    //解析不出结构,直接把接口原文带出去
+                    iErrorMessage = response.Trim();
+                    return false;
+                }
+                //接口整体返回码,0 为成功;非 0 时优先展示 message,没有 message 就展示接口原文
+                string code = GetJsonValue(root, "code");
+                if (code != "" && code != "0")
+                {
+                    string message = GetJsonValue(root, "message");
+                    iErrorMessage = message == "" ? response.Trim() : message;
+                    return false;
+                }
+                //业务结果看 data.oErrMessage,为空表示校验通过
+                Dictionary<string, object> data = null;
+                if (root.ContainsKey("data") && root["data"] != null)
+                {
+                    data = root["data"] as Dictionary<string, object>;
+                }
+                string oErrMessage = data == null ? "" : GetJsonValue(data, "oErrMessage");
+                if (oErrMessage != "")
+                {
+                    iErrorMessage = oErrMessage;
+                    return false;
+                }
+                return true;
+            }
+            catch (Exception ex)
+            {
+                //解析异常时保留接口原始返回,便于排查
+                iErrorMessage = "解析MDM注册校验报文失败:" + ex.Message + ",接口返回:" + response.Trim();
+                return false;
+            }
+        }
+
+        /// <summary>
+        /// 取 JSON 对象里的字符串值(键不存在或值为 null 时返回空串)
+        /// </summary>
+        private static string GetJsonValue(Dictionary<string, object> iJson, string iKey)
+        {
+            if (iJson == null || !iJson.ContainsKey(iKey) || iJson[iKey] == null)
+            {
+                return "";
+            }
+            return iJson[iKey].ToString().Trim();
+        }
+
+        #endregion
     }
 }