Browse Source

Update aliyun SMS error code

pull/127/head
cKey 5 years ago
parent
commit
053fcfec0b
  1. 28
      aspnet-core/modules/common/LINGYUN.Abp.Sms.Aliyun/LINYUN/Abp/Sms/Aliyun/AliyunSmsException.cs
  2. 57
      aspnet-core/modules/common/LINGYUN.Abp.Sms.Aliyun/LINYUN/Abp/Sms/Aliyun/AliyunSmsResponse.cs
  3. 12
      aspnet-core/modules/common/LINGYUN.Abp.Sms.Aliyun/LINYUN/Abp/Sms/Aliyun/AliyunSmsSender.cs
  4. 24
      aspnet-core/modules/common/LINGYUN.Abp.Sms.Aliyun/LINYUN/Abp/Sms/Aliyun/Localization/Resources/en.json
  5. 24
      aspnet-core/modules/common/LINGYUN.Abp.Sms.Aliyun/LINYUN/Abp/Sms/Aliyun/Localization/Resources/zh-Hans.json

28
aspnet-core/modules/common/LINGYUN.Abp.Sms.Aliyun/LINYUN/Abp/Sms/Aliyun/AliyunSmsException.cs

@ -0,0 +1,28 @@
using Microsoft.Extensions.Logging;
using Volo.Abp;
using Volo.Abp.ExceptionHandling;
using Volo.Abp.Localization;
using Volo.Abp.Logging;
namespace LINYUN.Abp.Sms.Aliyun
{
public class AliyunSmsException : AbpException, IHasErrorCode, ILocalizeErrorMessage, IHasLogLevel
{
public AliyunSmsException(string code, string message)
:base(message)
{
Code = code;
LogLevel = LogLevel.Warning;
}
public LogLevel LogLevel { get; set; }
public string Code { get; }
public string LocalizeMessage(LocalizationContext context)
{
return AliyunSmsResponse.GetErrorMessage(Code, Message)
.Localize(context.LocalizerFactory);
}
}
}

57
aspnet-core/modules/common/LINGYUN.Abp.Sms.Aliyun/LINYUN/Abp/Sms/Aliyun/AliyunSmsResponse.cs

