mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-12-29 18:04:42 +08:00
refactor: clean code
This commit is contained in:
@@ -43,7 +43,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV2
|
||||
{
|
||||
string plainXml = Utilities.AESUtility.DecryptWithECB(
|
||||
encodingKey: Convert.ToBase64String(Encoding.UTF8.GetBytes(key)),
|
||||
encodingCipherText: callback.EncryptedRequestInfo
|
||||
encodingCipherText: callback.EncryptedRequestInfo!
|
||||
);
|
||||
plainJson = Utilities.XmlUtility.ConvertToJson(plainXml);
|
||||
}
|
||||
|
||||
@@ -29,14 +29,14 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV2
|
||||
request.FileName = Guid.NewGuid().ToString("N").ToLower() + ".jpg";
|
||||
|
||||
if (request.FileHash == null)
|
||||
request.FileHash = Utilities.MD5Utility.Hash(request.FileBytes).ToLower();
|
||||
request.FileHash = BitConverter.ToString(Utilities.MD5Utility.Hash(request.FileBytes ?? Array.Empty<byte>())).Replace("-", "").ToLower();
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Post, "secapi", "mch", "uploadmedia");
|
||||
|
||||
string boundary = "--BOUNDARY--" + DateTimeOffset.Now.Ticks.ToString("x");
|
||||
string sign = Utilities.RequestSigner.Sign(new Dictionary<string, string?>() { { "mch_id", client.Credentials.MerchantId }, { "media_hash", request.FileHash } }, client.Credentials.MerchantSecret, Constants.SignTypes.MD5);
|
||||
using var fileContent = new ByteArrayContent(request.FileBytes);
|
||||
using var fileContent = new ByteArrayContent(request.FileBytes ?? Array.Empty<byte>());
|
||||
using var httpContent = new MultipartFormDataContent(boundary);
|
||||
httpContent.Add(fileContent, "\"media\"", $"\"{HttpUtility.UrlEncode(request.FileName)}\"");
|
||||
httpContent.Add(new StringContent(client.Credentials.MerchantId, Encoding.UTF8), $"\"mch_id\"");
|
||||
@@ -44,6 +44,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV2
|
||||
httpContent.Add(new StringContent(sign, Encoding.UTF8), $"\"sign\"");
|
||||
httpContent.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data; boundary=" + boundary);
|
||||
fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("image/jpeg");
|
||||
fileContent.Headers.ContentLength = request.FileBytes?.Length;
|
||||
|
||||
return await client.SendRequestAsync<Models.UploadMerchantMediaResponse>(flurlReq, httpContent: httpContent, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user