diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index 070cd8e5..46a8cc35 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -5272,7 +5272,7 @@ namespace Myshipping.Application { using (var request = new HttpRequestMessage(new HttpMethod("Post"), url)) { - request.Headers.TryAddWithoutValidation("Content-Type", "application/x-www-form-urlencoded"); + //request.Headers.TryAddWithoutValidation("Content-Type", "application/x-www-form-urlencoded"); var multipartContent = new MultipartFormDataContent(); multipartContent.Add(new StringContent("user_key"), key); multipartContent.Add(new StringContent("user_secret"), secret); diff --git a/Myshipping.Application/Service/BookingOrderSF/BookingOrderSFService.cs b/Myshipping.Application/Service/BookingOrderSF/BookingOrderSFService.cs index 89e62560..80564e5e 100644 --- a/Myshipping.Application/Service/BookingOrderSF/BookingOrderSFService.cs +++ b/Myshipping.Application/Service/BookingOrderSF/BookingOrderSFService.cs @@ -350,36 +350,26 @@ namespace Myshipping.Application await GetToken(); } - using (var httpClient = new HttpClient()) + var dictParam = new Dictionary { + { "partnerID", partnerID }, + { "serviceCode", "EXP_RECE_CREATE_ORDER"}, + { "requestID", requestID}, + { "timestamp", timeStamp}, + { "accessToken",_cache.Get($"SFToken{UserManager.TENANT_ID}")}, + { "msgData", sFSend} + }; + var strRtn = await url.SetBody(dictParam, "application/x-www-form-urlencoded") + .PostAsStringAsync(); + _logger.LogInformation("发送快递SendBooking:" + strRtn); + var jobj = strRtn.ToJObject(); + if (jobj.GetStringValue("apiResultCode") == "A1000") { - using (var request = new HttpRequestMessage(new HttpMethod("Post"), url)) - { - request.Headers.TryAddWithoutValidation("Content-Type", "application/x-www-form-urlencoded"); - var multipartContent = new MultipartFormDataContent(); - multipartContent.Add(new StringContent("partnerID"), partnerID); - multipartContent.Add(new StringContent("serviceCode"), "EXP_RECE_CREATE_ORDER"); - multipartContent.Add(new StringContent("requestID"), requestID); - multipartContent.Add(new StringContent("timestamp"), timeStamp.ToString()); - multipartContent.Add(new StringContent("accessToken"), _cache.Get($"SFToken{UserManager.TENANT_ID}")); - multipartContent.Add(new StringContent("msgData"), json); - request.Content = multipartContent; - var response = await httpClient.SendAsync(request); - if (response.IsSuccessStatusCode) - { - var strRtn = response.Content.ReadAsStringAsync().Result; - _logger.LogInformation("发送快递SendBooking:" + strRtn); - var jobj = strRtn.ToJObject(); - if (jobj.GetStringValue("apiResultCode") == "A1000") - { - rt = "下单成功!"; - - } - else - { - throw Oops.Bah(jobj.GetStringValue("apiErrorMsg")); - } - } - } + rt = "下单成功!"; + + } + else + { + throw Oops.Bah(jobj.GetStringValue("apiErrorMsg")); } return rt; } @@ -395,39 +385,31 @@ namespace Myshipping.Application var rt = String.Empty; //获取url var dict = _cache.GetAllDictData().Result; - _logger.LogInformation("顺丰调用字典:"+dict.ToJsonString()); var url = dict.Where(x => x.Code == "SFToken").Select(x => x.Value).FirstOrDefault(); + var partnerID = dict.Where(x => x.Code == "customercode").Select(x => x.Value).FirstOrDefault();//顾客编码: var secret = dict.Where(x => x.Code == "CheckCode").Select(x => x.Value).FirstOrDefault();//沙箱校验码 - - using (var httpClient = new HttpClient()) + _logger.LogInformation("顺丰partnerID" + partnerID); + _logger.LogInformation("顺丰secret" + secret); + var dictParam = new Dictionary { + { "partnerID",partnerID }, + { "grantType", "password"}, + { "secret", secret}}; + + var strRtn = await url.SetBody(dictParam, "application/x-www-form-urlencoded") + .PostAsStringAsync(); + _logger.LogInformation("顺丰GetToken" + strRtn); + var jobj = strRtn.ToJObject(); + if (jobj.GetStringValue("apiResultCode") == "A1000") { - using (var request = new HttpRequestMessage(new HttpMethod("Post"), url)) - { - request.Headers.TryAddWithoutValidation("Content-Type", "application/x-www-form-urlencoded"); - var multipartContent = new MultipartFormDataContent(); - multipartContent.Add(new StringContent("partnerID"), partnerID); - multipartContent.Add(new StringContent("grantType"), "password"); - multipartContent.Add(new StringContent("secret"), secret); - request.Content = multipartContent; - var response = await httpClient.SendAsync(request); - if (response.IsSuccessStatusCode) - { - var strRtn = response.Content.ReadAsStringAsync().Result; - _logger.LogInformation("顺丰GetToken" + strRtn); - var jobj = strRtn.ToJObject(); - if (jobj.GetStringValue("apiResultCode") == "A1000") - { - rt = jobj.GetStringValue("accessToken"); - await _cache.SetTimeoutAsync($"SFToken{UserManager.TENANT_ID}", rt, TimeSpan.FromHours(3)); - } - else - { - throw Oops.Bah(jobj.GetStringValue("apiErrorMsg")); - } - } - } + rt = jobj.GetStringValue("accessToken"); + await _cache.SetTimeoutAsync($"SFToken{UserManager.TENANT_ID}", rt, TimeSpan.FromHours(3)); + } + else + { + throw Oops.Bah(jobj.GetStringValue("apiErrorMsg")); } + return rt; } @@ -443,7 +425,7 @@ namespace Myshipping.Application var json = new { orderId = Id.ToString() - }.ToJsonString(); + }; long timeStamp = DateTimeOffset.Now.ToUnixTimeSeconds(); //获取url @@ -456,37 +438,30 @@ namespace Myshipping.Application { await GetToken(); } - using (var httpClient = new HttpClient()) + + + + var dictParam = new Dictionary { + { "partnerID", partnerID }, + { "serviceCode", "EXP_RECE_SEARCH_ORDER_RESP"}, + { "requestID", requestID}, + { "timestamp", timeStamp}, + { "accessToken",_cache.Get($"SFToken{UserManager.TENANT_ID}")}, + { "msgData", json} + }; + var strRtn = await url.SetBody(dictParam, "application/x-www-form-urlencoded") + .PostAsStringAsync(); + + _logger.LogInformation("查询快递QueryKDSchedule:" + strRtn); + var jobj = strRtn.ToJObject(); + if (jobj.GetStringValue("apiResultCode") == "A1000") { - using (var request = new HttpRequestMessage(new HttpMethod("Post"), url)) - { - request.Headers.TryAddWithoutValidation("Content-Type", "application/x-www-form-urlencoded"); - var multipartContent = new MultipartFormDataContent(); - multipartContent.Add(new StringContent("partnerID"), partnerID); - multipartContent.Add(new StringContent("serviceCode"), "EXP_RECE_SEARCH_ORDER_RESP"); - multipartContent.Add(new StringContent("requestID"), requestID); - multipartContent.Add(new StringContent("timestamp"), timeStamp.ToString()); - multipartContent.Add(new StringContent("accessToken"), _cache.Get($"SFToken{UserManager.TENANT_ID}")); - multipartContent.Add(new StringContent("msgData"), json); - request.Content = multipartContent; - var response = await httpClient.SendAsync(request); - if (response.IsSuccessStatusCode) - { - var strRtn = response.Content.ReadAsStringAsync().Result; - _logger.LogInformation("查询快递QueryKDSchedule:" + strRtn); - var jobj = strRtn.ToJObject(); - if (jobj.GetStringValue("apiResultCode") == "A1000") - { - rt = jobj.GetStringValue("apiResultData").ToJsonString(); - } - else - { - throw Oops.Bah(jobj.GetStringValue("apiErrorMsg")); - } - } - } + rt = jobj.GetStringValue("apiResultData").ToJsonString(); + } + else + { + throw Oops.Bah(jobj.GetStringValue("apiErrorMsg")); } - return rt; }