123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- using RestSharp;
- using Fw.Utility.UnifyResponse;
- using System.Text;
- using System.Security.Cryptography;
- using Hotline.Share.Dtos.Quality;
- using Hotline.Ai.Quality;
- namespace Hotline.Ai.XingTang
- {
- public class AiQualityService : IAiQualityService
- {
- private readonly RestClient _client;
- private readonly string _baseUrl;
- public AiQualityService(string baseUrl)
- {
- _client = new RestClient();
- _baseUrl = baseUrl;
- }
- public async Task CreateAiOrderQualityTask(
- string id,
- string audioFile,
- string fromNo,
- DateTime? callStartTime,
- string viteRecordPrefix,
- string ywlxString,
- CancellationToken cancellationToken)
- {
- }
- public async Task<string> CreateAiOrderQualityTask(string filename, CancellationToken cancellationToken)
- {
- var url = _baseUrl + "/offlinerecog?filename=" + filename;
- var baseUrl = new Uri(url);
- return await ExecuteAsync(baseUrl.ToString(), Method.Get, "", cancellationToken);
- }
- public async Task<ApiResponse<TResponse>> ExecuteAsync<TRequest, TResponse>(string path, Method httpMethod,
- TRequest request, CancellationToken cancellationToken)
- where TRequest : class
- {
- var req = new RestRequest(path, httpMethod);
- if (httpMethod is Method.Get)
- {
- req.AddObject(request);
- }
- else
- {
- req.AddJsonBody(request);
- }
- try
- {
- var response = await _client.ExecuteAsync<ApiResponse<TResponse>>(req, cancellationToken);
- return response.Data;
- }
- catch (Exception e)
- {
- throw new HttpRequestException($"智能质检平台错误,Error: {e.Message}");
- }
- }
- public async Task<string> ExecuteAsync<TRequest>(string path, Method httpMethod, TRequest request,
- CancellationToken cancellationToken)
- where TRequest : class
- {
- var req = new RestRequest(path, httpMethod);
- req.Timeout = new TimeSpan(0,30,0);
- try
- {
- var response = await _client.ExecuteAsync<ApiResponse>(req, cancellationToken);
- return response.Content;
- }
- catch (Exception e)
- {
- throw new HttpRequestException($"智能质检平台错误,Error: {e.Message}");
- }
- }
- /// <summary>
- /// MD5加密
- /// </summary>
- /// <param name="input">需要加密的字符串</param>
- /// <returns></returns>
- private static string MD5Encrypt(string? input)
- {
- using var md5 = MD5.Create();
- var t = md5.ComputeHash(Encoding.UTF8.GetBytes(input));
- var sb = new StringBuilder(32);
- for (var i = 0; i < t.Length; i++)
- sb.Append(t[i].ToString("x").PadLeft(2, '0'));
- return sb.ToString();
- }
- private static string Base64En(string? model)
- {
- var bytes = Encoding.UTF8.GetBytes(model);
- return Convert.ToBase64String(bytes);
- }
- }
- }
|