Bitzsoft.Integrations.Sms
1.0.0-alpha.1
This is a prerelease version of Bitzsoft.Integrations.Sms.
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Bitzsoft.Integrations.Sms --version 1.0.0-alpha.1
NuGet\Install-Package Bitzsoft.Integrations.Sms -Version 1.0.0-alpha.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Bitzsoft.Integrations.Sms" Version="1.0.0-alpha.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Bitzsoft.Integrations.Sms" Version="1.0.0-alpha.1" />
<PackageReference Include="Bitzsoft.Integrations.Sms" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Bitzsoft.Integrations.Sms --version 1.0.0-alpha.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Bitzsoft.Integrations.Sms, 1.0.0-alpha.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Bitzsoft.Integrations.Sms@1.0.0-alpha.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Bitzsoft.Integrations.Sms&version=1.0.0-alpha.1&prerelease
#tool nuget:?package=Bitzsoft.Integrations.Sms&version=1.0.0-alpha.1&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Bitzsoft.Integrations.Sms
短信双通道集成 -- 阿里云短信 + 腾讯云短信统一抽象,一套接口切换两大云厂商。
功能特性
- 统一
ISMS接口,屏蔽阿里云与腾讯云 SDK 差异 - 支持
SendAsync异步发送,返回标准化SMSResult - 阿里云短信:基于 OpenPlatform POP 签名调用
- 腾讯云短信:基于腾讯云 API 3.0 签名调用
- Options 强类型配置,支持
IConfigurationSection绑定 - 独立 DI 注册,可按需引入单通道或双通道
安装
dotnet add package Bitzsoft.Integrations.Sms
或直接在项目文件中引用:
<PackageReference Include="Bitzsoft.Integrations.Sms" Version="*" />
配置
在 appsettings.json 中添加对应通道配置:
{
"AliyunSms": {
"AccessKeyId": "your-access-key-id",
"AccessKeySecret": "your-access-key-secret",
"RegionId": "cn-hangzhou",
"Domain": "dysmsapi.aliyuncs.com",
"Version": "2017-05-25"
},
"TencentSms": {
"SecretId": "your-secret-id",
"SecretKey": "your-secret-key",
"AppId": "1400xxxxxx",
"Region": "ap-guangzhou",
"CountryCode": "+86"
}
}
注册服务
阿里云短信通道
using Bitzsoft.Integrations.Sms.Aliyun;
using Bitzsoft.Integrations.Sms.Aliyun.Options;
// 方式一:通过 IConfigurationSection 绑定
builder.Services.AddAliyunSms(builder.Configuration.GetSection("AliyunSms"));
// 方式二:通过委托手动配置
builder.Services.AddAliyunSms(options =>
{
options.AccessKeyId = "your-access-key-id";
options.AccessKeySecret = "your-access-key-secret";
options.RegionId = "cn-hangzhou";
options.Domain = "dysmsapi.aliyuncs.com";
options.Version = "2017-05-25";
});
腾讯云短信通道
using Bitzsoft.Integrations.Sms.Tencent;
using Bitzsoft.Integrations.Sms.Tencent.Options;
// 方式一:通过 IConfigurationSection 绑定
builder.Services.AddTencentSms(builder.Configuration.GetSection("TencentSms"));
// 方式二:通过委托手动配置
builder.Services.AddTencentSms(options =>
{
options.SecretId = "your-secret-id";
options.SecretKey = "your-secret-key";
options.AppId = "1400xxxxxx";
options.Region = "ap-guangzhou";
options.CountryCode = "+86";
});
使用示例
以下示例展示在业务服务中通过阿里云通道发送验证码短信:
using Bitzsoft.Integrations.Sms.Abstractions;
/// <summary>
/// 用户注册服务
/// </summary>
public class RegistrationService
{
private readonly ISMS _sms;
/// <summary>
/// 初始化注册服务实例
/// </summary>
/// <param name="sms">短信发送服务(由 DI 注入具体通道实现)</param>
public RegistrationService(ISMS sms)
{
_sms = sms;
}
/// <summary>
/// 发送手机验证码
/// </summary>
/// <param name="phoneNumber">目标手机号</param>
/// <param name="verificationCode">6 位数字验证码</param>
/// <param name="cancellationToken">取消令牌</param>
public async Task<bool> SendVerificationCodeAsync(
string phoneNumber,
string verificationCode,
CancellationToken cancellationToken = default)
{
var templateParams = new Dictionary<string, string>
{
{ "code", verificationCode }
};
SMSResult result = await _sms.SendAsync(
phoneNumber: phoneNumber,
signName: "我的应用",
templateCode: "SMS_123456789",
templateParams: templateParams,
cancellationToken: cancellationToken);
if (!result.Success)
{
// 记录失败日志,包含错误码与错误消息
Console.WriteLine(
"短信发送失败: ErrorCode={0}, ErrorMessage={1}",
result.ErrorCode,
result.ErrorMessage);
return false;
}
// 可将 result.BizId 存储用于后续状态查询
Console.WriteLine("短信发送成功, BizId={0}", result.BizId);
return true;
}
}
相关包
- Bitzsoft.Integrations.CrawlingService -- 网页爬取服务集成客户端
- Bitzsoft.Integrations.Ocr -- OCR 文字识别集成
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Aliyun.OSS.SDK.NetCore (>= 2.13.0)
- aliyun-net-sdk-core (>= 1.6.2)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.4)
- Microsoft.Extensions.Options (>= 10.0.4)
- TencentCloudSDK (>= 3.0.1363)
-
net8.0
- Aliyun.OSS.SDK.NetCore (>= 2.13.0)
- aliyun-net-sdk-core (>= 1.6.2)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.4)
- Microsoft.Extensions.Options (>= 10.0.4)
- TencentCloudSDK (>= 3.0.1363)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Bitzsoft.Integrations.Sms:
| Package | Downloads |
|---|---|
|
Bitzsoft.Integrations.All
Bitzsoft 第三方集成聚合包 — 包含全部 Integration 模块 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-alpha.8 | 37 | 7/1/2026 |
| 1.0.0-alpha.7 | 63 | 6/16/2026 |
| 1.0.0-alpha.6 | 69 | 6/16/2026 |
| 1.0.0-alpha.5 | 60 | 6/14/2026 |
| 1.0.0-alpha.3 | 59 | 6/7/2026 |
| 1.0.0-alpha.2 | 59 | 5/29/2026 |
| 1.0.0-alpha.1 | 59 | 5/28/2026 |