当前位置:网站首页>Call Alibaba Cloud oss and sms services
Call Alibaba Cloud oss and sms services
2022-08-05 03:19:00 【The road of handsome architecture】
调用阿里云oss和sms服务
pom.xml
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.10.2</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>dysmsapi20170525</artifactId>
<version>2.0.17</version>
</dependency>
oss
package com.cs.springboot.oss;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.Bucket;
import com.aliyun.oss.model.CreateBucketRequest;
import com.aliyun.oss.model.GetObjectRequest;
import com.aliyun.oss.model.PutObjectRequest;
import java.io.File;
import java.util.List;
public class Demo {
public static void main(String[] args) {
String endpoint = "https://oss-cn-shenzhen.aliyuncs.com";
String accessKeyId = "xxxxx";
String accessKeySecret = "xxxxx";
String bucketName = "chens1";
OSS ossClient = new OSSClientBuilder().build(endpoint,accessKeyId,accessKeySecret);
// CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);
// Bucket bucket = ossClient.createBucket(createBucketRequest);
//
// if (bucket.getName() != null) {
// System.out.println("success");
// }
ossClient.deleteBucket(bucketName);
List<Bucket> buckets = ossClient.listBuckets();
for (Bucket bucket1 : buckets) {
System.out.println(" - " + bucket1.getName());
}
String objectName = "image/1.png";
// String filePath = "C:\\Users\\DELL\\Desktop\\素材\\2.png";
// PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName,objectName,new File(filePath));
// ossClient.putObject(putObjectRequest);
// String filePath = "C:\\Users\\DELL\\Desktop\\素材\\3.png";
// ossClient.getObject(new GetObjectRequest(bucketName,objectName),new File(filePath));
if (ossClient != null) {
ossClient.shutdown();
}
}
}
sms
package com.cs.springboot.sms;
import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.teautil.models.RuntimeOptions;
import java.util.Arrays;
import java.util.List;
public class Demo {
public static Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
Config config = new Config().setAccessKeyId(accessKeyId)
.setAccessKeySecret(accessKeySecret);
config.endpoint = "dysmsapi.aliyuncs.com";
return new Client(config);
}
public static void main(String[] args_) throws Exception {
List<String> args = Arrays.asList(args_);
Client client = Demo.createClient("xxxxxx","xxxxxx");
SendSmsRequest sendSmsRequest = new SendSmsRequest()
.setSignName("阿里云短信测试")
.setTemplateCode("SMS_154950909")
.setPhoneNumbers("15527830801")
.setTemplateParam("{\"code\":\"1234\"}")
.setSmsUpExtendCode("123456")
.setOutId("外部流水扩展字段");
SendSmsResponse response = client.sendSms(sendSmsRequest);
System.out.println(response.getHeaders());
System.out.println("=========");
System.out.println(response.getBody().getRequestId());
System.out.println(response.getBody().getMessage());
System.out.println(response.getBody().getBizId());
System.out.println(response.getBody().getCode());
}
}
边栏推荐
- STM32 uses stm32cubemx LL library series tutorial
- Matlab drawing 3
- 冒泡排序与快速排序
- 905. 区间选点
- burp安装及代理设置
- (11) Metaclass
- 链表的简单描述及代码的简单实现
- Package zip is not available, but is referred to by another package.
- [Filter tracking] based on matlab unscented Kalman filter inertial navigation + DVL combined navigation [including Matlab source code 2019]
- Chinese characters to Pinyin
猜你喜欢
冰蝎V4.0攻击来袭,安全狗产品可全面检测
[Qixi Festival] Romantic Tanabata, code teaser.Turn love into a gorgeous three-dimensional scene and surprise her (him)!(send code)
QT MV\MVC structure
【软件测试】自动化测试之unittest框架
QT language file production
public static <T> List<T> asList(T... a) 原型是怎么回事?
Beidou no. 3 short message terminal high slope in open-pit mine monitoring programme
论治理与创新,2022 开放原子全球开源峰会 OpenAnolis 分论坛圆满落幕
[论文笔记] MapReduce: Simplified Data Processing on Large Clusters
【已解决】Unity Coroutinue 协程未有效执行的问题
随机推荐
十五. 实战——mysql建库建表 字符集 和 排序规则
The Tanabata copywriting you want has been sorted out for you!
你要的七夕文案,已为您整理好!
调用阿里云oss和sms服务
After the large pixel panorama is completed, what are the promotion methods?
达梦8数据库导出导入
ffmpeg 枚举decoders, encoders 分析
J9 Digital Currency: What is the creator economy of web3?
Why did they choose to fall in love with AI?
rpc-remote procedure call demo
Turn: Charles Handy: Who you are is more important than what you do
Solve the problem of port occupancy Port xxxx was already in use
Details such as compiling pretreatment
[Storage] Dawning Storage DS800-G35 ISCSI maps each LUN to the server
rpc-remote procedure call demo
How to sort multiple fields and multiple values in sql statement
Syntax basics (variables, input and output, expressions and sequential statements)
沃谈小知识 |“远程透传”那点事儿
public static <T> List<T> asList(T... a) 原型是怎么回事?
2022-08-04 The sixth group, hidden from spring, study notes