アリは、JavaおよびSMSツールを使用して、OSS

免責事項:この記事はブロガーオリジナル記事です、ブロガーなく再生してはならないhttps://blog.csdn.net/weixin_43835717/article/details/90747008を許可

OSSを提供するために、アリやテキストメッセージング機能

私たちは、最新バージョンを使用することをお勧めします

インストール

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

使用


アリOSS:

  • 単純なファイルのアップロードは、(ファイルが最大5Gを超えることはできません)画像のアップロードのアドレスが成功した戻り、後続の戻り結果の裁量に応じて、リターン・エラー・メッセージが失敗しました。
@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);
}
  • 、唯一の指定されたファイルを現在のプレゼンテーションを削除し、複数のファイルを削除し、ファイル名の正常な戻りリストを削除するには、[削除]をサポートするOSSをアップロードした後、成功の道に戻るfileOssUrl:ファイルを削除します。
@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);
}

ダウンロードファイル:fileOssUrlが成功したアップロードのOSSのURLの後に戻るには、localFilePathは(作成されますが存在しない)ローカルディレクトリを保存したい、それが成功のためにtrueを返します。

@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("下载失败");
}

ストリーミングファイルのダウンロード:

@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("下载失败");
}

アリのSMS:

  • SMSを送信:首尾OK送られたコード表現の内容を返すために、より多くのステータスコードは、に行く状態コード
@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クエリ、日付がYYYYMMDDしなければならない形式(20181207)、唯一の最後の30日間サポート;コード要求の内容を返しますが、OKの代表のために成功した、ページあたり1-50の範囲内のメッセージの数は、(見ることがレコードを送信するためにページ番号を指定します1最小)、
    より多くの走行状態コード:ステータスコード
@GetMapping("query-ali")
@ApiOperation(value = "查询阿里短信发送记录", httpMethod = "GET")
public ResponseEntity queryAli() {
    String result = AliSms.of("您的accessKeyId", "您的accessKey秘钥")
            .querySendDetails("157********", "查询日期(年月日)", "每页数量", "当前页数");
    return ResponseEntity.ok(result);
}

おすすめ

転載: blog.csdn.net/weixin_43835717/article/details/90747008