苦于阿里云短信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
1
共 2 条评论, 1 页
评论区
写评论还有变量也是
--
👇
Rustln: 建议函数名称改为:send_sms
建议函数名称改为:send_sms