< 返回版块

wandercn 发表于 2022-05-21 14:32

Tags:sms,aliyunsms ,gostd ,aliyunapi,dysmsapi

苦于阿里云短信sdk没有rust,自己实现了一个阿里云短信sdk。

https://github.com/wandercn/alibaba-cloud-sdk-rust

使用自己写的gostd::net::http 发http请求。

Example

use alibaba_cloud_sdk_rust::services::dysmsapi;

const AliyunSmsServerRegion: &str = "cn-hangzhou";
const AliyunSmsAccessKeyID: &str = "LTAI4FwqPxiAxxxxxx";
const AliyunSmsAccessKeySecret: &str = "xxxxx0FJqHTTLwDUuhxxxxx";
const AliyunSmsReportTempleateCode: &str = "SMS_226xxxx"; // 通知模版
const AliyunSmsSignName: &str = "阿里云"; // 短信署名

fn main()->Result<(), std::io::Error>{
    let phoneNumber="1391212xxxx";
    match  SendSMS(phoneNumber) {
        Ok(response)=> println!("{:?}",response),
        Err(err)=>println!("{}",err),
    }
}

fn SendSMS(phoneNumber: &str) -> Result<(), std::io::Error> {
    let mut client = dysmsapi::Client::NewClientWithAccessKey(
        AliyunSmsServerRegion,
        AliyunSmsAccessKeyID,
        AliyunSmsAccessKeySecret,
    )?;
    let mut request = dysmsapi::CreateSendSmsRequest();
    request.PhoneNumbers = strings::Replace(phoneNumber, "+86", "", -1);
    request.SignName = AliyunSmsSignName.to_owned();
    request.TemplateCode = AliyunSmsReportTempleateCode.to_owned();
    let response = client.SendSms(&mut request)?;
    println!("{:?}", &response);

    Ok(())
}

Ext Link: https://github.com/wandercn/alibaba-cloud-sdk-rust

评论区

写评论
soft5 2022-05-22 15:11

还有变量也是

--
👇
Rustln: 建议函数名称改为:send_sms

Rustln 2022-05-21 21:30

建议函数名称改为:send_sms

1 共 2 条评论, 1 页