alielie
2026-06-04 771a0e7b6b1276087515bbe94de28358cb92963b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using HMI.Core.Util;
using log4net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Plugin.TestResult_WPF;
using System;
using System.Net.Http;
using System.Text;
 
namespace Plugin.TestResult.Util
{
    public class HttpResult
    {
        public int code { get; set; }
        public string msg { get; set; }
        public string ipn { get; set; }
    }
 
    public class PNUtil
    {
        public static bool GetPN(string mesAddress, string stationName, string sn, out string pn, out string msg)
        {
            pn = null;
            msg = string.Empty;
            try
            {
                //OP170Burn-In老化
                string json = $"{{\"csn\":\"{sn}\",\"station_name\":\"{stationName}\"}}";
                HttpClient val = new HttpClient();
                ViewControl.Logger.Debug($"Get PN Send: [{json}]");
                try
                {
                    StringContent val2 = new StringContent(json, Encoding.UTF8, "application/json");
                    HttpResponseMessage result = val.PostAsync($"http://{mesAddress}/mes-module-system-2.1.1/lixun/api/getPn", (HttpContent)(object)val2).Result;
                    result.EnsureSuccessStatusCode();
                    string resJson = result.Content.ReadAsStringAsync().Result;
                    HttpResult httpResult = JsonUtil.Deserialize<HttpResult>(resJson);
                    ViewControl.Logger.Debug($"Get PN Receive: [{resJson}]");
                    if (httpResult.code == 200)
                    {
                        pn = httpResult.ipn;
                        return true;
                    }
                    msg = httpResult.msg;
                    return false;
                }
                finally
                {
                    ((IDisposable)val)?.Dispose();
                }
            }
            catch (Exception ex)
            {
                ViewControl.Logger.Debug($"Get PN Error.", ex);
                msg = $"请求PN异常!{ex.Message}";
                return false;
            }
        }
 
 
        public static bool CheckIn(ILog log, string mesAddress, string stationName, string sn, out bool needCheckIn, out string msg)
        {
            JObject data = new JObject();
            data.Add("cmd", "QUERY_RECORD");
            data.Add("p", "UOP");
 
            data.Add("sn", sn);
            data.Add("station_name", stationName);
            data.Add("op", "A0000001");
 
            needCheckIn = false;
            msg = string.Empty;
            string sendData = string.Empty;
            string resData = null;
            try
            {
                sendData = data.ToString(Formatting.None);
                using (HttpClient val = new HttpClient())
                {
                    StringContent val2 = new StringContent(sendData, Encoding.UTF8, "application/json");
                    HttpResponseMessage result = val.PostAsync("http://" + mesAddress + "/mes-module-system-2.1.1/lixun/api/checkIn", (HttpContent)(object)val2).Result;
                    result.EnsureSuccessStatusCode();
                    resData = result.Content.ReadAsStringAsync().Result;
                    JObject httpResult = JObject.Parse(resData);
 
                    log.Info("CheckIn Send: " + httpResult.Value<string>("sendStr"));
                    log.Info("CheckIn Receive: " + httpResult.Value<string>("receiveStr"));
                    log.Info("CheckIn Get: " + resData);
 
                    msg = httpResult.Value<string>("msg");
                    if (httpResult.Value<int>("code") == 200)
                    {
                        needCheckIn = httpResult.Value<bool>("needCheckIn");
                        return true;
                    }
                    log.Error("CheckIn Error: " + msg);
                    return false;
                }
            }
            catch (Exception ex)
            {
                msg = ex.Message + " in " + ex.StackTrace + ".SendStr: " + sendData + ",ResultStr: " + resData;
                log.Error("CheckIn Unknow Error: " + msg);
                return false;
            }
        }
    }
}