当前位置:网站首页>调用阿里云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());
}
}
边栏推荐
- Principle and Technology of Virtual Memory
- 1527. Patients suffering from a disease
- 2022 High-level installation, maintenance, and removal of exam questions mock exam question bank and online mock exam
- How to Add Category-Specific Widgets in WordPress
- Matlab画图3
- Thinking (88): Use protobuf custom options for multi-version management of data
- Ant Sword Advanced Module Development
- QStyle platform style
- 虚拟内存原理与技术
- Bubble Sort and Quick Sort
猜你喜欢
如何在WordPress中添加特定类别的小工具
[Solved] Unity Coroutine coroutine is not executed effectively
A small tool to transfer files using QR code - QFileTrans 1.2.0.1
dmp(dump)转储文件
QT language file production
告白数字化转型时代,时速云镌刻价值新起点
Flink 1.15.1 Cluster Construction (StandaloneSession)
Countdown to 2 days|Cloud native Meetup Guangzhou Station, waiting for you!
人人都在说的数据中台,你需要关注的核心特点是什么?
Data to enhance Mixup principle and code reading
随机推荐
The usage of try...catch and finally in js
Data to enhance Mixup principle and code reading
Use SuperMap iDesktopX data migration tool to migrate map documents and symbols
1484. 按日期分组销售产品
1873. The special bonus calculation
1873. 计算特殊奖金
汉字转拼音
J9 Digital Currency: What is the creator economy of web3?
Compressed storage of special matrices
AI + Small Nucleic Acid Drugs | Eleven Completes $22 Million Seed Round Financing
HDU 1114: Piggy-Bank ← The Complete Knapsack Problem
VSCode Change Default Terminal how to modify the Default Terminal VSCode
Dynamic management of massive service instances
【滤波跟踪】基于matlab无迹卡尔曼滤波惯性导航+DVL组合导航【含Matlab源码 2019期】
用CH341A烧录外挂Flash (W25Q16JV)
627. Change of gender
The second council meeting of the Dragon Lizard Community was successfully held!Director general election, 4 special consultants joined
Countdown to 2 days|Cloud native Meetup Guangzhou Station, waiting for you!
使用二维码传输文件的小工具 - QFileTrans 1.2.0.1
Intersection of Boolean Operations in SuperMap iDesktop.Net - Repairing Complex Models with Topological Errors