| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Security.Cryptography; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core; |
| | |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | string response = string.Empty; |
| | | string requestHash = string.Empty; |
| | | string responseHash = string.Empty; |
| | | Dt_ApiInfo? apiInfo = null; |
| | | try |
| | | { |
| | | apiInfo = BaseDal.QueryFirst(x => x.ApiCode == apiCode) ?? throw new Exception($"æªæ¾å°{remark}æ¥å£é
置信æ¯ï¼è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | response = HttpHelper.Post(apiInfo.ApiAddress, requestParameters); |
| | | requestHash = ComputeHash(requestParameters); |
| | | responseHash = ComputeHash(response); |
| | | if (apiInfo.Remark.Contains("åå车")) |
| | | { |
| | | FOURBOTReturn fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>(); |
| | |
| | | { |
| | | if (isAdd && !string.IsNullOrEmpty(response) && apiInfo != null) |
| | | { |
| | | Dt_InterfaceLog interfaceLog = new Dt_InterfaceLog() |
| | | #region æ¥è¯¢å½å¤©æ¯å¦åå¨ç¸åè®°å½ |
| | | var today = DateTime.Now.Date; |
| | | var existingLog = _interfaceLogService.Repository.QueryFirst(x => |
| | | x.ApiCode == apiCode && |
| | | x.RequestParametersHash == requestHash && |
| | | x.ResponseParametersHash == responseHash && |
| | | x.CreateDate.Date == today); |
| | | if (existingLog != null) |
| | | { |
| | | ApiCode = apiCode, |
| | | RequestParameters = requestParameters, |
| | | ApiAddress = apiInfo.ApiAddress, |
| | | ApiName = apiInfo.ApiName, |
| | | PushFrequency = 1, |
| | | PushState = content.Status ? 1 : 2, |
| | | Requestor = "WCS", |
| | | Recipient = apiInfo.Remark, |
| | | ResponseParameters = response, |
| | | Creater = "System", |
| | | Remark = content.Status ? remark : content.Message, |
| | | }; |
| | | _interfaceLogService.Repository.AddData(interfaceLog); |
| | | existingLog.PushFrequency = existingLog.PushFrequency + 1; |
| | | existingLog.PushState = content.Status ? 1 : 2; |
| | | existingLog.ResponseParameters = response; |
| | | existingLog.Remark = content.Status ? remark : content.Message; |
| | | existingLog.Modifier = App.User?.UserName ?? "System"; |
| | | existingLog.ModifyDate = DateTime.Now; |
| | | _interfaceLogService.Repository.UpdateData(existingLog); |
| | | } |
| | | #endregion |
| | | else |
| | | { |
| | | Dt_InterfaceLog interfaceLog = new Dt_InterfaceLog() |
| | | { |
| | | ApiCode = apiCode, |
| | | RequestParameters = requestParameters, |
| | | ApiAddress = apiInfo.ApiAddress, |
| | | ApiName = apiInfo.ApiName, |
| | | RequestParametersHash = requestHash, |
| | | ResponseParametersHash = responseHash, |
| | | PushFrequency = 1, |
| | | PushState = content.Status ? 1 : 2, |
| | | Requestor = "WCS", |
| | | Recipient = apiInfo.Remark, |
| | | ResponseParameters = response, |
| | | Creater = "System", |
| | | Remark = content.Status ? remark : content.Message, |
| | | }; |
| | | _interfaceLogService.Repository.AddData(interfaceLog); |
| | | } |
| | | } |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 计ç®å符串çSHA256åå¸å¼ |
| | | /// </summary> |
| | | private static string ComputeHash(string input) |
| | | { |
| | | if (string.IsNullOrEmpty(input)) |
| | | return string.Empty; |
| | | |
| | | using (SHA256 sha256 = SHA256.Create()) |
| | | { |
| | | byte[] bytes = Encoding.UTF8.GetBytes(input); |
| | | byte[] hashBytes = sha256.ComputeHash(bytes); |
| | | return BitConverter.ToString(hashBytes).Replace("-", "").ToLower(); |
| | | } |
| | | } |
| | | } |
| | | } |