Ali oss using java and SMS tools

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allow https://blog.csdn.net/weixin_43835717/article/details/90747008

Ali and text messaging capabilities to provide oss

We recommend using the latest version

installation

<dependency>
    <groupId>cn.gjing</groupId>
    <artifactId>tools-ali</artifactId>
    <version>1.0.1</version>
</dependency>

Instructions


Ali OSS:

  • Simple file upload (file can not exceed the maximum 5G) returns the address of the picture upload was successful, failed return error messages, according to the discretion of the subsequent return result;
@PostMapping("/upload")
@ApiOperation(value = "上传图片", httpMethod = "POST")
public ResponseEntity testUpload(@RequestParam(name = "file") MultipartFile file) {
   String fileOssUrl = AliOss.of("endPoint", "accessKeyId","accessKeySecret", "bucketName")
           .upload(file);
   return ResponseEntity.ok(fileOssUrl);
}
  • Delete files: Delete to delete the successful return list of file names, support delete multiple files, delete the current presentation only the specified file, fileOssUrl return to the path of success after uploading oss
@DeleteMapping("/file")
@ApiOperation(value = "删除文件", httpMethod = "DELETE")
public ResponseEntity deleteImg(@RequestParam("url") String url) {
   List<String> deleteObjectList = AliOss.of("endPoint", "accessKeyId","accessKeySecret", "bucketName")
           .delete(Collections.singletonList(url));
   return ResponseEntity.ok(deleteObjectList);
}

Download file: fileOssUrl to return after a successful upload oss ​​url, localFilePath (does not exist will be created) you want to save a local directory, it returns true for success;

@PostMapping("/img-native")
@ApiOperation(value = "下载文件到本地", httpMethod = "POST")
public ResponseEntity downImgToNative(String fileOssUrl, String path) {
   boolean down = AliOss.of("endPoint", "accessKeyId","accessKeySecret", "bucketName")
       .downloadFile(fileOssUrl, path);
   if (down) {
       return ResponseEntity.ok("下载成功");
   }
   return ResponseEntity.badRequest().body("下载失败");
}

Streaming Download file:

@GetMapping("/img-stream")
@ApiOperation(value = "流式下载", httpMethod = "GET")
public ResponseEntity streamDown(String fileOssUrl, HttpServletResponse response) {
   boolean down = AliOss.of("endPoint", "accessKeyId","accessKeySecret", "bucketName")
       .downloadStream(fileOssUrl, response);
   if (down) {
       return ResponseEntity.ok("下载成功");
   }
   return ResponseEntity.badRequest().body("下载失败");
}

Ali SMS:

  • Send SMS: to return the contents of the Code representation sent successfully ok, more status codes go to the state code
@PostMapping("/send-ali")
@ApiOperation(value = "阿里短信", httpMethod = "POST")
public ResponseEntity sendAli() {
    //参数,必须与对应的短信模板参数对应,如果没有参数,可以传null或者空map
    Map<String, String> param = new HashMap<>(16);
    map.put("code", "123123");
    //接收的短信的手机号,支持多个,英文逗号隔开
    String send = AliSms.of("accessKeyId", "accessKeySecret")
            .send("157********", "短信模板Code", param, "短信签名");
    return ResponseEntity.ok(send);
}
  • SMS query, the date must be yyyyMMdd format (20,181,207), supports only the last 30 days; return the contents of the Code request was successful for the OK representatives, the number of messages in the range of 1-50 per page, specify the page number to send records to be viewed ( minimum 1),
    more travel status code: status code
@GetMapping("query-ali")
@ApiOperation(value = "查询阿里短信发送记录", httpMethod = "GET")
public ResponseEntity queryAli() {
    String result = AliSms.of("您的accessKeyId", "您的accessKey秘钥")
            .querySendDetails("157********", "查询日期(年月日)", "每页数量", "当前页数");
    return ResponseEntity.ok(result);
}

Guess you like

Origin blog.csdn.net/weixin_43835717/article/details/90747008