use std::collections::HashMap;
use spring::tracing;
use crate::aliyun::Aliyun;
use crate::config::SmsConfig;
#[derive(Debug, Clone)]
pub struct SmsClient {
config: SmsConfig,
}
impl SmsClient {
pub fn new(config: SmsConfig) -> Self {
Self { config }
}
pub async fn send_sms_by_aliyun(&self, phone_numbers: &str, template_code: &str, template_param: Option<HashMap<&str, &str>>) -> anyhow::Result<()> {
let aliyun_config = &self.config.aliyun;
match aliyun_config {
None => Err(anyhow::Error::msg("Sms config not found")),
Some(config) => {
Aliyun::new(config)
.send_sms(phone_numbers, template_code, template_param)
.await
.map_err(|e| {
tracing::error!("Sms Send Fail: {}", e);
anyhow::Error::msg(format!("{}", e))
})
}
}
}
}