jianghaiqing 1 year ago
commit eb599c39c4

@ -5272,7 +5272,7 @@ namespace Myshipping.Application
{ {
using (var request = new HttpRequestMessage(new HttpMethod("Post"), url)) 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(); var multipartContent = new MultipartFormDataContent();
multipartContent.Add(new StringContent("user_key"), key); multipartContent.Add(new StringContent("user_key"), key);
multipartContent.Add(new StringContent("user_secret"), secret); multipartContent.Add(new StringContent("user_secret"), secret);

@ -350,23 +350,16 @@ namespace Myshipping.Application
await GetToken(); await GetToken();
} }
using (var httpClient = new HttpClient()) var dictParam = new Dictionary<string, object> {
{ { "partnerID", partnerID },
using (var request = new HttpRequestMessage(new HttpMethod("Post"), url)) { "serviceCode", "EXP_RECE_CREATE_ORDER"},
{ { "requestID", requestID},
request.Headers.TryAddWithoutValidation("Content-Type", "application/x-www-form-urlencoded"); { "timestamp", timeStamp},
var multipartContent = new MultipartFormDataContent(); { "accessToken",_cache.Get($"SFToken{UserManager.TENANT_ID}")},
multipartContent.Add(new StringContent("partnerID"), partnerID); { "msgData", sFSend}
multipartContent.Add(new StringContent("serviceCode"), "EXP_RECE_CREATE_ORDER"); };
multipartContent.Add(new StringContent("requestID"), requestID); var strRtn = await url.SetBody(dictParam, "application/x-www-form-urlencoded")
multipartContent.Add(new StringContent("timestamp"), timeStamp.ToString()); .PostAsStringAsync();
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); _logger.LogInformation("发送快递SendBooking:" + strRtn);
var jobj = strRtn.ToJObject(); var jobj = strRtn.ToJObject();
if (jobj.GetStringValue("apiResultCode") == "A1000") if (jobj.GetStringValue("apiResultCode") == "A1000")
@ -378,9 +371,6 @@ namespace Myshipping.Application
{ {
throw Oops.Bah(jobj.GetStringValue("apiErrorMsg")); throw Oops.Bah(jobj.GetStringValue("apiErrorMsg"));
} }
}
}
}
return rt; return rt;
} }
@ -395,25 +385,19 @@ namespace Myshipping.Application
var rt = String.Empty; var rt = String.Empty;
//获取url //获取url
var dict = _cache.GetAllDictData().Result; var dict = _cache.GetAllDictData().Result;
_logger.LogInformation("顺丰调用字典:"+dict.ToJsonString());
var url = dict.Where(x => x.Code == "SFToken").Select(x => x.Value).FirstOrDefault(); 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 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();//沙箱校验码 var secret = dict.Where(x => x.Code == "CheckCode").Select(x => x.Value).FirstOrDefault();//沙箱校验码
_logger.LogInformation("顺丰partnerID" + partnerID);
using (var httpClient = new HttpClient()) _logger.LogInformation("顺丰secret" + secret);
{ var dictParam = new Dictionary<string, string> {
using (var request = new HttpRequestMessage(new HttpMethod("Post"), url)) { "partnerID",partnerID },
{ { "grantType", "password"},
request.Headers.TryAddWithoutValidation("Content-Type", "application/x-www-form-urlencoded"); { "secret", secret}};
var multipartContent = new MultipartFormDataContent();
multipartContent.Add(new StringContent("partnerID"), partnerID); var strRtn = await url.SetBody(dictParam, "application/x-www-form-urlencoded")
multipartContent.Add(new StringContent("grantType"), "password"); .PostAsStringAsync();
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); _logger.LogInformation("顺丰GetToken" + strRtn);
var jobj = strRtn.ToJObject(); var jobj = strRtn.ToJObject();
if (jobj.GetStringValue("apiResultCode") == "A1000") if (jobj.GetStringValue("apiResultCode") == "A1000")
@ -425,9 +409,7 @@ namespace Myshipping.Application
{ {
throw Oops.Bah(jobj.GetStringValue("apiErrorMsg")); throw Oops.Bah(jobj.GetStringValue("apiErrorMsg"));
} }
}
}
}
return rt; return rt;
} }
@ -443,7 +425,7 @@ namespace Myshipping.Application
var json = new var json = new
{ {
orderId = Id.ToString() orderId = Id.ToString()
}.ToJsonString(); };
long timeStamp = DateTimeOffset.Now.ToUnixTimeSeconds(); long timeStamp = DateTimeOffset.Now.ToUnixTimeSeconds();
//获取url //获取url
@ -456,23 +438,20 @@ namespace Myshipping.Application
{ {
await GetToken(); await GetToken();
} }
using (var httpClient = new HttpClient())
{
using (var request = new HttpRequestMessage(new HttpMethod("Post"), url))
{ var dictParam = new Dictionary<string, object> {
request.Headers.TryAddWithoutValidation("Content-Type", "application/x-www-form-urlencoded"); { "partnerID", partnerID },
var multipartContent = new MultipartFormDataContent(); { "serviceCode", "EXP_RECE_SEARCH_ORDER_RESP"},
multipartContent.Add(new StringContent("partnerID"), partnerID); { "requestID", requestID},
multipartContent.Add(new StringContent("serviceCode"), "EXP_RECE_SEARCH_ORDER_RESP"); { "timestamp", timeStamp},
multipartContent.Add(new StringContent("requestID"), requestID); { "accessToken",_cache.Get($"SFToken{UserManager.TENANT_ID}")},
multipartContent.Add(new StringContent("timestamp"), timeStamp.ToString()); { "msgData", json}
multipartContent.Add(new StringContent("accessToken"), _cache.Get($"SFToken{UserManager.TENANT_ID}")); };
multipartContent.Add(new StringContent("msgData"), json); var strRtn = await url.SetBody(dictParam, "application/x-www-form-urlencoded")
request.Content = multipartContent; .PostAsStringAsync();
var response = await httpClient.SendAsync(request);
if (response.IsSuccessStatusCode)
{
var strRtn = response.Content.ReadAsStringAsync().Result;
_logger.LogInformation("查询快递QueryKDSchedule:" + strRtn); _logger.LogInformation("查询快递QueryKDSchedule:" + strRtn);
var jobj = strRtn.ToJObject(); var jobj = strRtn.ToJObject();
if (jobj.GetStringValue("apiResultCode") == "A1000") if (jobj.GetStringValue("apiResultCode") == "A1000")
@ -483,10 +462,6 @@ namespace Myshipping.Application
{ {
throw Oops.Bah(jobj.GetStringValue("apiErrorMsg")); throw Oops.Bah(jobj.GetStringValue("apiErrorMsg"));
} }
}
}
}
return rt; return rt;
} }

Loading…
Cancel
Save