当前位置:网站首页>调用阿里云oss和sms服务
调用阿里云oss和sms服务
2022-08-05 03:08:00 【帅大大的架构之路】
调用阿里云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());
}
}
边栏推荐
- 【七夕节】浪漫七夕,代码传情。将爱意变成绚烂的立体场景,给她(他)一个惊喜!(送代码)
- Dynamic management of massive service instances
- VSCode Change Default Terminal how to modify the Default Terminal VSCode
- Object.defineProperty monitors data changes in real time and updates the page
- 优炫数据库的单节点如何转集群
- Countdown to 2 days|Cloud native Meetup Guangzhou Station, waiting for you!
- How OpenGL works
- 剑指Offer--找出数组中重复的数字(三种解法)
- The 22-07-31 weeks summary
- AI+PROTAC | dx/tx completes $5 million seed round
猜你喜欢

QT语言文件制作

.NET应用程序--Helloworld(C#)

word column notes

ASP.NET应用程序--Hello World

人人都在说的数据中台,你需要关注的核心特点是什么?

Matlab drawing 3

Simple description of linked list and simple implementation of code

Why did they choose to fall in love with AI?

J9 Digital Currency: What is the creator economy of web3?

2022高处安装、维护、拆除考试题模拟考试题库及在线模拟考试
随机推荐
1484. Sell Products by Date
Question about #sql shell#, how to solve it?
Apache DolphinScheduler, a new generation of distributed workflow task scheduling platform in practice - Medium
How to solve the error cannot update secondary snapshot during a parallel operation when the PostgreSQL database uses navicat to open the table structure?
sql server installation prompts that the username does not exist
Details such as compiling pretreatment
torch.roll()
沃谈小知识 |“远程透传”那点事儿
The usage of try...catch and finally in js
Bubble Sort and Quick Sort
(十一)元类
[Qixi Festival] Romantic Tanabata, code teaser.Turn love into a gorgeous three-dimensional scene and surprise her (him)!(send code)
百日刷题计划 ———— DAY2
J9 Digital Currency: What is the creator economy of web3?
1873. 计算特殊奖金
QStyle platform style
word column notes
Is your data safe in this hyperconnected world?
语法基础(变量、输入输出、表达式与顺序语句)
Data to enhance Mixup principle and code reading