Commit df26cf7a 刘韬

客户更新API接口,配合更新

1 个父辈 4825c196
using OnlineStore.Common; using OnlineStore.Common;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Net;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
...@@ -19,14 +21,16 @@ namespace DeviceLibrary ...@@ -19,14 +21,16 @@ namespace DeviceLibrary
public static CountResult inputCounterDataByXRayMachine(string TwoDBarcode, int qty) public static CountResult inputCounterDataByXRayMachine(string TwoDBarcode, int qty)
{ {
var wc = new MyWebClient(15000); var wc = new MyWebClient(15000);
if (string.IsNullOrEmpty(wc.Headers["Content-Type"])) //if (string.IsNullOrEmpty(wc.Headers["Content-Type"]))
wc.Headers.Add("Content-Type", "application/json;charset=UTF-8"); // wc.Headers.Add("Content-Type", "application/json;charset=UTF-8");
wc.Headers[HttpRequestHeader.ContentType] = "application/json; charset=utf-8";
wc.Encoding = Encoding.UTF8; wc.Encoding = Encoding.UTF8;
var data = new Wiston_Request(); var data = new Wiston_Request();
data.userId = "Q14050052"; data.userId = "Q14050052";
data.language = 1; data.language = 1;
data.requestTime = 0; data.requestTime = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
data.data.Add("TwoDBarcode", TwoDBarcode); data.data.Add("TwoDBarcode", TwoDBarcode);
data.data.Add("Qty", qty); data.data.Add("Qty", qty);
data.data.Add("Counter", ConfigHelper.Config.Get("upload_Counter")); data.data.Add("Counter", ConfigHelper.Config.Get("upload_Counter"));
...@@ -40,6 +44,23 @@ namespace DeviceLibrary ...@@ -40,6 +44,23 @@ namespace DeviceLibrary
result = wc.UploadString(ConfigHelper.Config.Get("inputCounterDataByXRayMachine"), "POST", json); result = wc.UploadString(ConfigHelper.Config.Get("inputCounterDataByXRayMachine"), "POST", json);
return JsonHelper.DeserializeJsonToObject<CountResult>(result); return JsonHelper.DeserializeJsonToObject<CountResult>(result);
} }
catch (WebException ex) // 先捕获 HTTP 级异常
{
string respBody = null;
if (ex.Response != null)
{
using (var sr = new StreamReader(ex.Response.GetResponseStream()))
respBody = sr.ReadToEnd();
}
LogUtil.info($"inputCounterDataByXRayMachine url:{ConfigHelper.Config.Get("inputCounterDataByXRayMachine")} retry:{retry}, " +
$"status:{(int?)((HttpWebResponse)ex.Response)?.StatusCode}, " +
$"responseBody:{respBody}, " +
$"exception:{ex}");
retry++;
if (retry < 3) goto retry;
return null;
}
catch (Exception e) catch (Exception e)
{ {
LogUtil.info($"inputCounterDataByXRayMachine retry:{retry}, {e.ToString()}"); LogUtil.info($"inputCounterDataByXRayMachine retry:{retry}, {e.ToString()}");
...@@ -58,14 +79,18 @@ namespace DeviceLibrary ...@@ -58,14 +79,18 @@ namespace DeviceLibrary
public static ReelLocation DetermineReelStorageLocation(string TwoDBarcode) public static ReelLocation DetermineReelStorageLocation(string TwoDBarcode)
{ {
var wc = new MyWebClient(15000); var wc = new MyWebClient(15000);
if (string.IsNullOrEmpty(wc.Headers["Content-Type"])) //if (string.IsNullOrEmpty(wc.Headers["Content-Type"]))
wc.Headers.Add("Content-Type", "application/json;charset=UTF-8"); // wc.Headers.Add("Content-Type", "application/json;charset=UTF-8");
wc.Headers[HttpRequestHeader.ContentType] = "application/json; charset=utf-8";
wc.Headers.Add("Accept", "application/json");
wc.Encoding = Encoding.UTF8; wc.Encoding = Encoding.UTF8;
var data = new Wiston_Request(); var data = new Wiston_Request();
data.userId = "Q14050052"; data.userId = "Q14050052";
data.language = 1; data.language = 0;
data.requestTime = 0; data.requestTime = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
//data.requestTime = 0;
data.data.Add("str2DBarcode", TwoDBarcode); data.data.Add("str2DBarcode", TwoDBarcode);
data.data.Add("labelPrinter", ConfigHelper.Config.Get("upload_labelPrinter")); data.data.Add("labelPrinter", ConfigHelper.Config.Get("upload_labelPrinter"));
...@@ -79,6 +104,23 @@ namespace DeviceLibrary ...@@ -79,6 +104,23 @@ namespace DeviceLibrary
result = wc.UploadString(ConfigHelper.Config.Get("DetermineReelStorageLocation"), "POST", json); result = wc.UploadString(ConfigHelper.Config.Get("DetermineReelStorageLocation"), "POST", json);
return JsonHelper.DeserializeJsonToObject<ReelLocation>(result); return JsonHelper.DeserializeJsonToObject<ReelLocation>(result);
} }
catch (WebException ex) // 先捕获 HTTP 级异常
{
string respBody = null;
if (ex.Response != null)
{
using (var sr = new StreamReader(ex.Response.GetResponseStream()))
respBody = sr.ReadToEnd();
}
LogUtil.info($"DetermineReelStorageLocation url:{ConfigHelper.Config.Get("DetermineReelStorageLocation")} retry:{retry}, " +
$"status:{(int?)((HttpWebResponse)ex.Response)?.StatusCode}, " +
$"responseBody:{respBody}, " +
$"exception:{ex}");
retry++;
if (retry < 3) goto retry;
return null;
}
catch (Exception e) catch (Exception e)
{ {
LogUtil.info($"DetermineReelStorageLocation retry:{retry}, {e.ToString()}"); LogUtil.info($"DetermineReelStorageLocation retry:{retry}, {e.ToString()}");
...@@ -99,7 +141,14 @@ namespace DeviceLibrary ...@@ -99,7 +141,14 @@ namespace DeviceLibrary
{ {
public string userId = ""; public string userId = "";
public int language = 0; public int language = 0;
public int requestTime = 0; public string requestTime = "";
public Dictionary<string, object> data = new Dictionary<string, object>();
}
class Wiston_Request2
{
public string userId = "";
public int language = 0;
public string requestTime = "";
public Dictionary<string, object> data = new Dictionary<string, object>(); public Dictionary<string, object> data = new Dictionary<string, object>();
} }
public class CountResult public class CountResult
......
...@@ -24,6 +24,7 @@ namespace AutoCountMachine ...@@ -24,6 +24,7 @@ namespace AutoCountMachine
[STAThread] [STAThread]
static void Main() static void Main()
{ {
var t = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
//OcrProcess.Run(); //OcrProcess.Run();
//ServerConn.inputCounterDataByXRayMachine("20.K0784.008-615313|1KQ-2111|5000|A2061531315212446|PANASONIC", 9); //ServerConn.inputCounterDataByXRayMachine("20.K0784.008-615313|1KQ-2111|5000|A2061531315212446|PANASONIC", 9);
//return; //return;
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!