@ -16,11 +16,60 @@ namespace LINYUN.Abp.Sms.Aliyun
return "ok".Equals(Code, StringComparison.CurrentCultureIgnoreCase); return "ok".Equals(Code, StringComparison.CurrentCultureIgnoreCase);
} }
public ILocalizableString GetErrorMessage() public static ILocalizableString GetErrorMessage(string code, string message)
{ {
Check.NotNullOrWhiteSpace(Code, nameof(Code)); // TODO: 把前缀写入本地化文档里面?
switch (Code) Check.NotNullOrWhiteSpace(code, nameof(code));
switch (code)
{ {
case "isv.SMS_SIGNATURE_SCENE_ILLEGAL":
return LocalizableString.Create<AliyunSmsResource>("SMS_SIGNATURE_SCENE_ILLEGAL");
case "isv.DENY_IP_RANGE":
return LocalizableString.Create<AliyunSmsResource>("DENY_IP_RANGE");
case "isv.MOBILE_COUNT_OVER_LIMIT":
return LocalizableString.Create<AliyunSmsResource>("MOBILE_COUNT_OVER_LIMIT");
case "isv.BUSINESS_LIMIT_CONTROL":
return LocalizableString.Create<AliyunSmsResource>("BUSINESS_LIMIT_CONTROL");
case "SignatureDoesNotMatch":
return LocalizableString.Create<AliyunSmsResource>("SignatureDoesNotMatch");
case "InvalidTimeStamp.Expired":
return LocalizableString.Create<AliyunSmsResource>("InvalidTimeStampExpired");
case "SignatureNonceUsed":
return LocalizableString.Create<AliyunSmsResource>("SignatureNonceUsed");
case "InvalidVersion":
return LocalizableString.Create<AliyunSmsResource>("InvalidVersion");
case "InvalidAction.NotFound":
return LocalizableString.Create<AliyunSmsResource>("InvalidActionNotFound");
case "isv.SIGN_COUNT_OVER_LIMIT":
return LocalizableString.Create<AliyunSmsResource>("SIGN_COUNT_OVER_LIMIT");
case "isv.TEMPLATE_COUNT_OVER_LIMIT":
return LocalizableString.Create<AliyunSmsResource>("TEMPLATE_COUNT_OVER_LIMIT");
case "isv.SIGN_NAME_ILLEGAL":
return LocalizableString.Create<AliyunSmsResource>("SIGN_NAME_ILLEGAL");
case "isv.SIGN_FILE_LIMIT":
return LocalizableString.Create<AliyunSmsResource>("SIGN_FILE_LIMIT");
case "isv.SIGN_OVER_LIMIT":
return LocalizableString.Create<AliyunSmsResource>("SIGN_OVER_LIMIT");
case "isv.TEMPLATE_OVER_LIMIT":
return LocalizableString.Create<AliyunSmsResource>("TEMPLATE_OVER_LIMIT");
case "SIGNATURE_BLACKLIST":
return LocalizableString.Create<AliyunSmsResource>("SIGNATURE_BLACKLIST");
case "isv.SHORTURL_OVER_LIMIT":
return LocalizableString.Create<AliyunSmsResource>("SHORTURL_OVER_LIMIT");
case "isv.NO_AVAILABLE_SHORT_URL":
return LocalizableString.Create<AliyunSmsResource>("NO_AVAILABLE_SHORT_URL");
case "isv.SHORTURL_NAME_ILLEGAL":
return LocalizableString.Create<AliyunSmsResource>("SHORTURL_NAME_ILLEGAL");
case "isv.SOURCEURL_OVER_LIMIT":
return LocalizableString.Create<AliyunSmsResource>("SOURCEURL_OVER_LIMIT");
case "isv.SHORTURL_TIME_ILLEGAL":
return LocalizableString.Create<AliyunSmsResource>("SHORTURL_TIME_ILLEGAL");
case "isv.PHONENUMBERS_OVER_LIMIT":
return LocalizableString.Create<AliyunSmsResource>("PHONENUMBERS_OVER_LIMIT");
case "isv.SHORTURL_STILL_AVAILABLE":
return LocalizableString.Create<AliyunSmsResource>("SHORTURL_STILL_AVAILABLE");
case "isv.SHORTURL_NOT_FOUND":
return LocalizableString.Create<AliyunSmsResource>("SHORTURL_NOT_FOUND");
case "isv.SMS_TEMPLATE_ILLEGAL": case "isv.SMS_TEMPLATE_ILLEGAL":
return LocalizableString.Create<AliyunSmsResource>("SMS_TEMPLATE_ILLEGAL"); return LocalizableString.Create<AliyunSmsResource>("SMS_TEMPLATE_ILLEGAL");
case "isv.SMS_SIGNATURE_ILLEGAL": case "isv.SMS_SIGNATURE_ILLEGAL":
@ -68,7 +117,7 @@ namespace LINYUN.Abp.Sms.Aliyun
case "isv.TEMPLATE_PARAMS_ILLEGAL": case "isv.TEMPLATE_PARAMS_ILLEGAL":
return LocalizableString.Create<AliyunSmsResource>("TEMPLATE_PARAMS_ILLEGAL"); return LocalizableString.Create<AliyunSmsResource>("TEMPLATE_PARAMS_ILLEGAL");
default: default:
throw new AbpException("no error code define!"); throw new AbpException($"no error code: {code} define, message: {message}");
} }
} }

12
aspnet-core/modules/common/LINGYUN.Abp.Sms.Aliyun/LINYUN/Abp/Sms/Aliyun/AliyunSmsSender.cs

