| | |
| | | using System.Data.SqlClient; |
| | | using System.Net.Cache; |
| | | using System.Net; |
| | | using System.Net.Cache; |
| | | using System.Text; |
| | | using Newtonsoft.Json; |
| | | using System.Data.SqlClient; |
| | | |
| | | |
| | | namespace Gs.Toolbox; |
| | | |
| | | public class InterfaceUtil |
| | | { |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="param">json参数</param> |
| | | /// <param name="edtUserGuid"></param> |
| | |
| | | /// <param name="hNo"></param> |
| | | /// <param name="urlType">如果为2,则是更新工单状态</param> |
| | | /// <returns>如果成功返回日志guid,否则返回串</returns> |
| | | public static (int, string) HttpPostErp(string param, |
| | | string edtUserGuid = "", string abtGuid = "", string hNo = "", |
| | | int urlType = 0) |
| | | public static (int, string) HttpPostErp(string param, string edtUserGuid = "", string abtGuid = "", string hNo = "", int urlType = 0) |
| | | { |
| | | var _rtn = 0; |
| | | int _rtn = 0; |
| | | //日志详细,发送的时候,记录日志,存储过程调用的时候,再累加上mes业务的操作结果 |
| | | var sbLog = new StringBuilder(); |
| | | sbLog.Append(DateTime.Now + "开始发送"); |
| | | var strLogGuid = Guid.NewGuid().ToString(); |
| | | var url = AppSettingsHelper.getValueByKey("TestErpUrl"); |
| | | System.Text.StringBuilder sbLog = new System.Text.StringBuilder(); |
| | | sbLog.Append(DateTime.Now.ToString() + "开始发送"); |
| | | string strLogGuid = Guid.NewGuid().ToString(); |
| | | string url = AppSettingsHelper.getValueByKey("TestErpUrl"); |
| | | if (urlType == 2) |
| | | url = AppSettingsHelper.getValueByKey("TestErpUrl2"); |
| | | HttpWebRequest request = null; |
| | | StreamWriter requestStream = null; |
| | | WebResponse response = null; |
| | | var responseStr = ""; |
| | | string responseStr = ""; |
| | | try |
| | | { |
| | | request = (HttpWebRequest)WebRequest.Create(url); |
| | |
| | | request.Timeout = 150000; |
| | | request.AllowAutoRedirect = false; |
| | | request.ServicePoint.Expect100Continue = false; |
| | | var noCachePolicy = |
| | | new HttpRequestCachePolicy(HttpRequestCacheLevel |
| | | .NoCacheNoStore); |
| | | HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore); |
| | | request.CachePolicy = noCachePolicy; |
| | | requestStream = new StreamWriter(request.GetRequestStream()); |
| | | requestStream.Write(param); |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogHelper.Debug(url, |
| | | "HttpPostErp response:" + param + ",ex:" + ex.Message); |
| | | LogHelper.Debug(url, "HttpPostErp response:" + param + ",ex:" + ex.Message); |
| | | responseStr = ex.Message; |
| | | _rtn = -1; |
| | | } |
| | |
| | | requestStream = null; |
| | | response = null; |
| | | } |
| | | |
| | | if (_rtn != -1) |
| | | { |
| | | var _result = JsonConvert.DeserializeObject<Result>(responseStr); |
| | | Result _result = JsonConvert.DeserializeObject<Result>(responseStr); |
| | | if ("200".Equals(_result.state)) |
| | | _rtn = 1; |
| | | } |
| | | |
| | | sbLog.Append("," + DateTime.Now + "结束发送"); |
| | | sbLog.Append("," + DateTime.Now.ToString() + "结束发送"); |
| | | if (_rtn > 0) |
| | | sbLog.Append(",发送成功"); |
| | | else |
| | |
| | | try |
| | | { |
| | | SqlParameter[] parameters = |
| | | { |
| | | new("@edtUserGuid", edtUserGuid), |
| | | new("@abtGuid", abtGuid), |
| | | new("@abtTable", ""), |
| | | new("@detail", sbLog.ToString()), |
| | | new("@hNo", hNo), |
| | | new("@RtnLogGuid", strLogGuid), |
| | | new("@SendJson", param), |
| | | new("@RtnJson", responseStr), |
| | | new("@isSuccess", _rtn > 0 ? 1 : 0), |
| | | new("@isErp", 1) |
| | | }; |
| | | { |
| | | new("@edtUserGuid", edtUserGuid), |
| | | new("@abtGuid", abtGuid), |
| | | new("@abtTable", ""), |
| | | new("@detail", sbLog.ToString()), |
| | | new("@hNo", hNo), |
| | | new("@RtnLogGuid", strLogGuid), |
| | | new("@SendJson", param), |
| | | new("@RtnJson", responseStr), |
| | | new("@isSuccess", (_rtn>0?1:0)), |
| | | new("@isErp", 1), |
| | | }; |
| | | DbHelperSQL.RunProcedure("[prc_log_create]", parameters); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogHelper.Debug(url, "HttpPostErp 写入日志表" + ex.Message); |
| | | } |
| | | |
| | | return (_rtn, _rtn > 0 ? strLogGuid : responseStr); |
| | | return (_rtn, (_rtn > 0 ? strLogGuid : responseStr)); |
| | | } |
| | | } |
| | | |
| | | public class Result |
| | | { |
| | | /// <summary> |
| | | /// 200成功,否则失败 |
| | | /// 200成功,否则失败 |
| | | /// </summary> |
| | | public string? state { get; set; } |
| | | |
| | | public string? msg { get; set; } |
| | | |
| | | public string? status { get; set; } |