初始化
This commit is contained in:
13
Common/Common.csproj
Normal file
13
Common/Common.csproj
Normal file
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="RestSharp" Version="112.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
75
Common/Entity.cs
Normal file
75
Common/Entity.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Common
|
||||
{
|
||||
public record TempResult
|
||||
{
|
||||
public string resDesc { get; set; }
|
||||
public TempData Result { get; set; }
|
||||
|
||||
}
|
||||
public record TempData
|
||||
{
|
||||
public int RoomTypeId { get; set; }
|
||||
public string RoomTypeName { get; set; }
|
||||
}
|
||||
|
||||
public class LoginData
|
||||
{
|
||||
public string username { get; set; }
|
||||
public string password { get; set; }
|
||||
}
|
||||
public class DeviceInfo
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string ModalAddress { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string EnglistName { get; set; }
|
||||
public string TWName { get; set; }
|
||||
public string TypeName { get; set; }
|
||||
}
|
||||
public record DeviceStatusData
|
||||
{
|
||||
public string? DeviceName { get; set; }
|
||||
public string? DeviceType { get; set; }
|
||||
public string? Address { get; set; }
|
||||
public ushort Status { get; set; }
|
||||
}
|
||||
public class HotelInfo
|
||||
{
|
||||
public string code { get; set; }
|
||||
}
|
||||
public class WebAPIData
|
||||
{
|
||||
public bool IsSuccess { get; set; }
|
||||
public List<JieFang> Result { get; set; }
|
||||
}
|
||||
public class JieFang
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string Code { get; set; }
|
||||
public string Name { get; set; }
|
||||
public List<DeviceInfo> Modals { get; set; }
|
||||
}
|
||||
|
||||
public class Block_NameList
|
||||
{
|
||||
public string? HotelCode { get; set; }
|
||||
public string? Human { get; set; }
|
||||
public List<string>? HostNumberList { get; set; }
|
||||
}
|
||||
//public class ReturnInfo
|
||||
//{
|
||||
// public bool isok { set; get; } // 是否成功,true成功
|
||||
// public string message { set; get; } // 传递接口信息,or报错信息
|
||||
// public int status { set; get; } // 服务器报错信息,正确为200,错误404/500等
|
||||
// public object response { set; get; } // 获取到的信息本体,若报错则为null
|
||||
//}
|
||||
|
||||
|
||||
|
||||
}
|
||||
100
Common/Http.cs
Normal file
100
Common/Http.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using RestSharp;
|
||||
|
||||
namespace Common
|
||||
{
|
||||
public class ReturnInfo
|
||||
{
|
||||
public bool isok { set; get; } // 是否成功,true成功
|
||||
public string message { set; get; } // 传递接口信息,or报错信息
|
||||
public int status { set; get; } // 服务器报错信息,正确为200,错误404/500等
|
||||
public object response { set; get; } // 获取到的信息本体,若报错则为null
|
||||
}
|
||||
public class Http
|
||||
{
|
||||
public static string BaseUrl = "https://www.boonlive-rcu.com";
|
||||
static public async Task<ReturnInfo> HttpPostSendData(Object data, string url)
|
||||
{
|
||||
ReturnInfo r = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
var options = new RestClientOptions(BaseUrl);
|
||||
var client = new RestClient(options);
|
||||
|
||||
string str = System.Text.Json.JsonSerializer.Serialize(data);
|
||||
|
||||
var request = new RestRequest(url);
|
||||
request.AddJsonBody(str);
|
||||
RestResponse response = await client.PostAsync(request);
|
||||
string? str1 = response.Content;
|
||||
r.isok = true;
|
||||
r.response = str1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
r.isok = false;
|
||||
r.response = ex.Message;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
static public async Task<ReturnInfo> HttpPostFormSendData(Dictionary<string, string> data, string url)
|
||||
{
|
||||
ReturnInfo r = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
var options = new RestClientOptions(BaseUrl);
|
||||
var client = new RestClient(options);
|
||||
|
||||
string str = System.Text.Json.JsonSerializer.Serialize(data);
|
||||
var request = new RestRequest(url);
|
||||
foreach (var item in data)
|
||||
{
|
||||
request.AddParameter(item.Key, item.Value);
|
||||
}
|
||||
|
||||
RestResponse response = await client.PostAsync(request);
|
||||
string? str1 = response.Content;
|
||||
r.isok = true;
|
||||
r.response = str1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
r.isok = false;
|
||||
r.response = ex.Message;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
static public async Task<ReturnInfo> HttpGetSendData(Object data, string url)
|
||||
{
|
||||
ReturnInfo r = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
var options = new RestClientOptions(BaseUrl);
|
||||
var client = new RestClient(options);
|
||||
|
||||
string str = System.Text.Json.JsonSerializer.Serialize(data);
|
||||
|
||||
var request = new RestRequest(url);
|
||||
request.AddParameter("jsonData", str);
|
||||
RestResponse response = await client.GetAsync(request);
|
||||
string? str1 = response.Content;
|
||||
r.isok = true;
|
||||
r.response = str1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
r.isok = false;
|
||||
r.response = ex.Message;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user