| | |
| | | 锘縰sing Newtonsoft.Json; |
| | | 锘縰sing Microsoft.Extensions.Logging; |
| | | using Newtonsoft.Json; |
| | | using Org.BouncyCastle.Asn1.Ocsp; |
| | | using System; |
| | | using System.Collections.Generic; |
| | |
| | | public class InvokeMESService : IInvokeMESService |
| | | { |
| | | private readonly IHttpClientFactory _httpClientFactory; |
| | | |
| | | private readonly ILogger<InvokeMESService> _logger; |
| | | private string UserName = "12312"; |
| | | private string Password = "1"; |
| | | public InvokeMESService(IHttpClientFactory httpClientFactory) |
| | | public InvokeMESService(IHttpClientFactory httpClientFactory, ILogger<InvokeMESService> logger) |
| | | { |
| | | _httpClientFactory = httpClientFactory; |
| | | _logger = logger; |
| | | } |
| | | |
| | | public async Task FeedbackInbound(string url, FeedbackInboundRequestModel model) |
| | | public async Task<ResponseModel> FeedbackInbound( FeedbackInboundRequestModel model) |
| | | { |
| | | string json = JsonConvert.SerializeObject(model); |
| | | var content = new StringContent(json, Encoding.UTF8, "application/json"); |
| | | var _client = _httpClientFactory.CreateClient("MESUrl"); |
| | | _client.DefaultRequestHeaders.Clear(); |
| | | _client.DefaultRequestHeaders.Add("Accept", "application/json"); |
| | | |
| | | var response = await _client.PostAsync(url, content); |
| | | _logger.LogInformation("InvokeMESService FeedbackInbound : " + json); |
| | | var response = await _client.PostAsync("AldMaterialWarehousing/MaterialWarehousing", content); |
| | | string body = await response.Content.ReadAsStringAsync(); |
| | | |
| | | _logger.LogInformation("InvokeMESService FeedbackInbound body: " + body); |
| | | if (!response.IsSuccessStatusCode) |
| | | { |
| | | |
| | | throw new HttpRequestException(body); |
| | | } |
| | | |
| | | // JsonConvert.DeserializeObject<ResponseModel>(body); |
| | | return JsonConvert.DeserializeObject<ResponseModel>(body); |
| | | } |
| | | |
| | | public async Task FeedbackOutbound(string url, FeedbackOutboundRequestModel model) |
| | | public async Task FeedbackOutbound( FeedbackOutboundRequestModel model) |
| | | { |
| | | string json = JsonConvert.SerializeObject(model); |
| | | var content = new StringContent(json, Encoding.UTF8, "application/json"); |
| | |
| | | _client.DefaultRequestHeaders.Clear(); |
| | | _client.DefaultRequestHeaders.Add("Accept", "application/json"); |
| | | |
| | | var response = await _client.PostAsync(url, content); |
| | | var response = await _client.PostAsync("AldMaterialOutbound/MaterialOutbound", content); |
| | | string body = await response.Content.ReadAsStringAsync(); |
| | | |
| | | if (!response.IsSuccessStatusCode) |
| | |
| | | string json = JsonConvert.SerializeObject(model); |
| | | |
| | | |
| | | string userDataEncoded = Uri.EscapeDataString(json); |
| | | //string baseUrl = "http://mestest.ald.com//OrBitWCFServiceR15/orbitwebapi.ashx?"; |
| | | string userTicket = await GetToken(UserName, Password); |
| | | string api = "WMS_BarcodeInformation"; |
| | | //string userDataEncoded = Uri.EscapeDataString(json); |
| | | ////string baseUrl = "http://mestest.ald.com//OrBitWCFServiceR15/orbitwebapi.ashx?"; |
| | | //string userTicket = await GetToken(UserName, Password); |
| | | //string api = "WMS_BarcodeInformation"; |
| | | |
| | | |
| | | var client = _httpClientFactory.CreateClient("MESUrl"); |
| | | // 鎷兼帴 URL 鍙傛暟 |
| | | string url = $"{client.BaseAddress}UserTicket={userTicket}&API={api}&UserData={userDataEncoded}"; |
| | | // string url = $"{client.BaseAddress}UserTicket={userTicket}&API={api}&UserData={userDataEncoded}"; |
| | | |
| | | |
| | | client.DefaultRequestHeaders.Clear(); |
| | |
| | | |
| | | var content = new StringContent(json, Encoding.UTF8, "application/json"); |
| | | |
| | | using var response = await client.PostAsync(url, content); |
| | | using var response = await client.PostAsync("", content); |
| | | var responseText = await response.Content.ReadAsStringAsync(); |
| | | if (!response.IsSuccessStatusCode) |
| | | { |