Browse Source

修改中兴数据对接接口

callm 1 month ago
parent
commit
e10dc0dcfb
1 changed files with 16 additions and 17 deletions
  1. 16 17
      UAS_MES_HYSX/PublicMethod/HttpServer.cs

+ 16 - 17
UAS_MES_HYSX/PublicMethod/HttpServer.cs

@@ -261,13 +261,12 @@ namespace UAS_MES_NEW.PublicMethod
                 }
             }
         }
-
-
     }
+
     public class HttpServer
     {
         static DataHelper dh = new DataHelper();
-        public static int SN_SERVICE_PORT = 8234;
+        public static int SN_SERVICE_PORT = 21610;
         public static int MAX_BUF_SIZE = 4096;
         static string ComputeSha256Hash(string input)
         {
@@ -304,17 +303,17 @@ namespace UAS_MES_NEW.PublicMethod
             obj.tool_name = "zte";
             obj.request = "Storage2";
             obj.User = "mes";
-            obj.password = "258456";
-            obj.po_sn = iSN;
+            obj.password = "Mes@hy_231019";
+            obj.po_sn = makecode;
             obj.wholeDeviceCode = "";
             obj.reg_code = regcode;
             obj.prefix_en_no = prefix;
             obj.prefix_big_box = "";
             obj.packing_num = "";
-            obj.isn = prefix;
+            obj.isn = iSN;
 
             string json = JsonConvert.SerializeObject(obj, Formatting.Indented);
-            string returnstr = SendData(json);
+            string returnstr = ToServerReq(json);
             JObject deviceObj = JObject.Parse(returnstr);
             string WholeDeviceCode = deviceObj["WholeDeviceCode"].ToString();
             string SN = deviceObj["SN"].ToString();
@@ -417,7 +416,7 @@ namespace UAS_MES_NEW.PublicMethod
             obj.packing_num = 20;
             obj.User = "mes";
             obj.po_sn = makecode;
-            obj.password = "258456";
+            obj.password = "Mes@hy_231019";
             obj.tool_name = "zte";
             obj.noType = 0;
 
@@ -446,9 +445,9 @@ namespace UAS_MES_NEW.PublicMethod
             {
                 dh.ExecuteSql("insert into ZTEDATA(ZD_ID,ZD_SN, ZD_MAKECODE, ZD_TYPE, ZD_VALUE,ZD_product_mode, ZD_PRODUCTNAME, ZD_MATERIAL_CODE, ZD_BATCH_NO, ZD_SOFT_VERSION, ZD_HD_VERSION, " +
                     "ZD_VOLTAGE, ZD_POWER, ZD_ORDER_NO, ZD_BIG_BOX_NO, ZD_D_SN, ZD_DEV_EN_NO, ZD_RESERVE3, ZD_DEVICEID, ZD_MAC_START, ZD_MAC_END,zd_production_date, ZD_INDATE)" +
-                    "values(ZTEDATA_seq.nextval,'" + deviceInfo.DSN[i] + "','','BOX','','" + deviceInfo.ProductName + "','" + deviceInfo.ProductName + "','" + deviceInfo.MaterialCode + "','" + deviceInfo.BatchNo + "','" + deviceInfo.SoftVersion + "','" + deviceInfo.HdVersion + "'," +
+                    "values(ZTEDATA_seq.nextval,'" + deviceInfo.DSN[i] + "','" + makecode + "','BOX','" + deviceInfo.DSN[i] + "','" + deviceInfo.ProductMode + "','" + deviceInfo.ProductName + "','" + deviceInfo.MaterialCode + "','" + deviceInfo.BatchNo + "','" + deviceInfo.SoftVersion + "','" + deviceInfo.HdVersion + "'," +
                     "'" + deviceInfo.Voltage + "','" + deviceInfo.Power + "','" + deviceInfo.OrderNo + "','" + deviceInfo.BigBoxNo + "','" + deviceInfo.DSN[i] + "'," +
-                    "'" + deviceInfo.Reserve3[i] + "','" + deviceInfo.DeviceId[i] + "','" + deviceInfo.MacStart[i] + "','" + deviceInfo.MacEnd[i] + "','" + deviceInfo.ProductionDate + "',sysdate)", "insert");
+                    "'" + deviceInfo.DevEnNo[i] + "', '" + deviceInfo.Reserve3[i] + "','" + deviceInfo.DeviceId[i] + "','" + deviceInfo.MacStart[i] + "','" + deviceInfo.MacEnd[i] + "','" + deviceInfo.ProductionDate + "',sysdate)", "insert");
             }
             Console.WriteLine(json);
         }
@@ -471,7 +470,7 @@ namespace UAS_MES_NEW.PublicMethod
             obj.packing_num = dt.Rows.Count;
             obj.User = "mes";
             obj.po_sn = makecode;
-            obj.password = "258456";
+            obj.password = "Mes@hy_231019";
             obj.tool_name = "zte";
 
             string json = JsonConvert.SerializeObject(obj, Formatting.Indented);
@@ -483,8 +482,8 @@ namespace UAS_MES_NEW.PublicMethod
         //发送数据
         public static string SendData(string json)
         {
-            string serverIP = "10.1.162.175";
-            int port = 8234;
+            string serverIP = "192.168.1.160";
+            int port = 21610;
 
             try
             {
@@ -493,7 +492,7 @@ namespace UAS_MES_NEW.PublicMethod
                 NetworkStream stream = client.GetStream();
 
                 // 发送数据
-                byte[] data = Encoding.UTF8.GetBytes(json);
+                byte[] data = BuildPacket(json);
                 stream.Write(data, 0, data.Length);
                 Console.WriteLine($"已发送请求: {json}");
 
@@ -510,7 +509,7 @@ namespace UAS_MES_NEW.PublicMethod
         private static string ReceiveDataSafely(NetworkStream stream)
         {
             MemoryStream ms = new MemoryStream();
-            byte[] buffer = new byte[1024];
+            byte[] buffer = new byte[8192];
             int totalBytesRead = 0;
             const int MAX_SIZE = 10 * 1024 * 1024;
 
@@ -590,7 +589,7 @@ namespace UAS_MES_NEW.PublicMethod
         public static string ToServerReq(string strJSON)
         {
             int nRet = 0;
-            string strServerIP = "10.1.162.175";
+            string strServerIP = "192.168.1.160";
             string strResp = "";
             IPAddress ip = IPAddress.Parse(strServerIP);
             Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
@@ -641,7 +640,7 @@ namespace UAS_MES_NEW.PublicMethod
                         nSize = stHead.getDatalen();
                         while (nPos < nSize)
                         {
-                            nRecvSize = clientSocket.Receive(bytRecv, nPos, 1869881979 - nPos, SocketFlags.None);
+                            nRecvSize = clientSocket.Receive(bytRecv, nPos, nSize - nPos, SocketFlags.None);
                             if (nRecvSize < 0)
                             {
                                 nRet = -14;