mirror of
https://github.com/BeyondDimension/SteamTools.git
synced 2026-10-26 03:59:34 +08:00
add sms send
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
namespace System.Application.Columns
|
||||
{
|
||||
public interface IResult<T>
|
||||
{
|
||||
T Result { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
namespace System.Application.Models
|
||||
{
|
||||
public abstract class JsonModel
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
return Serializable.SJSON(this);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class JsonModel<T> : JsonModel where T : JsonModel<T>
|
||||
{
|
||||
public static T? Parse(string value)
|
||||
{
|
||||
return Serializable.DJSON<T>(value);
|
||||
}
|
||||
|
||||
public static bool TryParse(string value, out T? result)
|
||||
{
|
||||
try
|
||||
{
|
||||
result = Parse(value);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
using System.Application.Columns;
|
||||
using System.Common;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Properties;
|
||||
|
||||
namespace System.Application
|
||||
{
|
||||
public static class PhoneNumberHelper
|
||||
{
|
||||
const char HideChar = '*';
|
||||
public const int Length = 11;
|
||||
|
||||
/// <summary>
|
||||
/// 手机号码隐藏中间四位数字
|
||||
@@ -40,12 +41,14 @@ namespace System.Application
|
||||
/// <inheritdoc cref="ToStringHideMiddleFour(string?, char)"/>
|
||||
public static string ToStringHideMiddleFour(this IReadOnlyPhoneNumber phoneNumber, char hideChar = HideChar) => ToStringHideMiddleFour(phoneNumber.PhoneNumber, hideChar);
|
||||
|
||||
public const int ChineseMainlandPhoneNumberLength = 11;
|
||||
|
||||
/// <summary>
|
||||
/// 获取中国大陆地区11位手机号码
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static string? GetChineseMainlandPhoneNumber11(string? value)
|
||||
public static string? GetChineseMainlandPhoneNumber(string? value)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
@@ -72,5 +75,94 @@ namespace System.Application
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 中国大陆地区手机号码号段
|
||||
/// </summary>
|
||||
static class ChineseMainlandPhoneNumberSegment
|
||||
{
|
||||
/// <summary>
|
||||
/// 中国电信
|
||||
/// </summary>
|
||||
public static byte[] ChinaTelecom = { 133, 153, 177, 173, 180, 181, 189, 199, 149 };
|
||||
|
||||
/// <summary>
|
||||
/// 中国联通
|
||||
/// </summary>
|
||||
public static byte[] ChinaUnicom = { 130, 131, 132, 155, 156, 185, 186, 145, 176, 166, 146, 175 };
|
||||
|
||||
/// <summary>
|
||||
/// 中国移动
|
||||
/// </summary>
|
||||
public static byte[] ChinaMobile = { 139, 138, 137, 136, 135, 134, 147, 150, 151, 152, 157, 158, 159, 178, 182, 183, 184, 187, 188, 198, 148, 172 };
|
||||
|
||||
/// <summary>
|
||||
/// 虚拟运营商
|
||||
/// </summary>
|
||||
public static byte[] MobileVirtualNetwork = { 170, 171 };
|
||||
|
||||
public static byte[] Other = { 190, 197, 196, 192 };
|
||||
|
||||
static Lazy<byte[]> mSummary = new(() => new[]
|
||||
{
|
||||
ChinaTelecom,
|
||||
ChinaUnicom,
|
||||
ChinaMobile,
|
||||
MobileVirtualNetwork
|
||||
}.SelectMany(b => b).ToArray());
|
||||
|
||||
/// <summary>
|
||||
/// 总号段
|
||||
/// </summary>
|
||||
public static byte[] Summary => mSummary.Value;
|
||||
|
||||
/// <summary>
|
||||
/// 黑名单
|
||||
/// </summary>
|
||||
public static readonly byte[] Blacklist = new byte[] {
|
||||
148, 149, 146, // 物联网号段
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 中国大陆地区手机号码号段验证使用 黑名单(<see langword="true"/>) 或 白名单(<see langword="false"/>)
|
||||
/// </summary>
|
||||
public static bool ChineseMainlandPhoneNumberSegmentVerifyUseBlacklistOrWhitelist { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 中国大陆地区手机号码号段验证(通常仅服务端验证)
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="errMsg"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsChineseMainlandPhoneNumberSegment(string value,
|
||||
[NotNullWhen(false)] out string? errMsg)
|
||||
{
|
||||
var segment = value.Substring(0, 3).TryParseByte();
|
||||
if (!segment.HasValue)
|
||||
{
|
||||
errMsg = string.Format(SR.UnsupportedPhoneNumberSegment_, 0);
|
||||
return false;
|
||||
}
|
||||
if (ChineseMainlandPhoneNumberSegmentVerifyUseBlacklistOrWhitelist)
|
||||
{
|
||||
if (ChineseMainlandPhoneNumberSegment.Blacklist.Contains(segment.Value))
|
||||
{
|
||||
errMsg = string.Format(SR.UnsupportedPhoneNumberSegment_, segment ?? 0);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!ChineseMainlandPhoneNumberSegment.Summary.Contains(segment.Value))
|
||||
{
|
||||
errMsg = string.Format(SR.UnsupportedPhoneNumberSegment_, segment ?? 0);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
errMsg = null;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,12 +52,63 @@ namespace System
|
||||
|
||||
#region TryParse
|
||||
|
||||
/// <summary>
|
||||
/// 尝试将数字的字符串表示形式转换为它的等效 16 位有符号整数
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static short? TryParseInt16(this string value) => short.TryParse(value, out var temp) ? temp : null;
|
||||
|
||||
/// <summary>
|
||||
/// 尝试将数字的字符串表示形式转换为它的等效 16 位无符号整数
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static ushort? TryParseUInt16(this string value) => ushort.TryParse(value, out var temp) ? temp : null;
|
||||
|
||||
/// <summary>
|
||||
/// 尝试将数字的字符串表示形式转换为它的等效 32 位有符号整数
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static int? TryParseInt32(this string value) => int.TryParse(value, out var temp) ? temp as int? : null;
|
||||
public static int? TryParseInt32(this string value) => int.TryParse(value, out var temp) ? temp : null;
|
||||
|
||||
/// <summary>
|
||||
/// 尝试将数字的字符串表示形式转换为它的等效 32 位无符号整数
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static uint? TryParseUInt32(this string value) => uint.TryParse(value, out var temp) ? temp : null;
|
||||
|
||||
/// <summary>
|
||||
/// 尝试将数字的字符串表示形式转换为它的等效 64 位有符号整数
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static long? TryParseInt64(this string value) => long.TryParse(value, out var temp) ? temp : null;
|
||||
|
||||
/// <summary>
|
||||
/// 尝试将数字的字符串表示形式转换为它的等效 64 位无符号整数
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static ulong? TryParseUInt64(this string value) => ulong.TryParse(value, out var temp) ? temp : null;
|
||||
|
||||
/// <summary>
|
||||
/// 尝试将数字的字符串表示形式转换为它的等效 byte 值
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static byte? TryParseByte(this string value) => byte.TryParse(value, out var temp) ? temp : null;
|
||||
|
||||
public static bool? TryParseBoolean(this string value) => bool.TryParse(value, out var temp) ? temp : null;
|
||||
|
||||
/// <summary>
|
||||
/// 尝试将数字的字符串表示形式转换为它的等效 sbyte 值
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static sbyte? TryParseSByte(this string value) => sbyte.TryParse(value, out sbyte temp) ? temp : null;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
+9
@@ -248,5 +248,14 @@ namespace System.Properties {
|
||||
return ResourceManager.GetString("Unknown", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 不受支持的手机号码号段({0}) 的本地化字符串。
|
||||
/// </summary>
|
||||
internal static string UnsupportedPhoneNumberSegment_ {
|
||||
get {
|
||||
return ResourceManager.GetString("UnsupportedPhoneNumberSegment_", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,4 +181,7 @@
|
||||
<data name="Unknown" xml:space="preserve">
|
||||
<value>未知</value>
|
||||
</data>
|
||||
<data name="UnsupportedPhoneNumberSegment_" xml:space="preserve">
|
||||
<value>不受支持的手机号码号段({0})</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -6,16 +6,16 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1"/>
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0"/>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0"/>
|
||||
<PackageReference Include="Nito.Comparers" Version="6.1.0"/>
|
||||
<PackageReference Include="Xamarin.Essentials" Version="1.6.1"/>
|
||||
<PackageReference Include="Crc32.NET" Version="1.2.0"/>
|
||||
<PackageReference Include="gfoidl.Base64" Version="1.1.1"/>
|
||||
<PackageReference Include="MessagePack" Version="2.2.85"/>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3"/>
|
||||
<PackageReference Include="System.Text.Json" Version="5.0.1"/>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
|
||||
<PackageReference Include="Nito.Comparers" Version="6.1.0" />
|
||||
<PackageReference Include="Xamarin.Essentials" Version="1.6.1" />
|
||||
<PackageReference Include="Crc32.NET" Version="1.2.0" />
|
||||
<PackageReference Include="gfoidl.Base64" Version="1.1.1" />
|
||||
<PackageReference Include="MessagePack" Version="2.2.85" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="System.Text.Json" Version="5.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user