Browse Source

Merge branch 'master' of http://119.3.29.177:3000/xusc/IcsFromERPJob

Branch_PaiNaWeiSJob
shiqian.wang 3 months ago
parent
commit
085f2aae83
  1. BIN
      .vs/ICSSoft.FromERP/v16/.suo
  2. 3
      ICSSoft.FromERP/App.config
  3. 172
      ICSSoft.FromERP/HttpHelper.cs
  4. 2
      ICSSoft.FromERP/ICSSoft.FromERP.csproj
  5. 61
      ICSSoft.FromERP/SyncCas_Jinyang.cs
  6. 2
      ICSSoft.Test/Program.cs

BIN
.vs/ICSSoft.FromERP/v16/.suo

Binary file not shown.

3
ICSSoft.FromERP/App.config

@ -12,6 +12,9 @@
<add key="WeiMasOrgUrl" value="https://test.zhangsanfeng.vip"/>
<!--基础资料 地址-->
<add key="WeiMasErpUrl" value="https://test-basic.zhangsanfeng.vip"/>
<!--金杨数采 地址-->
<add key="JinyangCapUrl" value="https://esb.ampacetech.com/extr/ipaas/MRD/api/mrd/supplierUpload"/>
</appSettings>
<connectionStrings>
<!--<add name="SysConnectionString" connectionString="Data Source=119.3.29.177;Database=ICSMESBase;Uid=gitea;Pwd=aA123456;"/>-->

172
ICSSoft.FromERP/HttpHelper.cs

