using HMI.Core.Util; 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 sn, out string pn, out string msg) { pn = null; msg = string.Empty; try { string json = $"{{\"csn\":\"{sn}\",\"station_name\":\"OP170Burn-In老化\"}}"; 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(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; } } } }