SmsClient

Struct SmsClient 

Source
pub struct SmsClient { /* private fields */ }

Implementations§

Source§

impl SmsClient

Source

pub async fn execute<Req>(&self, request: Req) -> SmsResult<Req::Output>
where Req: ApiRequest,

通用的 API 执行方法,支持重试和超时

此方法封装了所有 API 请求的公共逻辑:

  • 参数验证
  • 重试机制(指数退避)
  • 超时控制
  • HTTP 请求构建
  • 签名生成
  • 响应解析
Source§

impl SmsClient

Source

pub async fn send_sms( &self, request: SendSmsRequest, ) -> SmsResult<Vec<SendStatus>>

发送短信

§参数
  • request: 发送短信请求
§返回

成功时返回每个号码的发送状态列表

§错误
  • InvalidParameter: 参数错误(手机号格式、模板ID等)
  • RateLimited: 触发频率限制
  • InsufficientBalance: 余额不足
  • PartialFailure: 部分号码发送失败
Source

pub async fn send_simple_sms( &self, app_id: impl Into<String>, phone_numbers: &[impl AsRef<str>], template_id: impl Into<String>, sign_name: impl Into<String>, ) -> SmsResult<Vec<SendStatus>>

快捷发送短信(无模板参数)

这是一个便捷方法,适用于不需要模板参数的简单短信发送场景。

§参数
  • app_id: SMS 应用 ID (如 “1400123456”)
  • phone_numbers: 手机号列表,支持国内和国际号码
  • template_id: 短信模板 ID
  • sign_name: 短信签名名称
§示例
let results = client.send_simple_sms(
    "1400123456",
    &["13800000000", "13900000000"],
    "123456",
    "公司名称",
).await?;

for status in results {
    if status.is_success() {
        println!("✓ {} 发送成功", status.phone_number);
    }
}
Source

pub async fn send_template_sms( &self, app_id: impl Into<String>, phone_numbers: &[impl AsRef<str>], template_id: impl Into<String>, sign_name: impl Into<String>, template_params: &[impl AsRef<str>], ) -> SmsResult<Vec<SendStatus>>

快捷发送带模板参数的短信

这是一个便捷方法,适用于需要填充模板参数的短信发送场景。

§参数
  • app_id: SMS 应用 ID (如 “1400123456”)
  • phone_numbers: 手机号列表
  • template_id: 短信模板 ID
  • sign_name: 短信签名名称
  • template_params: 模板参数列表,按模板中的占位符顺序填充
§示例
// 假设模板内容为: "您的验证码是{1},请在{2}分钟内完成验证"
let results = client.send_template_sms(
    "1400123456",
    &["13800000000"],
    "123456",
    "公司名称",
    &["888888", "5"],  // 验证码和有效期
).await?;
Source

pub async fn send_single_sms( &self, app_id: impl Into<String>, phone_number: impl AsRef<str>, template_id: impl Into<String>, sign_name: impl Into<String>, ) -> SmsResult<SendStatus>

发送单条短信(最简化版本)

这是最简化的快捷方法,用于向单个手机号发送不含模板参数的短信。

§参数
  • app_id: SMS 应用 ID
  • phone_number: 单个手机号
  • template_id: 短信模板 ID
  • sign_name: 短信签名名称
§返回

返回该手机号的发送状态

§示例
let status = client.send_single_sms(
    "1400123456",
    "13800000000",
    "123456",
    "公司名称",
).await?;

if status.is_success() {
    println!("短信发送成功!");
}
Source

pub async fn send_single_template_sms( &self, app_id: impl Into<String>, phone_number: impl AsRef<str>, template_id: impl Into<String>, sign_name: impl Into<String>, template_params: &[impl AsRef<str>], ) -> SmsResult<SendStatus>

发送单条带模板参数的短信

§参数
  • app_id: SMS 应用 ID
  • phone_number: 单个手机号
  • template_id: 短信模板 ID
  • sign_name: 短信签名名称
  • template_params: 模板参数列表
§返回

返回该手机号的发送状态

§示例
let status = client.send_single_template_sms(
    "1400123456",
    "13800000000",
    "123456",
    "公司名称",
    &["888888", "5"],
).await?;
Source§

impl SmsClient

Source

pub async fn add_sms_sign( &self, request: AddSmsSignRequest, ) -> SmsResult<AddSignStatus>

添加短信签名

§参数
  • request: 添加签名请求
§返回