@ -8,12 +8,13 @@ using System.Net;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http.Headers;
namespace ICSSoft.FromERP
{
public class HttpHelper
{
/// <summary>
/// POST请求
/// </summary>
@ -21,7 +22,7 @@ namespace ICSSoft.FromERP
/// <param name="requestJson">请求json</param>
/// <param name="token">token</param>
/// <returns></returns>
public static async Task<T> HttpClientPost<T>(string url, string requestJson, string contentType = "application/json", string token = "") where T : new()
public static async Task<T> HttpClientPost<T>(string url, string requestJson, Dictionary<string, string> dic=null , string contentType = "application/json", string token = "") where T : new()
{
string result = string.Empty;
@ -29,20 +30,87 @@ namespace ICSSoft.FromERP
using (HttpContent httpContent = new StringContent(requestJson, System.Text.Encoding.UTF8, contentType))
{
//使用注入的httpclientfactory获取client
using (var httpClient = new HttpClient())
using (var httpClient = new HttpClient( ))
{
if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
{
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
// httpClient.BaseAddress. = HttpVersion.Version10;
// httpClient.DefaultRequestVersion = HttpVersion.Version30,
}
//设置请求头
//设置超时时间
if (!string.IsNullOrEmpty(token))
httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
if (dic != null)
{
foreach (var item in dic)
{
httpClient.DefaultRequestHeaders.Add(item.Key, item.Value);
}
}
httpClient.Timeout = new TimeSpan(0, 0, 60);
HttpResponseMessage res = httpClient.PostAsync(url, httpContent).Result;
res.EnsureSuccessStatusCode();
result = res.Content.ReadAsStringAsync().Result;
result = res.Content.ReadAsStringAsync().Result;
return JsonConvert.DeserializeObject<T>(result);
}
}
}
public static async Task<T> HttpClientPost2<T>(string url, string requestJson, Dictionary<string, string> dic, string contentType = "application/json") where T : new()
{
string result = string.Empty;
Uri postUrl = new Uri(url);
//使用注入的httpclientfactory获取client
using (var httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType));
using (StringContent strcontent = new StringContent(requestJson, Encoding.UTF8, contentType))
{
var message = new HttpRequestMessage(HttpMethod.Post, url);
//设置cookie信息
foreach (var item in dic)
{
message.Headers.Add(item.Key, item.Value);
}
//设置contetn
message.Content = strcontent;
//发送请求
var res = httpClient.SendAsync(message).Result;
res.EnsureSuccessStatusCode();
result = await res.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<T>(result);
}
////设置请求头
////设置超时时间
//if (dic != null && dic.Count > 0)
//{
// foreach (var item in dic)
// {
// httpClient.DefaultRequestHeaders.Add(item.Key, item.Value);
// }
//}
////if (!string.IsNullOrEmpty(token))
//// httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
//httpClient.Timeout = new TimeSpan(0, 0, 60);
//HttpResponseMessage res = httpClient.PostAsync(url, httpContent).Result;
//res.EnsureSuccessStatusCode();
//result = await res.Content.ReadAsStringAsync();
//return JsonConvert.DeserializeObject<T>(result);
}
}
public static async Task<T> HttpClientGet<T>(string url, string contentType = "application/json", string token = "") where T : new()
@ -54,19 +122,20 @@ namespace ICSSoft.FromERP
httpClient.Timeout = new TimeSpan(0, 0, 60);
HttpResponseMessage res = httpClient.GetAsync(url).Result;
res.EnsureSuccessStatusCode();
var t = res.Content.ReadAsStringAsync().Result;
var t = res.Content.ReadAsStringAsync().Result;
return JsonConvert.DeserializeObject<T>(t);
};
}
public static async Task<T> PostForm<T, R>(string Url, R message) where T : new()
public static async Task<T> PostForm<T, R>(string Url, R message, Dictionary<string, string> dic=null) where T : new()
{
var res = new T();
using (HttpClient httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
var body = new List<KeyValuePair<string, string>>();
foreach (PropertyInfo info in typeof(R).GetProperties())
{
@ -75,21 +144,98 @@ namespace ICSSoft.FromERP
}
var content = new FormUrlEncodedContent(body);
httpClient.DefaultRequestHeaders.Add("Method", "Post");
HttpResponseMessage response = await httpClient.PostAsync(Url, content);
if (dic != null)
{
foreach (var item in dic)
{
httpClient.DefaultRequestHeaders.Add(item.Key, item.Value);
}
}
HttpResponseMessage response = httpClient.PostAsync(Url, content).Result;
if ((int)response.StatusCode == 200)
{
response.EnsureSuccessStatusCode();
string result = response.Content.ReadAsStringAsync().Result;
res = JsonConvert.DeserializeObject<T>(result);
}
else
string result = response.Content.ReadAsStringAsync().Result;
res = JsonConvert.DeserializeObject<T>(result);
}
return res;
}
public static async Task<T> HttpPostNoFile<T>(string url, string data)
{
// Encoding encoding = Encoding.UTF8;
// string jsonParam = data;
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Method = "post";
request.ContentType = "application/json";
byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());
request.ContentLength = byteData.Length;
using (Stream postStream = request.GetRequestStream())
{
postStream.Write(byteData, 0, byteData.Length);
}
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
string result = response.Content.ReadAsStringAsync().Result;
res = JsonConvert.DeserializeObject<T>(result);
var result= reader.ReadToEnd().ToString();
return JsonConvert.DeserializeObject<T>(result);
}
}
return res;
}
public static string PostData(byte[] data, string url, string contentType = "application/json", int timeout = 20)
{
//创建httpWebRequest对象
HttpWebRequest httpRequest = null;
if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
{
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
httpRequest = WebRequest.Create(url) as HttpWebRequest;
httpRequest.ProtocolVersion = HttpVersion.Version10;
}
else
{
httpRequest = WebRequest.Create(url) as HttpWebRequest;
}
if (httpRequest == null)
{
throw new ApplicationException(string.Format("Invalid url string: {0}", url));
}
//填充httpWebRequest的基本信息
httpRequest.ContentType = contentType;
httpRequest.Method = "POST";
httpRequest.Timeout = timeout * 1000;
//填充并发送要post的内容
httpRequest.ContentLength = data.Length;
httpRequest.Headers.Add("deipaaskeyauth", "a5P1RTL4380zd9jpb57qXx63rdynUHN2");
using (Stream requestStream = httpRequest.GetRequestStream())
{
requestStream.Write(data, 0, data.Length);
requestStream.Close();
}
//发送post请求到服务器并读取服务器返回信息
var response = httpRequest.GetResponse();
using (Stream responseStream = response.GetResponseStream())
{
//读取服务器返回信息
string stringResponse = string.Empty;
using (StreamReader responseReader = new StreamReader(responseStream, Encoding.UTF8))
{
stringResponse = responseReader.ReadToEnd();
}
responseStream.Close();
return stringResponse;
}
}
}
}

2
ICSSoft.FromERP/ICSSoft.FromERP.csproj

@ -26,7 +26,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\Root\</OutputPath>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>

61
ICSSoft.FromERP/SyncCas_Jinyang.cs

