mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-12-22 03:19:55 +08:00
refactor: clean code
This commit is contained in:
@@ -110,7 +110,7 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Post, "assetsupload", client.Credentials.Token!);
|
||||
|
||||
using var fileContent = new ByteArrayContent(request.FileBytes ?? new byte[0]);
|
||||
using var fileContent = new ByteArrayContent(request.FileBytes ?? Array.Empty<byte>());
|
||||
using var paramContent = new StringContent(
|
||||
Utilities.WxBizMsgCryptor.AESEncrypt(
|
||||
plainText: Utilities.XmlUtility.Serialize(request),
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Post, "v1", "file", "upload");
|
||||
|
||||
using var fileContent = new ByteArrayContent(request.FileBytes ?? new byte[0]);
|
||||
using var fileContent = new ByteArrayContent(request.FileBytes ?? Array.Empty<byte>());
|
||||
using var httpContent = new MultipartFormDataContent();
|
||||
httpContent.Add(fileContent, "\"file\"", $"\"{HttpUtility.UrlEncode(request.FileName)}\"");
|
||||
fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse(request.FileContentType);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Xml.Serialization;
|
||||
using System;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models.Platform
|
||||
{
|
||||
@@ -18,7 +19,7 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models.Platform
|
||||
/// 获取或设置文件字节数组。
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public byte[] FileBytes { get; set; } = new byte[0];
|
||||
public byte[] FileBytes { get; set; } = Array.Empty<byte>();
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置文件名。如果不指定将由系统自动生成。
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models.ThirdParty
|
||||
using System;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models.ThirdParty
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /v1/file/upload 接口的请求。</para>
|
||||
@@ -10,7 +12,7 @@
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public byte[] FileBytes { get; set; } = new byte[0];
|
||||
public byte[] FileBytes { get; set; } = Array.Empty<byte>();
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置文件名。如果不指定将由系统自动生成。
|
||||
|
||||
@@ -13,14 +13,13 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Utilities
|
||||
/// 获取 SHA-1 信息摘要。
|
||||
/// </summary>
|
||||
/// <param name="bytes">信息字节数组。</param>
|
||||
/// <returns>信息摘要。</returns>
|
||||
public static string Hash(byte[] bytes)
|
||||
/// <returns>信息摘要字节数组。</returns>
|
||||
public static byte[] Hash(byte[] bytes)
|
||||
{
|
||||
if (bytes == null) throw new ArgumentNullException(nameof(bytes));
|
||||
|
||||
using SHA1 sha = SHA1.Create();
|
||||
byte[] hashBytes = sha.ComputeHash(bytes);
|
||||
return BitConverter.ToString(hashBytes).Replace("-", "");
|
||||
return sha.ComputeHash(bytes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -32,8 +31,9 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Utilities
|
||||
{
|
||||
if (message == null) throw new ArgumentNullException(nameof(message));
|
||||
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(message);
|
||||
return Hash(bytes);
|
||||
byte[] msgBytes = Encoding.UTF8.GetBytes(message);
|
||||
byte[] hashBytes = Hash(msgBytes);
|
||||
return BitConverter.ToString(hashBytes).Replace("-", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user