using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; //using FkServices = LittleCow.Framework.Services; namespace Store.Client.Services { ///// ///// 商铺服务 ///// //internal class ShopService : ITransientDependency //{ // private readonly ShopApi _shopApi; // private readonly IEventBus _eventBus; // public ShopService(ShopApi shopApi, IEventBus eventBus) // { // _shopApi = shopApi; // _eventBus = eventBus; // } // /// // /// 获取所有商铺信息 // /// // /// // /// // public List GetShops() where T : ShopBase // { // HttpResult result = _shopApi.GetShops(); // if (result.StatusCode == System.Net.HttpStatusCode.OK) // { // StringBuilder sb = new StringBuilder(); // sb.Append("["); // Regex regShopList = new Regex("]+?)>"); // if (regShopList.IsMatch(result.Html)) // { // int index = 0; // MatchCollection matchs = regShopList.Matches(result.Html); // foreach (Match item in matchs) // { // string value = item.Value; // value = value.Replace("", "\"}"); // value = value.Replace("':'", "\":\""); // value = value.Replace("' '", "\",\""); // if (index > 0) // { // sb.Append(","); // } // sb.Append(value); // index++; // } // sb.Append("]"); // List list = JsonConvert.DeserializeObject>(sb.ToString()); // list.RemoveAll(a => string.IsNullOrEmpty(a.Name)); // return list; // } // } // return new List(); // } // public string GetShopCookie(List shops) // { // HttpResult result = _shopApi.GetShopsCookie(shops); // if (result.StatusCode == System.Net.HttpStatusCode.OK) // { // MatchCollection matchs = Regex.Matches(result.Html, @"([\w\W]+?)"); // if (matchs != null) // { // foreach (Match item in matchs) // { // string shopId = item.Groups[1].Value; // string json = item.Groups[2].Value; // var rootToken = JToken.Parse(json); // string cookie = rootToken["Cookies"]?.ToString() ?? ""; // var shop = shops.FirstOrDefault(a => a.Id == shopId); // if (shop != null) // { // shop.Cookie = new Cookies(cookie); // } // } // } // } // return null; // } // /// // /// 检测商铺登录状态 // /// // public void CheckShopStatus(ShopBase shop) // { // HttpItem item = new HttpItem(); // item.URL = "https://myseller.taobao.com/ajaxProxy.do?_ksTS=1548152154745_13&callback=seller_layout_head&action=FrameworkLayoutAction&event_submit_do_layout_data=true"; // item.Referer = "https://myseller.taobao.com"; // item.Method = MethodType.Post; // item.Cookie = shop.Cookie.GetCookieString(); // HttpResult result = HttpHelper.Request(item); // if (result.StatusCode == System.Net.HttpStatusCode.OK) // { // string a = result.Html.Contains("\"shopName\":\"") ? "登录成功" : "会话已过期"; // } // //string urlx = // //string refere = // //string htmlx = GetPostTaobaoHtml.GetUrl(urlx, refere, true, "", Shop.Cookies); // //Shop.MsgForCookiesLogin = htmlx.Contains("\"shopName\":\"") ? "登录成功" : "会话已过期"; // //GetTaobaoShops.ShopsTemp.Add(Shop); // } // /// // /// 获取值 // /// // /// // /// // /// // private string GetUserValue(string html, string reg) // { // string temp = Regex.Match(html, @"[""]" + reg + @"[""][\s]*:[\s]*[""]([^""]*?)[""]")?.Value; // if (string.IsNullOrEmpty(temp)) // temp = Regex.Match(html, @"[']" + reg + @"['][\s]*:[\s]*[']([^']*?)[']")?.Groups[1].Value; // if (string.IsNullOrEmpty(temp)) // temp = Regex.Match(html, @"['""]" + reg + @"['""][\s]*:[\s]*([\d]+)")?.Value; // return temp; // } //} }