@ -44,50 +44,51 @@ namespace ICSSoft.FromERP
DataTable dt = ICSHelper.GetERPDB(conStr);
foreach (DataRow dr in dt.Rows)
{
var dtNowBegin = new DateTime(2000, 1, 1, 0, 0, 0);//默认开始时间
var dtNow = DateTime.Now;
string erpName = ICSHelper.GetConfigString()["ERPDB"];
string TenantId = dr["TenantId"].ToString();//mes 组织
string TenantCode = dr["TenantCode"].ToString();
string ErpId = dr["ErpID"].ToString(); //erpID
string Class = this.GetType().Name + TenantCode;
erpName = string.Format(erpName, TenantId);
//var dtNowBegin = new DateTime(2000, 1, 1, 0, 0, 0);//默认开始时间
//var dtNow = DateTime.Now;
//string erpName = ICSHelper.GetConfigString()["ERPDB"];
//string TenantId = dr["TenantId"].ToString();//mes 组织
//string TenantCode = dr["TenantCode"].ToString();
//string ErpId = dr["ErpID"].ToString(); //erpID
//string Class = this.GetType().Name + TenantCode;
//erpName = string.Format(erpName, TenantId);
string sql0 = " SELECT top 1 ModifyDate FROM ICSERPTime where ClassName='" + Class + "'";
var lastDate = ICSHelper.ExecuteScalar(conStr, sql0).ToDateOrNull();
if (!lastDate.HasValue)
{
lastDate = dtNowBegin;
}
//string sql0 = " SELECT top 1 ModifyDate FROM ICSERPTime where ClassName='" + Class + "'";
//var lastDate = ICSHelper.ExecuteScalar(conStr, sql0).ToDateOrNull();
//if (!lastDate.HasValue)
//{
// lastDate = dtNowBegin;
//}
string sql = @" select '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' as MTIME into #TempVendor ";
sql = ICSHelper.Time(Namespace, Class, TenantId, sql, "#TempVendor");
sql += "DROP TABLE #TempVendor";
ICSHelper.ExecuteDate(conStr, sql);
//string sql = @" select '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' as MTIME into #TempVendor ";
//sql = ICSHelper.Time(Namespace, Class, TenantId, sql, "#TempVendor");
//sql += "DROP TABLE #TempVendor";
//ICSHelper.ExecuteDate(conStr, sql);
List<CapInputDto> list = new List<CapInputDto>();
var input = new CapInputDto();
input.WorkshopID = "";
input.EquipmentID = "";
input.ProductNo = "";
input.LotNo = "";
input.CollectionTime = "";
input.WorkshopID = "1";
input.EquipmentID = "1";
input.ProductNo = "1";
input.LotNo = "1";
input.CollectionTime = "1";
input.ParamValue_Resistance = 12;
input.ParamValue_Height = 12;
input.Msg = "";
var inputObj = JsonConvert.SerializeObject(input);
string url = ICSHelper.GetConfigString()["WeiMasErpUrl"] + @"/BasicAssistingService/FromWeMec/APIVenderToMES";
list.Add(input);
var inputObj = JsonConvert.SerializeObject(list);
//string url = ICSHelper.GetConfigString()["JinyangCapUrl"]+ @"?deipaaskeyauth=a5P1RTL4380zd9jpb57qXx63rdynUHN2";
string url = ICSHelper.GetConfigString()["JinyangCapUrl"];
var result = HttpHelper.HttpClientPost<ResponseInfoDto>(url, inputObj).Result;
var result = HttpHelper.HttpClientPost<ResponseInfoDto>(url, inputObj, new Dictionary<string, string>() { { "deipaaskeyauth", "a5P1RTL4380zd9jpb57qXx63rdynUHN2" } }).Result;
// var result = HttpHelper.HttpClientPost<ResponseInfoDto>(url, inputObj).Result;
if (result.Result == "OK")
{
// insertSql += "DROP TABLE #tempFromErp4Vendor";
//ICSHelper.ExecuteDate(conStr, insertSql);
}
else
{

2
ICSSoft.Test/Program.cs

@ -13,7 +13,7 @@ namespace ICSSoft.Test
//ICSVendor test = new ICSVendor();
//test.Execute();
SyncCustomer_WeiMas test = new SyncCustomer_WeiMas();
SyncCas_Jinyang test = new SyncCas_Jinyang();
test.Execute();
// var ss= ICSHelper.ApiSign("sj_w_id", "70FF7F01C5899A5ACAAD4ECB7FA5B3C5", 1724650261);

Loading…
Cancel
Save