|
|
@ -94,9 +94,6 @@ namespace Myshipping.Application
|
|
|
|
private readonly ILogger<BookingOrderSFService> _logger;
|
|
|
|
private readonly ILogger<BookingOrderSFService> _logger;
|
|
|
|
private readonly ISysCacheService _cache;
|
|
|
|
private readonly ISysCacheService _cache;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public BookingOrderSFService(SqlSugarRepository<BookingOrderSFExpressDelivery> rep, SqlSugarRepository<BookingOrderSFExpressdeliveryBusiness> business,
|
|
|
|
public BookingOrderSFService(SqlSugarRepository<BookingOrderSFExpressDelivery> rep, SqlSugarRepository<BookingOrderSFExpressdeliveryBusiness> business,
|
|
|
|
SqlSugarRepository<BookingOrderSFExpressdeliveryDetail> detail,
|
|
|
|
SqlSugarRepository<BookingOrderSFExpressdeliveryDetail> detail,
|
|
|
|
ILogger<BookingOrderSFService> logger, ISysCacheService cache)
|
|
|
|
ILogger<BookingOrderSFService> logger, ISysCacheService cache)
|
|
|
@ -235,9 +232,6 @@ namespace Myshipping.Application
|
|
|
|
return Get(entity.Id);
|
|
|
|
return Get(entity.Id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 删除单据
|
|
|
|
/// 删除单据
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
@ -291,12 +285,158 @@ namespace Myshipping.Application
|
|
|
|
return ordOut;
|
|
|
|
return ordOut;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 发送快递
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="Id"></param>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
[HttpPost("/BookingOrderSF/SendBooking")]
|
|
|
|
|
|
|
|
public async Task<dynamic> SendBooking(long Id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var rt = String.Empty;
|
|
|
|
|
|
|
|
SFSendBooking sFSend = new SFSendBooking();
|
|
|
|
|
|
|
|
var Delivery = _rep.FirstOrDefault(x => x.Id == Id);
|
|
|
|
|
|
|
|
if (Delivery==null) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
throw Oops.Bah("请选择正确数据!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sFSend.orderId = Id.ToString();
|
|
|
|
|
|
|
|
sFSend.language = "zh_CN";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<CargoDetailsItem> cargo = new List<CargoDetailsItem>();
|
|
|
|
|
|
|
|
cargo.Add(new CargoDetailsItem
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
count = (int)Delivery.KDNum,
|
|
|
|
|
|
|
|
name = Delivery.GOODSNAME
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<ContactInfoListItem> contactList = new List<ContactInfoListItem>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
contactList.Add(new ContactInfoListItem
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
address = $"{Delivery.FJProvince}{Delivery.FJCity}{Delivery.FJAddress}",
|
|
|
|
|
|
|
|
contact = Delivery.FJPeople,
|
|
|
|
|
|
|
|
contactType = 1,
|
|
|
|
|
|
|
|
country = "CN",
|
|
|
|
|
|
|
|
postCode = Delivery.FJPostCode,
|
|
|
|
|
|
|
|
tel = Delivery.FJTel,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
contactList.Add(new ContactInfoListItem
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
address = $"{Delivery.SJProvince}{Delivery.SJCity}{Delivery.SJAddress}",
|
|
|
|
|
|
|
|
contact = Delivery.SJPeople,
|
|
|
|
|
|
|
|
contactType = 2,
|
|
|
|
|
|
|
|
country = "CN",
|
|
|
|
|
|
|
|
postCode = Delivery.SJPostCode,
|
|
|
|
|
|
|
|
tel = Delivery.SJTel,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
sFSend.contactInfoList = contactList;
|
|
|
|
|
|
|
|
sFSend.cargoDetails = cargo;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var json= sFSend.ToJson();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long timeStamp = DateTimeOffset.Now.ToUnixTimeSeconds();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取url
|
|
|
|
|
|
|
|
var dict = _cache.GetAllDictData().Result;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var url = dict.Where(x => x.Code == "SFSendBooking").Select(x => x.Value).FirstOrDefault();
|
|
|
|
|
|
|
|
var partnerID = dict.Where(x => x.Code == "customercode").Select(x => x.Value).FirstOrDefault();//顾客编码:
|
|
|
|
|
|
|
|
var requestID = dict.Where(x => x.Code == "CheckCode").Select(x => x.Value).FirstOrDefault();//沙箱校验码
|
|
|
|
|
|
|
|
if (!_cache.Exists($"SFToken{UserManager.TENANT_ID}")) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 jobj = strRtn.ToJObject();
|
|
|
|
|
|
|
|
if (jobj.GetStringValue("apiResultCode") == "A1000")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
rt = "下单成功!";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw Oops.Bah(jobj.GetStringValue("apiErrorMsg"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return rt;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 获取顺丰token
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
[NonAction]
|
|
|
|
|
|
|
|
public async Task<dynamic> GetToken()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var rt = String.Empty;
|
|
|
|
|
|
|
|
//获取url
|
|
|
|
|
|
|
|
var dict = _cache.GetAllDictData().Result;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return rt;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|