using AllBase; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using Work.Api; namespace Work { public class CostTemplateSet { public ShopChatBase Shop; public static List costTemplateList = new List(); public static List costlateList = new List(); public void query() { costlateList.Clear(); costTemplateList.Clear(); string html = ""; if (!BaseClass.UseApiFirst) { string url = "https://mms.pinduoduo.com/express_inf/cost_template/get_list"; string refere = "https://mms.pinduoduo.com/Pdd.html"; string data = "{\"mallId\":" + Shop.MallId + ",\"pageNo\":1,\"pageSize\":10,\"sourceKey\":\"MMS\"}"; html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies); //var m = BaseRegex.GetMatchRegex(ref html, @"{[\s]*""costTemplateId"":[\s\S]+?""dispatchCost""[^}]+?}"); var m = BaseRegex.GetMatchRegex(ref html, @"{[\s]*""costTemplateId"":[\s\S]+?""noShipConfig""[\w\W]+?][\s]*}"); for (int j = 0; m != null && j < m.Count; j++) { string list = m[j].Groups[0].Value; CostTemplate costTemplate = new CostTemplate(); costTemplate.shopName = Shop.ShopName; costTemplate.costTemplateId = BaseRegex.GetLongJson(ref list, "costTemplateId"); costTemplate.costTemplateName = BaseRegex.GetStringJson(ref list, "costTemplateName"); costTemplate.costType = BaseRegex.GetIntJson(ref list, "costType"); costTemplate.provinceId = BaseRegex.GetIntJson(ref list, "provinceId"); costTemplate.cityId = BaseRegex.GetIntJson(ref list, "cityId"); costTemplate.districtId = BaseRegex.GetIntJson(ref list, "districtId"); costTemplate.templateItemId = BaseRegex.GetLongJson(ref list, "templateItemId"); costTemplate.updateTime = BaseRegex.GetLongJson(ref list, "updateTime"); var mcp = BaseRegex.GetMatchRegex(ref list, @"""dispatchFree"":{[\w\W]+?""dispatchCost"""); string mcpStr = mcp[0].Groups[0].Value; var mc = BaseRegex.GetMatchRegex(ref mcpStr, @"{""province"":([\d]+?)}"); for (int k = 0; mc != null && k < mc.Count; k++) { int province = int.Parse(mc[k].Groups[1].Value); costTemplate.provinceList.Add(province); } costTemplate.firstStandard = BaseRegex.GetIntJson(ref list, "firstStandard"); costTemplate.firstCost = BaseRegex.GetIntJson(ref list, "firstCost"); costTemplate.addStandard = BaseRegex.GetIntJson(ref list, "addStandard"); costTemplate.addCost = BaseRegex.GetIntJson(ref list, "addCost"); costTemplate.minCountForDeliveryFree = BaseRegex.GetIntJson(ref list, "minCountForDeliveryFree"); costTemplate.noShipReasonType = BaseRegex.GetIntJson(ref list, "noShipReasonType"); costTemplate.minAmountForDeliveryFree = BaseRegex.GetIntJson(ref list, "minAmountForDeliveryFree"); mc = BaseRegex.GetMatchRegex(ref list, @"""hasMinAmount"":([\w\W]+?),"); if (mc != null && mc.Count > 0) costTemplate.hasMinAmount = mc[0].Groups[1].Value; costTemplate.minText = "minCountForDeliveryFree"; costTemplate.buygood = costTemplate.minCountForDeliveryFree.ToString(); if (costTemplate.hasMinAmount == "true") { costTemplate.buygood = costTemplate.minAmountForDeliveryFree + "00"; costTemplate.minText = "minAmountForDeliveryFree"; } mc = BaseRegex.GetMatchRegex(ref list, @"""areaList"":[{""province"":[\d]+?}],""firstStandard"""); for (int k = 0; mc != null && k < mc.Count; k++) { string item = mc[k].Groups[0].Value; int province = BaseRegex.GetIntJson(ref item, "province"); costTemplate.payList.Add(province); } mc = BaseRegex.GetMatchRegex(ref list, @"""noShipConfig"":[[\w\W]+?]"); mcpStr = mc[0].Groups[0].Value; var mcv = BaseRegex.GetMatchRegex(ref mcpStr, @"{""province"":([\d]+),""noShipReasonType"":[\d]+}"); for (int k = 0; mcv != null && k < mcv.Count; k++) { int province = int.Parse(mcv[k].Groups[1].Value); costTemplate.nopayList.Add(province); } costTemplateList.Add(costTemplate); costlateList.Add(costTemplate); } } else { string htmlTemplate = new PinduoduoApiGetProduct(Shop).GetLogisticsTemplate(); if (htmlTemplate.Contains("goods_logistics_template_get_response")) { // {"goods_logistics_template_get_response":{"total_count":2,"logistics_template_list":[{"free_deliver_house":false,"template_name":"123","cost_template_list":[],"free_deliver_house_area_list":[],"cost_type":0,"province_id":3,"sf_free_type":0,"template_id":135941251406166,"district_id":3404,"additional_service_type":null,"free_province_list":[{"province":"北京市","province_id":2},{"province":"安徽省","province_id":3},{"province":"福建省","province_id":4},{"province":"广东省","province_id":6},{"province":"广西壮族自治区","province_id":7},{"province":"贵州省","province_id":8},{"province":"河北省","province_id":10},{"province":"河南省","province_id":11},{"province":"黑龙江省","province_id":12},{"province":"湖北省","province_id":13},{"province":"湖南省","province_id":14},{"province":"吉林省","province_id":15},{"province":"江苏省","province_id":16},{"province":"江西省","province_id":17},{"province":"辽宁省","province_id":18},{"province":"山东省","province_id":22},{"province":"山西省","province_id":23},{"province":"陕西省","province_id":24},{"province":"上海市","province_id":25},{"province":"四川省","province_id":26},{"province":"天津市","province_id":27},{"province":"云南省","province_id":30},{"province":"浙江省","province_id":31},{"province":"重庆市","province_id":32}],"city_id":3401},{"free_deliver_house":false,"template_name":"12345","cost_template_list":[],"free_deliver_house_area_list":[],"cost_type":0,"province_id":3,"sf_free_type":0,"template_id":135853330403670,"district_id":3404,"additional_service_type":null,"free_province_list":[{"province":"安徽省","province_id":3}],"city_id":3401}],"request_id":"15876283275836320"}} JObject jObj = JObject.Parse(htmlTemplate); var jArr = jObj["goods_logistics_template_get_response"]["logistics_template_list"] as JArray; if (jArr != null) { foreach (var item in jArr) { string str = item.ToString(); CostTemplate costTemplate = new CostTemplate(); costTemplate.shopName = Shop.ShopName; costTemplate.costTemplateId = AllBase.BaseRegex.GetLongJson(ref str, "template_id"); // 模板编号 costTemplate.costTemplateName = AllBase.BaseRegex.GetStringJson(ref str, "template_name"); // 模板名称 costTemplate.costType = AllBase.BaseRegex.GetIntJson(ref str, "cost_type"); // 模板付费类型 costTemplate.provinceId = AllBase.BaseRegex.GetIntJson(ref str, "province_id"); // 发货省编号 costTemplate.cityId = AllBase.BaseRegex.GetIntJson(ref str, "city_id"); // 发货市编号 costTemplate.districtId = AllBase.BaseRegex.GetIntJson(ref str, "district_id"); // 发货区编号 //costTemplate.templateItemId = AllBase.BaseRegex.GetLongJson(ref str, "templateItemId"); //costTemplate.updateTime = BaseRegex.GetLongJson(ref str, "updateTime"); // 包邮地区 var provinceArr = item["free_province_list"] as JArray; if (provinceArr != null) { foreach (var freeProvince in provinceArr) { try { int province = Convert.ToInt32(freeProvince["province_id"]); costTemplate.provinceList.Add(province); //costTemplate.provinceNameList.Add(freeProvince["province"].ToString()); } catch { } } } costTemplate.firstStandard = AllBase.BaseRegex.GetIntJson(ref str, "first_standard"); // 首件 costTemplate.firstCost = AllBase.BaseRegex.GetIntJson(ref str, "first_cost"); // 首件或首重邮费价格,单位为分 costTemplate.addStandard = AllBase.BaseRegex.GetIntJson(ref str, "add_standard"); // 续重或续件 costTemplate.addCost = AllBase.BaseRegex.GetIntJson(ref str, "add_cost"); // 续件或续重邮费价格,单位为分 costTemplate.minCountForDeliveryFree = AllBase.BaseRegex.GetIntJson(ref str, "have_free_min_count"); // 对不包邮地区,满足指定件数包邮,该值为商家设置的指定件数,若为 - 1则商家没有开启满足件数包邮 costTemplate.minAmountForDeliveryFree = AllBase.BaseRegex.GetIntJson(ref str, "have_free_min_amount"); // 对不包邮地区,满足指定价格包邮,该值为商家设置的指定订单金额,若为 - 1则商家没有开启满足指定价格包邮,注意,单位为分 //costTemplate.noShipReasonType = AllBase.BaseRegex.GetIntJson(ref str, "noShipReasonType"); // 不包邮原因 API接口暂不支持 var mc = AllBase.BaseRegex.GetMatchRegex(ref str, @"""is_have_free_min_amount"":([\w\W]+?),"); if (mc != null && mc.Count > 0) costTemplate.hasMinAmount = mc[0].Groups[1].Value.StartsWith("true") ? "true" : "false"; costTemplate.minText = "minCountForDeliveryFree"; costTemplate.buygood = costTemplate.minCountForDeliveryFree.ToString(); if (costTemplate.hasMinAmount == "true") { //costTemplate.buygood = costTemplate.minAmountForDeliveryFree + "00"; costTemplate.minText = "minAmountForDeliveryFree"; } // 邮费配送地区 mc = AllBase.BaseRegex.GetMatchRegex(ref str, @"""areaList"":[{""province"":[\d]+?}],""firstStandard"""); var costProvinceArr = item["cost_template_list"] as JArray; if (costProvinceArr != null) { foreach (var costProvinceItem in costProvinceArr) { string costStr = costProvinceItem.ToString(); int provinceId = AllBase.BaseRegex.GetIntJson(ref costStr, "province_id"); costTemplate.payList.Add(provinceId); } } // 不配送地区 API接口暂不支持 //mc = BaseRegex.GetMatchRegex(ref list, @"""noShipConfig"":[[\w\W]+?]"); //mcpStr = mc[0].Groups[0].Value; //var mcv = BaseRegex.GetMatchRegex(ref mcpStr, @"{""province"":([\d]+),""noShipReasonType"":[\d]+}"); //for (int k = 0; mcv != null && k < mcv.Count; k++) //{ // int province = int.Parse(mcv[k].Groups[1].Value); // costTemplate.nopayList.Add(province); //} costlateList.Add(costTemplate); costTemplateList.Add(costTemplate); } } } Thread.Sleep(1000); } } } public class CostTemplate { public string shopName = ""; public long costTemplateId = 0; public long templateItemId = 0; public string costTemplateName = ""; public int costType = 0; public int provinceId = 0; public int cityId = 0; public int districtId = 0; public long updateTime = 0; public List provinceList = new List(); public int firstStandard = 0; public int firstCost = 0; public int addStandard = 0; public int addCost = 0; public int minCountForDeliveryFree = 0; public int noShipReasonType = 0; public int minAmountForDeliveryFree = 0; public string hasMinAmount = "false"; public string minText = ""; public string buygood = ""; public List payList = new List(); public List nopayList = new List(); } }