using System.Collections.Generic; using AllBase; using System; using System.IO; using System.IO.Compression; using System.Net; using System.Threading; //using JavaScriptEngineSwitcher.Core; //using JavaScriptEngineSwitcher.V8; using Work.CollectClass; using System.Text; using System.Linq; namespace Work.Api { public class UpdatePinduoduoExpressSet { public static List Express = new List(); /// /// 获取最后一个运费模板 /// /// /// /// /// public long GetFirst(string cookies, int mallid, ShopChatBase Shop) { string url = "https://mms.pinduoduo.com/express_inf/cost_template/get_list"; string refere = "https://mms.pinduoduo.com/Pdd.html"; string data = "{\"mallId\":" + mallid + ",\"pageNo\":1,\"pageSize\":1000}"; string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies); var m = BaseRegex.GetMatchRegex(ref html, @"""costTemplateId"":[\s]*([\d]+)"); long id = 0; for (int i = 0; m != null && i < m.Count; i++) { long j = long.Parse(m[0].Groups[1].Value); if (j > id) id = j; } if (id > 0) return id; html = new PinduoduoApiGetProduct(Shop).GetLogisticsTemplate(); m = BaseRegex.GetMatchRegex(ref html, @"""template_id"":[\s]*([\d]+)"); for (int i = 0; m != null && i < m.Count; i++) { long j = long.Parse(m[0].Groups[1].Value); if (j > id) id = j; } return id; } /// /// 获取指定第几新的运费模板,如果超过模板总数,返回最旧的一个 /// /// /// /// /// 排名第几新的运费模板 /// public long GetOneRank(string cookies, int mallid, ShopChatBase Shop, ref int rank) { string url = "https://mms.pinduoduo.com/express_inf/cost_template/get_list"; string refere = "https://mms.pinduoduo.com/Pdd.html"; string data = "{\"mallId\":" + mallid + ",\"pageNo\":1,\"pageSize\":1000}"; string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies); var m = BaseRegex.GetMatchRegex(ref html, @"""costTemplateId"":[\s]*([\d]+)"); List tempIds = new List(); long id = 0; for (int i = 0; m != null && i < m.Count; i++) { long j = long.Parse(m[0].Groups[1].Value); if (j > 0) tempIds.Add(j); } if (tempIds.Count > 0) { tempIds = tempIds.OrderByDescending(t => t).ToList(); if (rank < tempIds.Count - 1) return tempIds[rank]; else { rank = 1000; return tempIds.Last(); } } // 使用api获取 html = new PinduoduoApiGetProduct(Shop).GetLogisticsTemplate(); m = BaseRegex.GetMatchRegex(ref html, @"""template_id"":[\s]*([\d]+)"); for (int i = 0; m != null && i < m.Count; i++) { long j = long.Parse(m[0].Groups[1].Value); if (j > 0) tempIds.Add(j); } if (tempIds.Count > 0) { tempIds = tempIds.OrderByDescending(t => t).ToList(); if (rank < tempIds.Count - 1) return tempIds[rank]; else { rank = 1000; return tempIds.Last(); } } return id; } public long GetRandx(string cookies, int mallid, ShopChatBase Shop) { string url = "https://mms.pinduoduo.com/express_inf/cost_template/get_list"; string refere = "https://mms.pinduoduo.com/Pdd.html"; string data = "{\"mallId\":" + mallid + ",\"pageNo\":1,\"pageSize\":1000}"; string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies); var m = BaseRegex.GetMatchRegex(ref html, @"""costTemplateId"":[\s]*([\d]+)"); long id = 0; if (m == null) goto UseApi; if (m.Count == 1) { long tid = BaseRegex.GetLongJson(ref html, "costTemplateId"); string urlxt = "https://mms.pinduoduo.com/express_inf/cost_template/copy"; string referext = "https://mms.pinduoduo.com/orders/order/carriage/list"; string dataxt = "{\"costTemplateId\":" + tid + ",\"sourceKey\":\"MMS\"}"; string htmlxt = Request_mms_pinduoduo_com(urlxt, referext, Shop.Cookies, dataxt, getAnti0aon()); if (htmlxt.Contains("ok")) { html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies); tid = BaseRegex.GetLongJson(ref html, "costTemplateId"); return tid; } } int randx = new Random(Guid.NewGuid().GetHashCode()).Next(1, m.Count); return long.Parse(m[randx].Groups[1].Value); UseApi: html = new PinduoduoApiGetProduct(Shop).GetLogisticsTemplate(); m = BaseRegex.GetMatchRegex(ref html, @"""template_id"":[\s]*([\d]+)"); if (m == null || m.Count <= 1) return id; int randxt = new Random(Guid.NewGuid().GetHashCode()).Next(1, m.Count); return long.Parse(m[randxt].Groups[1].Value); } public int GetFirst(string cookies, int mallid) { string url = "https://mms.pinduoduo.com/express_base/cost_template/get_list"; string refere = "https://mms.pinduoduo.com/Pdd.html"; string data = "{\"mallId\":" + mallid + ",\"pageNo\":1,\"pageSize\":1000}"; string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies); int id = BaseRegex.GetIntJson(ref html, "costTemplateId"); return id; } public static string Request_mms_pinduoduo_com(string url, string referer, string cookie, string data, string antiContent, IWebProxy proxy = null) { string responseText = ""; HttpWebResponse response = null; try { //HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://mms.pinduoduo.com/cps/api/coupon/createCommonCoupon"); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.KeepAlive = true; request.Accept = "application/json"; //request.Headers.Add("Anti-Content", @"0aoAfxnUgOQoU9dVEHIuLKYezEfQ51QpOcKVg_S0aww9S8dseM_tTxYptgFssmH7wfRCpRvfISyXp-bZ8hcq7ux0Z1kvhFUkfIMk7EsEefUAZS7Jv1vYHm1Cplb4GZ43dSFtKu19dO7snIyL-VRj0JFy0ETKDkf1EdaPbWEu22sZ4s1duGD6WO9lgeS-oTsEwwa9ohcX2E_DG2PggPHqIuxcN_tIthAewaqklSPvPmFwzYxrlo256wd2i74SMvTzGTB--UkZ3gPl5t6K-6IVCz1MDD7WDS9HeoGm4RBmyd0LIpXG400lOfKBvPh-z09PL3_hjiL1KiBCENrs1ANosN35LJ8zhlCRi0YrDxphd8LGJFWDG0LrARGRuMW7d3d4IlWlEKFFMiucGGNlIZqDyExDIMny-8T-KY8fJ8BnNuzWyr"); request.Headers.Add("Anti-Content", antiContent); //request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"; request.UserAgent = BaseClass.ChromeUserAgent; request.ContentType = "application/json;charset=UTF-8"; request.Headers.Add("Origin", @"https://mms.pinduoduo.com"); request.Headers.Add("Sec-Fetch-Site", @"same-origin"); request.Headers.Add("Sec-Fetch-Mode", @"cors"); request.Headers.Add("Sec-Fetch-Dest", @"empty"); request.Referer = referer; request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br"); request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9"); request.Headers.Set(HttpRequestHeader.Cookie, cookie); if (proxy != null) request.Proxy = proxy; request.Method = "POST"; request.ServicePoint.Expect100Continue = false; string body = data; byte[] postBytes = System.Text.Encoding.UTF8.GetBytes(body); request.ContentLength = postBytes.Length; Stream stream = request.GetRequestStream(); stream.Write(postBytes, 0, postBytes.Length); stream.Close(); response = (HttpWebResponse)request.GetResponse(); } catch (WebException e) { if (e.Status == WebExceptionStatus.ProtocolError) response = (HttpWebResponse)e.Response; else responseText = "error," + e.Message; } catch (Exception ex) { responseText = "error," + ex.Message; } if (response != null) { if (string.IsNullOrEmpty(responseText)) responseText = ReadResponse(response); response.Close(); } Thread.Sleep(50 + Randomx.GetId(100)); return responseText; } /// /// 读取返回值 /// /// /// public static string ReadResponse(HttpWebResponse response) { using (Stream responseStream = response.GetResponseStream()) { Stream streamToRead = responseStream; if (response.ContentEncoding.ToLower().Contains("gzip")) { streamToRead = new GZipStream(streamToRead, CompressionMode.Decompress); } else if (response.ContentEncoding.ToLower().Contains("deflate")) { streamToRead = new DeflateStream(streamToRead, CompressionMode.Decompress); } using (StreamReader streamReader = new StreamReader(streamToRead, Encoding.UTF8)) { return streamReader.ReadToEnd(); } } } public static string getAnti0aon() { string anti = ""; //using (IJsEngine jsEngine = new V8JsEngine()) //{ // jsEngine.Execute(GetProductOnlineClass.PinDuoDUo_0ao); // anti = jsEngine.CallFunction("get_anti", "").ToString(); // try // { anti = "0ao" + anti.Substring(3); } // catch { } //} return anti; } } }