SACenter/SA.Domain.XFYun/XFYunEntity/XFYunRequest.cs

68 lines
2.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using SA.Core;
using SA.Core.Init;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
namespace SA.Domain.XFYun.XFYunEntity
{
/// <summary>
/// 讯飞云请求
/// </summary>
/// <typeparam name="TParams"></typeparam>
public class XFYunRequest<TParams>
where TParams : class
{
/// <summary>
/// 构造函数
/// </summary>
/// <param name="appId"></param>
/// <param name="groupId"></param>
/// <param name="key"></param>
/// <param name="param"></param>
public XFYunRequest(string? appId, string? key, string? groupId, TParams param)
{
var configs = InitConfiguration.GetSection("XFYunConfigs").Get<List<XFYunConfig>>();
var config = configs.FirstOrDefault(x => x.AppId == appId);
if (config == null) LogHelper.Error($"AppId: {appId},配置不存在,请检查配置");
var apiConfig = XFYunApiConfig.GetApiConfig(key ?? "");
Url = apiConfig?.Url;
GroupId = groupId;
Params = param;
ParamPosition = apiConfig?.ParamPosition;
ServiceType = apiConfig?.ServiceType;
ParamType = apiConfig?.ParamType;
Config = config;
}
/// <summary>
/// 讯飞云API的请求地址
/// </summary>
public string? Url { get; }
/// <summary>
/// 讯飞云API的应用配置此参数为可选不传该参数时默认读取后端服务配置文件
/// </summary>
public XFYunConfig? Config { get; }
/// <summary>
/// 接口分组ID在讯飞云管理平台上获取
/// </summary>
public string? GroupId { get; }
public string? ParamPosition { get; }
public string? ServiceType { get; }
public string? ParamType { get; }
/// <summary>
/// 讯飞云API的调用参数具体参数字段请查看讯飞云API文档
/// </summary>
public TParams Params { get; }
}
}