optimize
wet 1 year ago
parent c1163e7f82
commit 59e26bdd6e

@ -5254,7 +5254,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);

@ -350,23 +350,16 @@ namespace Myshipping.Application
await GetToken();
}
using (var httpClient = new HttpClient())
{
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;
var dictParam = new Dictionary<string, object> {
{ "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")
@ -378,9 +371,6 @@ namespace Myshipping.Application
{
throw Oops.Bah(jobj.GetStringValue("apiErrorMsg"));
}
}
}
}
return rt;
}
@ -395,25 +385,19 @@ 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())
{
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("顺丰partnerID" + partnerID);
_logger.LogInformation("顺丰secret" + secret);
var dictParam = new Dictionary<string, string> {
{ "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")
@ -425,9 +409,7 @@ namespace Myshipping.Application
{
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,23 +438,20 @@ namespace Myshipping.Application
{
await GetToken();
}
using (var httpClient = new HttpClient())
{
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;
var dictParam = new Dictionary<string, object> {
{ "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")
@ -483,10 +462,6 @@ namespace Myshipping.Application
{
throw Oops.Bah(jobj.GetStringValue("apiErrorMsg"));
}
}
}
}
return rt;
}

Loading…
Cancel
Save