You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
4.6 KiB
121 lines
4.6 KiB
using BBWYB.Common.Http;
|
|
using BBWYB.Common.Models;
|
|
using Newtonsoft.Json;
|
|
using SDKAdapter;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
|
|
namespace BBWYB.Server.Business
|
|
{
|
|
public class KuaiDi100Manager : IDenpendency
|
|
{
|
|
private RestApiService restApiService;
|
|
|
|
public IList<int> KuaiDi100PushStateList_ZaiTu = new List<int>() { 0, 1001, 1002, 1003 };
|
|
public IList<int> KuaiDi100PushStateList_LanShou = new List<int>() { 1, 101, 102, 103 };
|
|
public IList<int> KuaiDi100PushStateList_QianShou = new List<int>() { 3, 301, 302, 303, 304 };
|
|
public IList<int> KuaiDi100PushStateList_PaiJian = new List<int>() { 5, 501 };
|
|
private IList<KuaiDi100ExpressCompany> kuaiDi100ExpressCompanyList;
|
|
|
|
public KuaiDi100Manager(RestApiService restApiService)
|
|
{
|
|
this.restApiService = restApiService;
|
|
|
|
kuaiDi100ExpressCompanyList = new List<KuaiDi100ExpressCompany>();
|
|
var lines = File.ReadAllLines(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "KuaiDi100ExpressCompany.txt"), System.Text.Encoding.UTF8);
|
|
foreach (var line in lines)
|
|
{
|
|
var array = line.Split(',', StringSplitOptions.RemoveEmptyEntries);
|
|
if (!array[2].Contains("国内"))
|
|
continue;
|
|
kuaiDi100ExpressCompanyList.Add(new KuaiDi100ExpressCompany()
|
|
{
|
|
ExpressId = array[1],
|
|
ExpressName = array[0],
|
|
Type = array[2]
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 订阅快递100
|
|
/// </summary>
|
|
/// <param name="waybillno"></param>
|
|
/// <param name="kuaidi100CompanyCode"></param>
|
|
/// <param name="callbackUrl"></param>
|
|
public void SubscribeKuaiDi100(string waybillno, string kuaidi100CompanyCode, string callbackUrl)
|
|
{
|
|
if (string.IsNullOrEmpty(kuaidi100CompanyCode))
|
|
throw new Exception("缺少快递100公司编码");
|
|
|
|
var paramStr = JsonConvert.SerializeObject(new
|
|
{
|
|
company = kuaidi100CompanyCode,
|
|
number = waybillno,
|
|
key = "SdcRPzxo8802",
|
|
parameters = new
|
|
{
|
|
callbackurl = callbackUrl,
|
|
salt = Guid.NewGuid(),
|
|
resultv2 = "4"
|
|
}
|
|
});
|
|
var subscribeResult = restApiService.SendRequest("https://poll.kuaidi100.com", "poll", $"schema=json¶m={paramStr}", null, HttpMethod.Post, RestApiService.ContentType_Form);
|
|
if (subscribeResult.StatusCode != System.Net.HttpStatusCode.OK)
|
|
throw new Exception(subscribeResult.Content);
|
|
var subscribeResponse = JsonConvert.DeserializeObject<KuaiDi100SubscribeResponse>(subscribeResult.Content);
|
|
if (!subscribeResponse.result)
|
|
throw new Exception(subscribeResponse.message);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取物流状态 ZaiTu LanShou QianShou PaiJian Unknow
|
|
/// </summary>
|
|
/// <param name="kuaidi100State"></param>
|
|
/// <returns></returns>
|
|
public string GetExpressState(int kuaidi100State)
|
|
{
|
|
if (KuaiDi100PushStateList_ZaiTu.Contains(kuaidi100State))
|
|
return "ZaiTu";
|
|
if (KuaiDi100PushStateList_LanShou.Contains(kuaidi100State))
|
|
return "LanShou";
|
|
if (KuaiDi100PushStateList_QianShou.Contains(kuaidi100State))
|
|
return "QianShou";
|
|
if (KuaiDi100PushStateList_PaiJian.Contains(kuaidi100State))
|
|
return "PaiJian";
|
|
return "Unknow";
|
|
}
|
|
|
|
public IList<KuaiDi100ExpressCompany> GetKuaiDi100ExpressCompanyList(KuaiDi100ExpressSearchRequest request)
|
|
{
|
|
if (string.IsNullOrEmpty(request.ExpressName))
|
|
return kuaiDi100ExpressCompanyList;
|
|
else
|
|
return kuaiDi100ExpressCompanyList.Where(x => x.ExpressName.Contains(request.ExpressName)).ToList();
|
|
}
|
|
}
|
|
|
|
public class KuaiDi100SubscribeResponse
|
|
{
|
|
public bool result { get; set; }
|
|
|
|
public int returnCode { get; set; }
|
|
|
|
public string message { get; set; }
|
|
}
|
|
|
|
public class KuaiDi100ExpressCompany
|
|
{
|
|
public string ExpressId { get; set; }
|
|
|
|
public string ExpressName { get; set; }
|
|
|
|
public string Type { get; set; }
|
|
}
|
|
|
|
public class KuaiDi100ExpressSearchRequest
|
|
{
|
|
public string ExpressName { get; set; }
|
|
}
|
|
}
|
|
|