@ -65,15 +65,11 @@ namespace LINYUN.Abp.Sms.Aliyun
var aliyunResponse = JsonSerializer.Deserialize<AliyunSmsResponse>(responseContent); var aliyunResponse = JsonSerializer.Deserialize<AliyunSmsResponse>(responseContent);
if (!aliyunResponse.IsSuccess()) if (!aliyunResponse.IsSuccess())
{ {
var localizerFactory = ServiceProvider.GetRequiredService<IStringLocalizerFactory>();
var localizerError = aliyunResponse.GetErrorMessage().Localize(localizerFactory);
if (Options.VisableErrorToClient) if (Options.VisableErrorToClient)
{ {
var localizer = ServiceProvider.GetRequiredService<IStringLocalizer<AliyunSmsResource>>(); throw new AliyunSmsException(aliyunResponse.Code, aliyunResponse.Message);
localizerError = localizer["SendMessageFailed", localizerError];
throw new UserFriendlyException(localizerError);
} }
throw new AbpException($"Text message sending failed:{localizerError}!"); throw new AbpException($"Text message sending failed, code:{aliyunResponse.Code}, message:{aliyunResponse.Message}!");
} }
} }
catch(ServerException se) catch(ServerException se)
@ -121,7 +117,9 @@ namespace LINYUN.Abp.Sms.Aliyun
if (Environment.IsDevelopment()) if (Environment.IsDevelopment())
{ {
// check phone number length... // check phone number length...
Check.NotNullOrWhiteSpace(Options.DeveloperPhoneNumber, nameof(Options.DeveloperPhoneNumber), Check.NotNullOrWhiteSpace(
Options.DeveloperPhoneNumber,
nameof(Options.DeveloperPhoneNumber),
maxLength: 11, minLength: 11); maxLength: 11, minLength: 11);
request.AddQueryParameters("PhoneNumbers", Options.DeveloperPhoneNumber); request.AddQueryParameters("PhoneNumbers", Options.DeveloperPhoneNumber);
} }

24
aspnet-core/modules/common/LINGYUN.Abp.Sms.Aliyun/LINYUN/Abp/Sms/Aliyun/Localization/Resources/en.json