成功时返回签名状态信息

§注意

个人认证用户不支持使用API添加签名,请使用控制台

Source§

impl SmsClient

Source

pub async fn delete_sms_sign( &self, request: DeleteSmsSignRequest, ) -> SmsResult<DeleteSignStatus>

删除短信签名

§参数
  • request: 删除签名请求
§返回

成功时返回删除状态信息

§注意

个人认证用户不支持使用API删除签名

Source§

impl SmsClient

Source

pub async fn describe_sms_sign_list( &self, request: DescribeSmsSignListRequest, ) -> SmsResult<Vec<DescribeSignStatus>>

查询短信签名状态

§参数
  • request: 查询签名请求
§返回

成功时返回签名状态列表

Source§

impl SmsClient

Source

pub async fn modify_sms_sign( &self, request: ModifySmsSignRequest, ) -> SmsResult<ModifySignStatus>

修改短信签名

§参数
  • request: 修改签名请求
§返回

成功时返回签名状态信息

§注意

个人认证用户不支持使用API修改签名

Source§

impl SmsClient

Source

pub async fn add_sms_template( &self, request: AddSmsTemplateRequest, ) -> SmsResult<AddTemplateStatus>

添加短信模板

Source§

impl SmsClient

Source

pub async fn delete_sms_template( &self, request: DeleteSmsTemplateRequest, ) -> SmsResult<DeleteTemplateStatus>

删除短信模板

Source§

impl SmsClient

Source

pub async fn describe_sms_template_list( &self, request: DescribeSmsTemplateListRequest, ) -> SmsResult<Vec<DescribeTemplateStatus>>

查询短信模板状态

Source§

impl SmsClient

Source

pub async fn modify_sms_template( &self, request: ModifySmsTemplateRequest, ) -> SmsResult<ModifyTemplateStatus>

修改短信模板

Source§

impl SmsClient

Source§

impl SmsClient

Source

pub async fn send_status_statistics( &self, request: SendStatusStatisticsRequest, ) -> SmsResult<SendStatistics>

发送短信数据统计

Source§

impl SmsClient

Source

pub async fn sms_packages_statistics( &self, request: SmsPackagesStatisticsRequest, ) -> SmsResult<Vec<SmsPackageInfo>>

套餐包信息统计

Source§

impl SmsClient

Source

pub async fn describe_phone_number_info( &self, request: DescribePhoneNumberInfoRequest, ) -> SmsResult<Vec<PhoneNumberInfo>>

号码信息查询

Source§

impl SmsClient

Source

pub async fn report_conversion( &self, request: ReportConversionRequest, ) -> SmsResult<ReportConversionStatus>

上报转化率

Source§

impl SmsClient

Source

pub async fn pull_sms_send_status_by_phone_number( &self, request: PullSmsSendStatusByPhoneNumberRequest, ) -> SmsResult<Vec<PullSmsStatus>>

拉取单个号码短信下发状态

§参数
  • request: 拉取请求
§返回

成功时返回指定号码的短信下发状态列表

Source§

impl SmsClient

Source

pub async fn pull_sms_reply_status( &self, request: PullSmsReplyStatusRequest, ) -> SmsResult<Vec<PullSmsReply>>

拉取短信回复状态

§参数
  • request: 拉取请求
§返回

成功时返回短信回复状态列表

Source§

impl SmsClient

Source

pub async fn pull_sms_reply_status_by_phone_number( &self, request: PullSmsReplyStatusByPhoneNumberRequest, ) -> SmsResult<Vec<PullSmsReply>>

拉取单个号码短信回复状态

§参数
  • request: 拉取请求
§返回

成功时返回指定号码的短信回复状态列表

Source§

impl SmsClient

Source

pub async fn pull_sms_send_status( &self, request: PullSmsSendStatusRequest, ) -> SmsResult<Vec<PullSmsStatus>>

拉取短信下发状态

§参数
  • request: 拉取请求
§返回

成功时返回短信下发状态列表

Source§

impl SmsClient

Source

pub fn new(credential: Credential, config: ClientConfig) -> SmsResult<Self>

创建新的SMS客户端

§参数
  • credential: API凭证 (SecretId/SecretKey)
  • config: 客户端配置
§错误
  • 配置验证失败
  • HTTP客户端构建失败(如代理配置错误)

Trait Implementations§

Source§

impl Clone for SmsClient

Source§

fn clone(&self) -> SmsClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more