增加Prism 框架
This commit is contained in:
1 parent
2cd6b8db86
commit
726eb6de16
99 files changed
+12527
No files matched your search
@@ -0,0 +1,90 @@
|
||||
using LittleCow.Core.Helpers;
|
||||
using LittleCow.Server.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Trade.Client.Helpers;
|
||||
using Trade.Client.HttpExtension;
|
||||
|
||||
namespace Trade.Client.APIs
|
||||
{
|
||||
/// <summary>
|
||||
/// 公共基础数据Api
|
||||
/// </summary>
|
||||
internal class CommonApi : ServerReqeustBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取服务器时间校准时间
|
||||
/// </summary>
|
||||
public DateTime GetServerTime()
|
||||
{
|
||||
HttpResult result = ServerRequest(new ServerHttpItem { URL = $"{_config.Host}/time.php", IsSign = true });
|
||||
if (result.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
if (DateTime.TryParse(result.Html, out DateTime dt))
|
||||
{
|
||||
return dt;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("连接服务器失败,将导致无法登录");
|
||||
}
|
||||
|
||||
}
|
||||
return DateTime.Now;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取签名验证配置
|
||||
/// </summary>
|
||||
public string GetAuthConfig()
|
||||
{
|
||||
ServerHttpItem item = new ServerHttpItem();
|
||||
item.URL = $"{_config.Host}?obj=api/config&act=auth_config";
|
||||
HttpResult result = ServerRequest(item);
|
||||
if (result.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
return result.Html;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取服务器图片缓存
|
||||
/// </summary>
|
||||
/// <param name="imgUrl"></param>
|
||||
/// <returns></returns>
|
||||
public HttpResult GetImageCache(string imgUrl)
|
||||
{
|
||||
long id = 123;//BaseClass.GetLong(imgUrl);
|
||||
ServerHttpItem item = new ServerHttpItem();
|
||||
item.Method = MethodType.Post;
|
||||
item.URL = BuildObjString("add_img");
|
||||
item.Postdata = "act=get&table=" + Math.Abs(id % 1024) + "&id=" + id;
|
||||
item.SignUser();
|
||||
return ServerRequest(item);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存服务集群负载比例
|
||||
/// </summary>
|
||||
public string GetCacheServerRatio()
|
||||
{
|
||||
|
||||
ServerHttpItem item = new ServerHttpItem();
|
||||
item.URL = BuildObjString("config&act=cache_service_mode");
|
||||
item.Method = MethodType.Post;
|
||||
item.SignUser();
|
||||
HttpResult result = ServerRequest(item);
|
||||
if (result.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
return result.Html;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,94 @@
|
||||
using LittleCow.Core.Autofac;
|
||||
using LittleCow.Core.DependencyInjection;
|
||||
using LittleCow.Core.Helpers;
|
||||
using LittleCow.Core.Logger;
|
||||
using LittleCow.Server.Commons;
|
||||
using LittleCow.Server.Extensions;
|
||||
using MAX.Core.DependencyInjection;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Trade.Client;
|
||||
using Trade.Client.Helpers;
|
||||
|
||||
namespace Trade.Client.HttpExtension
|
||||
{
|
||||
public class ServerReqeustBase : ITransientDependency
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 日志
|
||||
/// </summary>
|
||||
[Autowired]
|
||||
protected ILoggerFacade _log { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 服务器配置
|
||||
/// </summary>
|
||||
[Autowired]
|
||||
protected IServerConfig _config { get; set; }
|
||||
|
||||
public ServerReqeustBase()
|
||||
{
|
||||
}
|
||||
|
||||
public string BuildObjString(string urlpath)
|
||||
{
|
||||
return _config.Host + "?" + _config.ObjUrl + urlpath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 服务器请求
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
public HttpResult ServerRequest(ServerHttpItem item)
|
||||
{
|
||||
#if RELEASE
|
||||
item.WebProxy = null;
|
||||
#endif
|
||||
if (!item.URL.StartsWith("http"))
|
||||
{
|
||||
item.URL += _config.Host + item.URL;
|
||||
}
|
||||
item.Encoding = Encoding.UTF8;
|
||||
if (item.Method == MethodType.Post)
|
||||
{
|
||||
item.ContentType = "application/x-www-form-urlencoded";
|
||||
}
|
||||
if (!item.IsSign)
|
||||
{
|
||||
if (item.Shop != null)
|
||||
item.SignUser(item.Shop.Id, item.Shop.MainAccount);
|
||||
else
|
||||
item.Sign();
|
||||
}
|
||||
HttpResult result = HttpHelper.Request(item);
|
||||
if (result.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(result.Html))
|
||||
{
|
||||
if (result.Html[0] == 65279)
|
||||
{
|
||||
result.Html = result.Html.Remove(0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<HttpResult> ServerAsyncRequest(ServerHttpItem item)
|
||||
{
|
||||
return await Task.FromResult(ServerRequest(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace Trade.Client
|
||||
{
|
||||
public interface IServerConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// 服务器地址
|
||||
/// </summary>
|
||||
string Host { get; }
|
||||
/// <summary>
|
||||
/// 项目地址
|
||||
/// </summary>
|
||||
string ObjUrl { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Trade.Client
|
||||
{
|
||||
internal class ServerConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// 服务器时间差
|
||||
/// </summary>
|
||||
public static int TimeDifferent { get; internal set; }
|
||||
/// <summary>
|
||||
/// 是否使用新签名算法
|
||||
/// </summary>
|
||||
public static bool IsNewSignatureAuth { get; internal set; } = true;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using MAX.Core;
|
||||
using MAX.Core.DependencyInjection;
|
||||
using MAX.Core.Infrastructure;
|
||||
using RestSharp;
|
||||
|
||||
namespace Trade.Client;
|
||||
|
||||
public class Startup : IStartup
|
||||
{
|
||||
public Startup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public int Priority => IntPriority.Normal;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Register(IServiceRegistrar registrar)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
async Task ss()
|
||||
{
|
||||
// 1. 创建客户端
|
||||
var client = new RestClient("https://api.example.com");
|
||||
|
||||
// 2. 创建请求,并指定资源路径
|
||||
var request = new RestRequest("users/{id}", Method.GET);
|
||||
|
||||
// 3. 添加请求参数
|
||||
// 添加 URL 路径参数,替换 {id}
|
||||
request.AddUrlSegment("id", "123");
|
||||
// 添加 URL 查询参数
|
||||
request.AddQueryParameter("include", "details");
|
||||
// 添加请求头
|
||||
request.AddHeader("Authorization", "Bearer your-token");
|
||||
request.Method = Method.POST;
|
||||
|
||||
// 4. 执行请求,并获取响应
|
||||
// 这里 Execute 是同步方法,如果是异步场景也可以用 ExecuteAsync
|
||||
IRestResponse response = await client.ExecuteAsync(request);
|
||||
|
||||
// 5. 处理响应
|
||||
if (response.IsSuccessful)
|
||||
{
|
||||
// 响应内容可以通过 response.Content 获取
|
||||
var content = response.Content;
|
||||
// 或者通过 RestSharp 自带的序列化器直接反序列化成对象
|
||||
// var user = client.Execute<User>(request).Data;
|
||||
Console.WriteLine(content);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"请求失败: {response.StatusCode}, {response.ErrorMessage}");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="RestSharp" Version="106.15.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MAX.Core\MAX.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in new issue
Block a user