Files
KJD/Store.Framework/Services/ShopService.cs
T
2026-09-11 19:11:12 +08:00

135 lines
5.2 KiB
C#

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
{
///// <summary>
///// 商铺服务
///// </summary>
//internal class ShopService : ITransientDependency
//{
// private readonly ShopApi _shopApi;
// private readonly IEventBus _eventBus;
// public ShopService(ShopApi shopApi, IEventBus eventBus)
// {
// _shopApi = shopApi;
// _eventBus = eventBus;
// }
// /// <summary>
// /// 获取所有商铺信息
// /// </summary>
// /// <typeparam name="T"></typeparam>
// /// <returns></returns>
// public List<T> GetShops<T>() where T : ShopBase
// {
// HttpResult result = _shopApi.GetShops();
// if (result.StatusCode == System.Net.HttpStatusCode.OK)
// {
// StringBuilder sb = new StringBuilder();
// sb.Append("[");
// Regex regShopList = new Regex("<shop([^>]+?)>");
// 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("<shop '", "{\"");
// value = value.Replace("'>", "\"}");
// value = value.Replace("':'", "\":\"");
// value = value.Replace("' '", "\",\"");
// if (index > 0)
// {
// sb.Append(",");
// }
// sb.Append(value);
// index++;
// }
// sb.Append("]");
// List<T> list = JsonConvert.DeserializeObject<List<T>>(sb.ToString());
// list.RemoveAll(a => string.IsNullOrEmpty(a.Name));
// return list;
// }
// }
// return new List<T>();
// }
// public string GetShopCookie(List<ShopBase> shops)
// {
// HttpResult result = _shopApi.GetShopsCookie(shops);
// if (result.StatusCode == System.Net.HttpStatusCode.OK)
// {
// MatchCollection matchs = Regex.Matches(result.Html, @"<shop id=""([^""]+?)"">([\w\W]+?)</shop>");
// 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;
// }
// /// <summary>
// /// 检测商铺登录状态
// /// </summary>
// 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);
// }
// /// <summary>
// /// 获取值
// /// </summary>
// /// <param name="html"></param>
// /// <param name="reg"></param>
// /// <returns></returns>
// 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;
// }
//}
}