From 892c9eb284cb67eba45021776263c28dd6d22b9c Mon Sep 17 00:00:00 2001 From: jianweie code Date: Fri, 29 Dec 2023 21:35:34 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=E5=BF=AB?= =?UTF-8?q?=E9=80=92=E7=89=A9=E6=B5=81=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=96=B0=E5=A2=9Ev2=E7=89=88=E6=9C=AC=EF=BC=8C=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0v1=E4=B8=8Ev2=E7=89=88=E6=9C=AC=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SystemSettingConstVars.cs | 4 + .../SystemSettingDictionary.cs | 1 + CoreCms.Net.Model/CoreCms.Net.Model.xml | 209 +++++++++- CoreCms.Net.Model/ViewModels/Api/ShowApi.cs | 203 +++++++++- .../Shop/CoreCmsLogisticsServices.cs | 361 +++++++++++++----- .../Shop/CoreCmsLogisticsController.cs | 6 +- .../CoreCms.Net.Web.Admin.xml | 2 +- .../wwwroot/views/shop/setting/index.html | 8 + 8 files changed, 663 insertions(+), 131 deletions(-) diff --git a/CoreCms.Net.Configuration/SystemSettingConstVars.cs b/CoreCms.Net.Configuration/SystemSettingConstVars.cs index ab79c2d1..76f74055 100644 --- a/CoreCms.Net.Configuration/SystemSettingConstVars.cs +++ b/CoreCms.Net.Configuration/SystemSettingConstVars.cs @@ -612,6 +612,10 @@ namespace CoreCms.Net.Configuration /// /// 易源接口授权key /// + public const string ShowApiLogisticsVersion = "showApiLogisticsVersion"; + /// + /// 易源接口授权key + /// public const string ShowApiAppid = "showApiAppid"; /// /// 易源接口授权密钥 diff --git a/CoreCms.Net.Configuration/SystemSettingDictionary.cs b/CoreCms.Net.Configuration/SystemSettingDictionary.cs index 3a95573c..d950205c 100644 --- a/CoreCms.Net.Configuration/SystemSettingDictionary.cs +++ b/CoreCms.Net.Configuration/SystemSettingDictionary.cs @@ -204,6 +204,7 @@ namespace CoreCms.Net.Configuration //客服ID di.Add(SystemSettingConstVars.EntId, new DictionaryKeyValues() { sKey = "客服ID", sValue = "" }); //易源接口授权 + di.Add(SystemSettingConstVars.ShowApiLogisticsVersion, new DictionaryKeyValues() { sKey = "物流接口版本", sValue = "1" }); di.Add(SystemSettingConstVars.ShowApiAppid, new DictionaryKeyValues() { sKey = "AppId", sValue = "" }); di.Add(SystemSettingConstVars.ShowApiSecret, new DictionaryKeyValues() { sKey = "授权Secret", sValue = "" }); diff --git a/CoreCms.Net.Model/CoreCms.Net.Model.xml b/CoreCms.Net.Model/CoreCms.Net.Model.xml index de32affa..c8d3ed3b 100644 --- a/CoreCms.Net.Model/CoreCms.Net.Model.xml +++ b/CoreCms.Net.Model/CoreCms.Net.Model.xml @@ -10449,56 +10449,241 @@ 内容:【XXXXXXX公司】 派件中 派件人: 滕XX 电话 13787XXXXX 如有疑问,请联系:XXXXX-XXXXX - + - 查询货运公司列表返回实体数据 + 查询货运公司列表返回实体数据V1 - + 错误说明 - + 状态码 - + 返回资源序列 - + 返回资源主体 - + - 查询货运公司列表返回实体数据 + - + + + + + + + + 顺丰速运 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 查询成功! + + + + + + + + + + + + + + + + + + + + + + + + + 查询物流轨迹返回值V1 + + + 错误说明 - + 状态码 - + 返回资源序列 - + 返回资源主体 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 浙江省-台州市 + + + + + 【台州市】已离开 浙江台州分拨交付中心;发往 山东潍坊分拨交付中心 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 查询成功 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 韵达速递 + + 代码生成器下拉数据列表实体 diff --git a/CoreCms.Net.Model/ViewModels/Api/ShowApi.cs b/CoreCms.Net.Model/ViewModels/Api/ShowApi.cs index 79683be8..d4831542 100644 --- a/CoreCms.Net.Model/ViewModels/Api/ShowApi.cs +++ b/CoreCms.Net.Model/ViewModels/Api/ShowApi.cs @@ -12,12 +12,12 @@ using System.Collections.Generic; namespace CoreCms.Net.Model.ViewModels.Api { - #region 查询货运公司列表返回实体数据 + #region 查询货运公司列表返回实体数据V1 /// - /// 查询货运公司列表返回实体数据 + /// 查询货运公司列表返回实体数据V1 /// - public class ShowApiGetExpressCompanyListResult + public class ShowApiGetExpressCompanyListResultV1 { /// /// 错误说明 @@ -88,12 +88,79 @@ namespace CoreCms.Net.Model.ViewModels.Api #endregion 查询物流信息 - #region MyRegion + #region 查询货运公司列表返回实体数据V2 + public class Express_listItem + { + /// + /// + /// + public string img_url { get; set; } + /// + /// + /// + public string phone { get; set; } + /// + /// 顺丰速运 + /// + public string exp_name { get; set; } + /// + /// + /// + public string com { get; set; } + /// + /// + /// + public string url { get; set; } + /// + /// + /// + public string note { get; set; } + } + + public class Showapi_res_body + { + /// + /// + /// + public int ret_code { get; set; } + /// + /// + /// + public List express_list { get; set; } + /// + /// 查询成功! + /// + public string msg { get; set; } + } + + public class ShowApiGetExpressCompanyListResultV2 + { + /// + /// + /// + public string showapi_res_error { get; set; } + /// + /// + /// + public int showapi_res_code { get; set; } + /// + /// + /// + public string showapi_res_id { get; set; } + /// + /// + /// + public Showapi_res_body showapi_res_body { get; set; } + } + + #endregion + + #region 查询物流轨迹返回值V1 /// - /// 查询货运公司列表返回实体数据 + /// 查询物流轨迹返回值V1 /// - public class ShowApiGetExpressPollResult + public class ShowApiGetExpressPollResultV1 { /// /// 错误说明 @@ -113,11 +180,11 @@ namespace CoreCms.Net.Model.ViewModels.Api /// /// 返回资源主体 /// - public ExpressPollResBody showapi_res_body { get; set; } + public ExpressPollResBodyV1 showapi_res_body { get; set; } } - public class ExpressPollResBody + public class ExpressPollResBodyV1 { public long update { get; set; } public string upgrade_info { get; set; } @@ -127,7 +194,7 @@ namespace CoreCms.Net.Model.ViewModels.Api public int status { get; set; } public int fee_num { get; set; } public string tel { get; set; } - public List data { get; set; } + public List data { get; set; } public string expSpellName { get; set; } public string msg { get; set; } @@ -139,11 +206,127 @@ namespace CoreCms.Net.Model.ViewModels.Api public List possibleExpList { get; set; } } - public class PollData + public class PollDataV1 { public string time { get; set; } public string context { get; set; } } #endregion + + #region 查询物流轨迹返回值V2 + + + public class ShowApiGetExpressPollResultV2 + { + /// + /// + /// + public string showapi_res_error { get; set; } + /// + /// + /// + public int showapi_fee_num { get; set; } + /// + /// + /// + public int showapi_res_code { get; set; } + /// + /// + /// + public string showapi_res_id { get; set; } + /// + /// + /// + public ExpressPollResBodyV2 showapi_res_body { get; set; } + } + + + public class PollDataV2 + { + /// + /// + /// + public string time { get; set; } + /// + /// + /// + public string location { get; set; } + /// + /// + /// + public int status { get; set; } + /// + /// 浙江省-台州市 + /// + public string address { get; set; } + /// + /// 【台州市】已离开 浙江台州分拨交付中心;发往 山东潍坊分拨交付中心 + /// + public string context { get; set; } + } + + public class ExpressPollResBodyV2 + { + /// + /// + /// + public string delivery_time { get; set; } + /// + /// + /// + public string nu { get; set; } + /// + /// + /// + public string logo { get; set; } + /// + /// + /// + public string original_com { get; set; } + /// + /// + /// + public string com { get; set; } + /// + /// + /// + public string tel { get; set; } + /// + /// + /// + public List? data { get; set; } + /// + /// 查询成功 + /// + public string msg { get; set; } + /// + /// + /// + public List? possible_exp_list { get; set; } + /// + /// + /// + public int ret_code { get; set; } + /// + /// + /// + public int showapi_inner_fee_num { get; set; } + /// + /// + /// + public string update_time { get; set; } + /// + /// + /// + public int query_num { get; set; } + /// + /// 韵达速递 + /// + public string com_name { get; set; } + } + + #endregion + + } \ No newline at end of file diff --git a/CoreCms.Net.Services/Shop/CoreCmsLogisticsServices.cs b/CoreCms.Net.Services/Shop/CoreCmsLogisticsServices.cs index cea29daa..6854f2b9 100644 --- a/CoreCms.Net.Services/Shop/CoreCmsLogisticsServices.cs +++ b/CoreCms.Net.Services/Shop/CoreCmsLogisticsServices.cs @@ -21,6 +21,7 @@ using CoreCms.Net.Model.ViewModels.UI; using CoreCms.Net.Utility.Helper; using Flurl.Http; using Newtonsoft.Json; +using SqlSugar.Extensions; namespace CoreCms.Net.Services @@ -72,6 +73,7 @@ namespace CoreCms.Net.Services var jm = new AdminUiCallBack(); var allConfigs = await _settingServices.GetConfigDictionaries(); + var showApiLogisticsVersion = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShowApiLogisticsVersion).ObjToInt(1); var showApiAppid = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShowApiAppid); var showApiSecret = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShowApiSecret); var shopMobile = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShopMobile); @@ -82,69 +84,123 @@ namespace CoreCms.Net.Services var signStr = "maxSize" + maxSize + "showapi_appid" + showApiAppid + "showapi_timestamp" + showApiTimesTamp + showApiSecret; var md5Sign = CommonHelper.Md5For32(signStr).ToLower(); - var url = "https://route.showapi.com/64-20?expName=&maxSize=1500&page=&showapi_appid=" + showApiAppid + - "&showapi_timestamp=" + showApiTimesTamp + "&showapi_sign=" + md5Sign; - - - - var result = await url.PostAsync().ReceiveJson(); - - - - - if (result.showapi_res_code == 0) + string url; + if (showApiLogisticsVersion == 1) { - if (result.showapi_res_body != null && result.showapi_res_body.ret_code == 0 && result.showapi_res_body.expressList != null && result.showapi_res_body.expressList.Count > 0) + url = "https://route.showapi.com/64-20?expName=&maxSize=1500&page=&showapi_appid=" + showApiAppid + "&showapi_timestamp=" + showApiTimesTamp + "&showapi_sign=" + md5Sign; + + var result = await url.PostAsync().ReceiveJson(); + + if (result.showapi_res_code == 0) { - var list = new List(); - - - var systemLogistics = SystemSettingDictionary.GetSystemLogistics(); - systemLogistics.ForEach(p => + if (result.showapi_res_body != null && result.showapi_res_body.ret_code == 0 && result.showapi_res_body.expressList != null && result.showapi_res_body.expressList.Count > 0) { - var logistics = new CoreCmsLogistics(); - logistics.logiCode = p.sKey; - logistics.logiName = p.sDescription; - logistics.imgUrl = ""; - logistics.phone = shopMobile; - logistics.url = ""; - logistics.sort = -1; - logistics.isDelete = false; + var list = new List(); - list.Add(logistics); - }); - + var systemLogistics = SystemSettingDictionary.GetSystemLogistics(); + systemLogistics.ForEach(p => + { + var logistics = new CoreCmsLogistics(); + logistics.logiCode = p.sKey; + logistics.logiName = p.sDescription; + logistics.imgUrl = ""; + logistics.phone = shopMobile; + logistics.url = ""; + logistics.sort = -1; + logistics.isDelete = false; - var count = 0; - result.showapi_res_body.expressList.ForEach(p => + list.Add(logistics); + }); + + var count = 0; + result.showapi_res_body.expressList.ForEach(p => + { + var logistics = new CoreCmsLogistics(); + logistics.logiCode = p.simpleName; + logistics.logiName = p.expName; + logistics.imgUrl = p.imgUrl; + logistics.phone = p.phone; + logistics.url = p.url; + logistics.sort = count * 5; + logistics.isDelete = false; + + list.Add(logistics); + count++; + }); + await _dal.DeleteAsync(p => p.id > 0); + var bl = await _dal.InsertAsync(list) > 0; + jm.code = bl ? 0 : 1; + jm.msg = bl ? "数据刷新成功" : "数据刷新失败"; + } + else { - var logistics = new CoreCmsLogistics(); - logistics.logiCode = p.simpleName; - logistics.logiName = p.expName; - logistics.imgUrl = p.imgUrl; - logistics.phone = p.phone; - logistics.url = p.url; - logistics.sort = count * 5; - logistics.isDelete = false; - - list.Add(logistics); - count++; - }); - await _dal.DeleteAsync(p => p.id > 0); - var bl = await _dal.InsertAsync(list) > 0; - jm.code = bl ? 0 : 1; - jm.msg = bl ? "数据刷新成功" : "数据刷新失败"; + jm.msg = "接口获取数据失败"; + } } else { - jm.msg = "接口获取数据失败"; + jm.msg = result.showapi_res_error; } } else { - jm.msg = result.showapi_res_error; + url = "https://route.showapi.com/2650-5?expName=&maxSize=1500&page=&showapi_appid=" + showApiAppid + "&showapi_timestamp=" + showApiTimesTamp + "&showapi_sign=" + md5Sign; + + var result = await url.PostAsync().ReceiveJson(); + + if (result.showapi_res_code == 0) + { + if (result.showapi_res_body != null && result.showapi_res_body.ret_code == 0 && result.showapi_res_body.express_list != null && result.showapi_res_body.express_list.Count > 0) + { + var list = new List(); + + var systemLogistics = SystemSettingDictionary.GetSystemLogistics(); + systemLogistics.ForEach(p => + { + var logistics = new CoreCmsLogistics(); + logistics.logiCode = p.sKey; + logistics.logiName = p.sDescription; + logistics.imgUrl = ""; + logistics.phone = shopMobile; + logistics.url = ""; + logistics.sort = -1; + logistics.isDelete = false; + + list.Add(logistics); + }); + + var count = 0; + result.showapi_res_body.express_list.ForEach(p => + { + var logistics = new CoreCmsLogistics(); + logistics.logiCode = p.com; + logistics.logiName = p.exp_name; + logistics.imgUrl = p.img_url; + logistics.phone = p.phone; + logistics.url = p.url; + logistics.sort = count * 5; + logistics.isDelete = false; + + list.Add(logistics); + count++; + }); + await _dal.DeleteAsync(p => p.id > 0); + var bl = await _dal.InsertAsync(list) > 0; + jm.code = bl ? 0 : 1; + jm.msg = bl ? "数据刷新成功" : "数据刷新失败"; + } + else + { + jm.msg = "接口获取数据失败"; + } + } + else + { + jm.msg = result.showapi_res_error; + } } + return jm; } @@ -177,8 +233,8 @@ namespace CoreCms.Net.Services return jm; } - var allConfigs = await _settingServices.GetConfigDictionaries(); + var showApiLogisticsVersion = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShowApiLogisticsVersion).ObjToInt(1); var showApiAppid = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShowApiAppid); var showApiSecret = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShowApiSecret); @@ -187,70 +243,165 @@ namespace CoreCms.Net.Services var signStr = "com" + com + "nu" + number + "phone" + phone + "showapi_appid" + showApiAppid + "showapi_timestamp" + showApiTimesTamp + showApiSecret; var md5Sign = CommonHelper.Md5For32(signStr).ToLower(); - var url = "https://route.showapi.com/64-19?com=" + com + "&nu=" + number + "&phone=" + phone + "&showapi_appid=" + showApiAppid + - "&showapi_timestamp=" + showApiTimesTamp + "&showapi_sign=" + md5Sign; - - - var result = await url.PostAsync().ReceiveJson(); - - - if (result.showapi_res_code != 0) + string url; + if (showApiLogisticsVersion == 1) { - jm.status = false; - jm.msg = result.showapi_res_error; + url = "https://route.showapi.com/64-19?com=" + com + "&nu=" + number + "&phone=" + phone + "&showapi_appid=" + showApiAppid + "&showapi_timestamp=" + showApiTimesTamp + "&showapi_sign=" + md5Sign; + var result = await url.PostAsync().ReceiveJson(); + if (result.showapi_res_code != 0) + { + jm.status = false; + jm.msg = result.showapi_res_error; + } + else + { + jm = GetLogiInfo(1, result.showapi_res_code, result.showapi_res_body); + } } else { - switch (result.showapi_res_body.ret_code) + url = "https://route.showapi.com/2650-3?com=" + com + "&nu=" + number + "&phone=" + phone + "&showapi_appid=" + showApiAppid + "&showapi_timestamp=" + showApiTimesTamp + "&showapi_sign=" + md5Sign; + var result = await url.PostAsync().ReceiveJson(); + if (result.showapi_res_code != 0) { - case 0: - jm.status = true; - jm.msg = "查询成功"; - jm.data = result.showapi_res_body; - break; - case 1: - jm.status = false; - jm.msg = "输入参数错误"; - jm.data = result.showapi_res_body; - break; - case 2: - jm.status = false; - jm.msg = "查不到物流信息"; - jm.data = result.showapi_res_body; - break; - case 3: - jm.status = false; - jm.msg = "单号不符合规则"; - jm.data = result.showapi_res_body; - break; - case 4: - jm.status = false; - jm.msg = "快递公司编码不符合规则"; - jm.data = result.showapi_res_body; - break; - case 5: - jm.status = false; - jm.msg = "快递查询渠道异常"; - jm.data = result.showapi_res_body; - break; - case 6: - jm.status = false; - jm.msg = " auto时未查到单号对应的快递公司,请指定快递公司编码"; - jm.data = result.showapi_res_body; - break; - case 7: - jm.status = false; - jm.msg = "单号与手机号不匹配"; - jm.data = result.showapi_res_body; - break; - default: - jm.status = false; - jm.msg = "接口调用失败"; - jm.data = result.showapi_res_body; - break; + jm.status = false; + jm.msg = result.showapi_res_error; + } + else + { + jm = GetLogiInfo(1, result.showapi_res_code, result.showapi_res_body); } } return jm; } + + //根据状态反馈提示信息 + private WebApiCallBack GetLogiInfo(int version, int retCode, object showapiResBody) + { + var jm = new WebApiCallBack(); + + if (retCode == 0) + { + jm.status = true; + jm.msg = "查询成功"; + jm.data = showapiResBody; + } + else if (retCode == 1) + { + jm.status = false; + jm.msg = "输入参数错误"; + jm.data = showapiResBody; + } + else if (retCode == 2) + { + jm.status = false; + jm.msg = "查不到物流信息"; + jm.data = showapiResBody; + } + else if (retCode == 3) + { + jm.status = false; + jm.msg = "单号不符合规则"; + jm.data = showapiResBody; + } + else if (retCode == 4) + { + jm.status = false; + jm.msg = "快递公司编码不符合规则"; + jm.data = showapiResBody; + } + else if (retCode == 5) + { + jm.status = false; + jm.msg = "快递查询渠道异常"; + jm.data = showapiResBody; + } + else if (retCode == 6) + { + jm.status = false; + jm.msg = " auto时未查到单号对应的快递公司,请指定快递公司编码"; + jm.data = showapiResBody; + } + else if (retCode == 7) + { + jm.status = false; + jm.msg = "单号与手机号不匹配"; + jm.data = showapiResBody; + } + else if (version == 2) + { + jm.status = true; + + switch (retCode) + { + //101 揽件 + //102 在途中 + //103 派送中 + //104 已签收(完结状态) + //105 用户拒签 + //106 疑难件 + //107 无效单(完结状态) + //108 超时单 + //109 签收失败 + //110 退回 + //111 转投 + //112 待签 + //113 邮件回收 + case 101: + jm.msg = "揽件"; + break; + case 102: + jm.msg = "在途中"; + break; + case 103: + jm.msg = "派送中"; + break; + case 104: + jm.msg = "已签收(完结状态)"; + break; + case 105: + jm.msg = "用户拒签"; + break; + case 106: + jm.msg = "疑难件"; + break; + case 107: + jm.msg = "无效单(完结状态)"; + break; + case 108: + jm.msg = "超时单"; + break; + case 109: + jm.msg = "签收失败"; + break; + case 110: + jm.msg = "退回"; + break; + case 111: + jm.msg = "转投"; + break; + case 112: + jm.msg = "待签"; + break; + case 113: + jm.msg = "邮件回收"; + break; + default: + jm.status = false; + jm.msg = "未知状态"; + break; + } + jm.data = showapiResBody; + } + else + { + jm.status = false; + jm.msg = "接口调用失败"; + jm.data = showapiResBody; + } + + return jm; + } + } } diff --git a/CoreCms.Net.Web.Admin/Controllers/Shop/CoreCmsLogisticsController.cs b/CoreCms.Net.Web.Admin/Controllers/Shop/CoreCmsLogisticsController.cs index f9b97dbb..ab8540e0 100644 --- a/CoreCms.Net.Web.Admin/Controllers/Shop/CoreCmsLogisticsController.cs +++ b/CoreCms.Net.Web.Admin/Controllers/Shop/CoreCmsLogisticsController.cs @@ -186,14 +186,14 @@ namespace CoreCms.Net.Web.Admin.Controllers #endregion - #region 拉取数据更新============================================================ + #region 拉取数据更新快递公司============================================================ // POST: Api/CoreCmsLogistics/DoDelete/10 /// - /// 拉取数据更新 + /// 拉取数据更新快递公司 /// [HttpPost] - [Description("单选删除")] + [Description("拉取数据更新")] public async Task DoUpdateCompany() { var jm = await _coreCmsLogisticsServices.DoUpdateCompany(); diff --git a/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.xml b/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.xml index c08b08d1..5d68a29a 100644 --- a/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.xml +++ b/CoreCms.Net.Web.Admin/CoreCms.Net.Web.Admin.xml @@ -3470,7 +3470,7 @@ - 拉取数据更新 + 拉取数据更新快递公司 diff --git a/CoreCms.Net.Web.Admin/wwwroot/views/shop/setting/index.html b/CoreCms.Net.Web.Admin/wwwroot/views/shop/setting/index.html index 850024f0..698c04d2 100644 --- a/CoreCms.Net.Web.Admin/wwwroot/views/shop/setting/index.html +++ b/CoreCms.Net.Web.Admin/wwwroot/views/shop/setting/index.html @@ -983,6 +983,14 @@
易源接口
+
+ +
+ + +
+
v1地址:【https://www.showapi.com/apiGateway/view/64】 v2地址:【https://www.showapi.com/apiGateway/view/2650】
+