fix: 配置缺少
This commit is contained in:
@@ -29,13 +29,11 @@ public class AliyunClient : IAliyunClient
|
|||||||
{
|
{
|
||||||
_httpClientFactory = httpClientFactory;
|
_httpClientFactory = httpClientFactory;
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
|
|
||||||
|
_accessKeyId = "LTAI5tAqyWKcBcSvzpc1ZM72";
|
||||||
|
_accessKeySecret = "YZMSqsmMGlGZuHw5WU2tqt0mmIBX6h";
|
||||||
}
|
}
|
||||||
|
|
||||||
public AliyunClient(string accessKeyId, string accessKeySecret)
|
|
||||||
{
|
|
||||||
_accessKeyId = accessKeyId ?? "LTAI5tAqyWKcBcSvzpc1ZM72";
|
|
||||||
_accessKeySecret = accessKeySecret ?? "YZMSqsmMGlGZuHw5WU2tqt0mmIBX6h";
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 使用 Base64 图片进行三要素核验
|
/// 使用 Base64 图片进行三要素核验
|
||||||
@@ -46,9 +44,6 @@ public class AliyunClient : IAliyunClient
|
|||||||
string faceBase64,
|
string faceBase64,
|
||||||
string crop = "F")
|
string crop = "F")
|
||||||
{
|
{
|
||||||
var accessKeyId = _accessKeyId ?? GetRequiredConfig("AliyunOptions:AccessKeyId", "Aliyun:AccessKeyId");
|
|
||||||
var accessKeySecret = _accessKeySecret ?? GetRequiredConfig("AliyunOptions:AccessKeySecret", "Aliyun:AccessKeySecret");
|
|
||||||
|
|
||||||
if (faceBase64.Contains(","))
|
if (faceBase64.Contains(","))
|
||||||
{
|
{
|
||||||
faceBase64 = faceBase64[(faceBase64.IndexOf(',') + 1)..];
|
faceBase64 = faceBase64[(faceBase64.IndexOf(',') + 1)..];
|
||||||
@@ -59,7 +54,7 @@ public class AliyunClient : IAliyunClient
|
|||||||
{ "Action", "Id3MetaVerify" },
|
{ "Action", "Id3MetaVerify" },
|
||||||
{ "Format", "JSON" },
|
{ "Format", "JSON" },
|
||||||
{ "Version", ApiVersion },
|
{ "Version", ApiVersion },
|
||||||
{ "AccessKeyId", accessKeyId },
|
{ "AccessKeyId", _accessKeyId },
|
||||||
{ "SignatureMethod", "HMAC-SHA1" },
|
{ "SignatureMethod", "HMAC-SHA1" },
|
||||||
{ "SignatureVersion", "1.0" },
|
{ "SignatureVersion", "1.0" },
|
||||||
{ "SignatureNonce", Guid.NewGuid().ToString("N") },
|
{ "SignatureNonce", Guid.NewGuid().ToString("N") },
|
||||||
@@ -71,7 +66,7 @@ public class AliyunClient : IAliyunClient
|
|||||||
{ "Crop", crop }
|
{ "Crop", crop }
|
||||||
};
|
};
|
||||||
|
|
||||||
var signature = ComputeSignature(parameters, "POST", accessKeySecret);
|
var signature = ComputeSignature(parameters, "POST", _accessKeySecret);
|
||||||
var url = $"https://{Endpoint}/?Signature={PercentEncode(signature)}";
|
var url = $"https://{Endpoint}/?Signature={PercentEncode(signature)}";
|
||||||
var bodyString = BuildBodyString(parameters);
|
var bodyString = BuildBodyString(parameters);
|
||||||
|
|
||||||
@@ -85,20 +80,6 @@ public class AliyunClient : IAliyunClient
|
|||||||
return ParseResponse(rawResponse);
|
return ParseResponse(rawResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetRequiredConfig(params string[] keys)
|
|
||||||
{
|
|
||||||
foreach (var key in keys)
|
|
||||||
{
|
|
||||||
var value = _configuration.GetSection(key).Value;
|
|
||||||
if (!string.IsNullOrWhiteSpace(value))
|
|
||||||
{
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new UserFriendlyException($"阿里云配置缺失:{string.Join("或", keys)}");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static AliyunId3MetaVerifyResponse ParseResponse(string rawResponse)
|
private static AliyunId3MetaVerifyResponse ParseResponse(string rawResponse)
|
||||||
{
|
{
|
||||||
var result = new AliyunId3MetaVerifyResponse
|
var result = new AliyunId3MetaVerifyResponse
|
||||||
|
|||||||
Reference in New Issue
Block a user