当前位置:网站首页>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());
}
}
边栏推荐
- IJCAI2022 | DictBert: Pre-trained Language Models with Contrastive Learning for Dictionary Description Knowledge Augmentation
- The second council meeting of the Dragon Lizard Community was successfully held!Director general election, 4 special consultants joined
- A small tool to transfer files using QR code - QFileTrans 1.2.0.1
- 2022-08-04 The sixth group, hidden from spring, study notes
- The 22-07-31 weeks summary
- [Filter tracking] based on matlab unscented Kalman filter inertial navigation + DVL combined navigation [including Matlab source code 2019]
- 627. Change of gender
- sql怎么找字段里所有数据为空的字段
- Leading the highland of digital medicine, Zhongshan Hospital explores to create a "new paradigm" for future hospitals
- 调用阿里云oss和sms服务
猜你喜欢

龙蜥社区第二届理事大会圆满召开!理事换届选举、4 位特约顾问加入

Simple description of linked list and simple implementation of code

QT MV\MVC structure
![[Solved] Unity Coroutine coroutine is not executed effectively](/img/ab/035ef004a561fb98d3dd1d7d8b5618.png)
[Solved] Unity Coroutine coroutine is not executed effectively

北斗三号短报文终端露天矿山高边坡监测方案

ASP.NET application--Hello World

.NET Application -- Helloworld (C#)

After the large pixel panorama is completed, what are the promotion methods?

word分栏小记

Beyond YOLO5-Face | YOLO-FaceV2 officially open source Trick+ academic point full
随机推荐
dmp (dump) dump file
Apache DolphinScheduler, a new generation of distributed workflow task scheduling platform in practice - Medium
In 2022, you still can't "low code"?Data science can also play with Low-Code!
The pit of std::string::find return value
Turn: Charles Handy: Who you are is more important than what you do
627. Change of gender
Cloud Native (32) | Introduction to Platform Storage System in Kubernetes
tree table lookup
Intersection of Boolean Operations in SuperMap iDesktop.Net - Repairing Complex Models with Topological Errors
Countdown to 2 days|Cloud native Meetup Guangzhou Station, waiting for you!
[论文笔记] MapReduce: Simplified Data Processing on Large Clusters
In 2022, you still can't "low code"?Data science can also play with Low-Code!
Syntax basics (variables, input and output, expressions and sequential statements)
2022 High-level installation, maintenance, and removal of exam questions mock exam question bank and online mock exam
AI + Small Nucleic Acid Drugs | Eleven Completes $22 Million Seed Round Financing
undo问题
How Jin Cang database correctness verification platform installation file
How OpenGL works
龙蜥社区第二届理事大会圆满召开!理事换届选举、4 位特约顾问加入
905. 区间选点