using Common.DTOS;
using NetTaste;
using RestSharp;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Service
{
public class APIService
{
private static string Token = "Bearer u-cVaGe.hv160U5.zqxeyRKx11ifIR04iPjoayYQC00EXF";
#region 表处理
///
/// 初始化多维表格
///
/// 表格名称
public static FeishuResponse InitForm(string FormName)
{
try
{
var client = new RestClient("https://open.feishu.cn/open-apis/bitable/v1/apps");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", Token);
request.AddParameter("application/json", ParameterType.RequestBody);
request.AddJsonBody(new
{
folder_token = "",
name = FormName
});
IRestResponse response = client.Execute(request);
return Newtonsoft.Json.JsonConvert.DeserializeObject>(response.Content);
}
catch (Exception ex)
{
throw;
}
}
///
/// 创建表
///
/// 多维表格ID
/// 表名称
public static FeishuResponse AddTable(string FormID, string TableName)
{
try
{
var client = new RestClient($"https://open.feishu.cn/open-apis/bitable/v1/apps/{FormID}/tables");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", Token);
request.AddJsonBody(new
{
table = new
{
default_view_name = "默认的表格视图",
name = TableName,
fields = new object[]
{
new
{
field_name = "索引字段",
type = 1
},
new
{
field_name = "单选",
type = 3,
ui_type = "SingleSelect",
property = new
{
options = new[]
{
new { color = 0, name = "Enabled" },
new { color = 1, name = "Disabled" },
new { color = 2, name = "Draft" }
}
}
}
}
}
});
request.AddParameter("application/json", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
return Newtonsoft.Json.JsonConvert.DeserializeObject>(response.Content);
}
catch (Exception ex)
{
throw;
}
}
///
/// 删除表
///
/// 多维表格ID
/// 表ID
public static FeishuResponse