@ -2,6 +2,30 @@
"culture": "en", "culture": "en",
"texts": { "texts": {
"SendMessageFailed": "Text message sending failed:{0}", "SendMessageFailed": "Text message sending failed:{0}",
"SMS_SIGNATURE_SCENE_ILLEGAL": "Signature scene used by SMS is illegal",
"DENY_IP_RANGE": "Region where source IP address is disabled",
"MOBILE_COUNT_OVER_LIMIT": "Number of phone Numbers exceeds limit.",
"BUSINESS_LIMIT_CONTROL": "Business limit_limit, SMS frequency beyond limit.",
"SignatureDoesNotMatch": "Signature encryption error.",
"InvalidTimeStampExpired": "Please use GMT time: Timestamp error caused by time zone difference. The time the request was issued and the time the server received the request is not within 15 minutes.",
"SignatureNonceUsed": "Unique random number repetition, SignatureNonce is unique random number, used to prevent network replay attacks, use different random Numbers for different requests.",
"InvalidVersion": "Version error.Please confirm the Version of the interface. The Version of the SMS API is 2017-05-25.",
"InvalidActionNotFound": "Error interface name specified in parameter Action.Use the correct interface address and interface name in the parameter Action.",
"SIGN_COUNT_OVER_LIMIT": "The number of signatures requested in a natural day exceeds the limit.Arrange the number of signature requests for each day and reapply the next day.",
"TEMPLATE_COUNT_OVER_LIMIT": "The number of templates requested in a natural day exceeds the limit.Arrange the number of template applications for each day reasonably, and reapply the next day..",
"SIGN_NAME_ILLEGAL": "Signature name does not comply with the specification.See: https://help.aliyun.com/document_detail/108076.html?spm=a2c4g.11186623.2.12.610966fa9Q0QYe",
"SIGN_FILE_LIMIT": "Signature authentication material attachment size exceeds limit.",
"SIGN_OVER_LIMIT": "Number of signature characters exceeding the limit.",
"TEMPLATE_OVER_LIMIT": "Number of signature characters exceeding the limit.",
"SIGNATURE_BLACKLIST": "Signature blacklist, signature contains illegal information, please modify the signature",
"SHORTURL_OVER_LIMIT": "The number of short chains created in a day exceeds the limit",
"NO_AVAILABLE_SHORT_URL": "No valid short chain",
"SHORTURL_NAME_ILLEGAL": "Short chain name illegal",
"SOURCEURL_OVER_LIMIT": "Number of original link characters exceeds limit",
"SHORTURL_TIME_ILLEGAL": "Short chain is valid beyond the limit",
"PHONENUMBERS_OVER_LIMIT": "Upload more phone Numbers than the limit",
"SHORTURL_STILL_AVAILABLE": "Short links generated by the original link are still valid",
"SHORTURL_NOT_FOUND": "No short chain to remove",
"SMS_TEMPLATE_ILLEGAL": "template is not valid (not present or blocked)", "SMS_TEMPLATE_ILLEGAL": "template is not valid (not present or blocked)",
"SMS_SIGNATURE_ILLEGAL": "the signature is not valid (not present or blocked)", "SMS_SIGNATURE_ILLEGAL": "the signature is not valid (not present or blocked)",
"MOBILE_NUMBER_ILLEGAL": "invalid phone number ", "MOBILE_NUMBER_ILLEGAL": "invalid phone number ",

24
aspnet-core/modules/common/LINGYUN.Abp.Sms.Aliyun/LINYUN/Abp/Sms/Aliyun/Localization/Resources/zh-Hans.json

@ -2,6 +2,30 @@
"culture": "zh-Hans", "culture": "zh-Hans",
"texts": { "texts": {
"SendMessageFailed": "发送短信错误:{0}", "SendMessageFailed": "发送短信错误:{0}",
"SMS_SIGNATURE_SCENE_ILLEGAL": "短信所使用签名场景非法",
"DENY_IP_RANGE": "源IP地址所在的地区被禁用",
"MOBILE_COUNT_OVER_LIMIT": "手机号码数量超过限制",
"BUSINESS_LIMIT_CONTROL": "业务限流,短信发送频率超限。",
"SignatureDoesNotMatch": "签名(Signature)加密错误。",
"InvalidTimeStampExpired": "请使用GMT时间: 由于时区差异造成时间戳错误,发出请求的时间和服务器接收到请求的时间不在15分钟内。",
"SignatureNonceUsed": "唯一随机数重复,SignatureNonce为唯一随机数,用于防止网络重放攻击,不同请求请使用不同的随机数值。",
"InvalidVersion": "版本号(Version)错误。请确认接口的版本号,短信服务的API版本号(Version)为2017-05-25。",
"InvalidActionNotFound": "参数Action中指定的接口名错误。请在参数Action中使用正确的接口地址和接口名。",
"SIGN_COUNT_OVER_LIMIT": "一个自然日中申请签名数量超过限制。合理安排每天的签名申请数量,次日重新申请。",
"TEMPLATE_COUNT_OVER_LIMIT": "一个自然日中申请模板数量超过限制。合理安排每天的模板申请数量,次日重新申请。",
"SIGN_NAME_ILLEGAL": "签名名称不符合规范。See: https://help.aliyun.com/document_detail/108076.html?spm=a2c4g.11186623.2.12.610966fa9Q0QYe",
"SIGN_FILE_LIMIT": "签名认证材料附件大小超过限制。",
"SIGN_OVER_LIMIT": "签名字符数量超过限制。",
"TEMPLATE_OVER_LIMIT": "签名字符数量超过限制。",
"SIGNATURE_BLACKLIST": "签名黑名单,签名内容涉及违规信息,请修改签名内容",
"SHORTURL_OVER_LIMIT": "一天创建短链数量超过限制",
"NO_AVAILABLE_SHORT_URL": "无有效短链",
"SHORTURL_NAME_ILLEGAL": "短链名称非法",
"SOURCEURL_OVER_LIMIT": "原始链接字符数量超过限制",
"SHORTURL_TIME_ILLEGAL": "短链有效期期限超过限制",
"PHONENUMBERS_OVER_LIMIT": "上传手机号个数超过上限",
"SHORTURL_STILL_AVAILABLE": "原始链接生成的短链仍在有效期内",
"SHORTURL_NOT_FOUND": "没有可删除的短链",
"SMS_TEMPLATE_ILLEGAL": "模板不合法(不存在或被拉黑)", "SMS_TEMPLATE_ILLEGAL": "模板不合法(不存在或被拉黑)",
"SMS_SIGNATURE_ILLEGAL": "签名不合法(不存在或被拉黑)", "SMS_SIGNATURE_ILLEGAL": "签名不合法(不存在或被拉黑)",
"MOBILE_NUMBER_ILLEGAL": "无效的电话号码", "MOBILE_NUMBER_ILLEGAL": "无效的电话号码",

Loading…
Cancel
Save