//package com.inkasso.adapter.util;
//
//import com.aliyun.oss.ClientException;
//import com.aliyun.oss.OSS;
//import com.aliyun.oss.common.auth.*;
//import com.aliyun.oss.OSSClientBuilder;
//import com.aliyun.oss.OSSException;
//import com.aliyun.oss.model.PutObjectRequest;
//import com.aliyun.oss.model.PutObjectResult;
//
//import java.io.ByteArrayInputStream;
//import java.io.FileInputStream;
//import java.io.InputStream;
//import java.net.URL;
//import java.util.Date;
//
//public class OSSUtil {
//
//    private static final String endpoint = "https://oss-cn-beijing.aliyuncs.com";
//    private static final String accessKeyId = "LTAI5tGF9tdGNFoqAYKYwDQT";
//    private static final String secretAccessKey="OLtanMhq2wWNVj4dFREqS4HFltQHFM";
//    private static final String bucketName = "kafubao";
//
//
//
//    public static void uploadFile(String absolutePath,String path) throws Exception {
//        // Endpoint以华东1（杭州）为例，其它Region请按实际情况填写。
//        // 填写Object完整路径，完整路径中不能包含Bucket名称，例如exampledir/exampleobject.txt。
//        String objectName = "image/abd.jpg";
//        // 填写本地文件的完整路径，例如D:\\localpath\\examplefile.txt。
//        // 如果未指定本地路径，则默认从示例程序所属项目对应本地路径中上传文件流。
//        String filePath= "D:\\担保书(CIA-HT-2021328-G4).pdf_1.jpg";
//
//        // 创建OSSClient实例。
//        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId,secretAccessKey);
//        try {
//            InputStream inputStream = new FileInputStream(absolutePath);
//            // 创建PutObjectRequest对象。
//            PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, path, inputStream);
//            // 创建PutObject请求。
//            ossClient.putObject(putObjectRequest);
//
////            String url = getUrl(path);
////            System.out.println("能访问的路径========="+url);
//        } catch (OSSException oe) {
//            System.out.println("Caught an OSSException, which means your request made it to OSS, "
//                    + "but was rejected with an error response for some reason.");
//            System.out.println("Error Message:" + oe.getErrorMessage());
//            System.out.println("Error Code:" + oe.getErrorCode());
//            System.out.println("Request ID:" + oe.getRequestId());
//            System.out.println("Host ID:" + oe.getHostId());
//        } catch (ClientException ce) {
//            System.out.println("Caught an ClientException, which means the client encountered "
//                    + "a serious internal problem while trying to communicate with OSS, "
//                    + "such as not being able to access the network.");
//            System.out.println("Error Message:" + ce.getMessage());
//        } finally {
//            if (ossClient != null) {
//                ossClient.shutdown();
//            }
//        }
//    }
//
//    public static String  getUrl(String  objectPath){
//
//        // 创建OSSClient实例。
//        OSS ossClient = new OSSClientBuilder().build(endpoint,  accessKeyId,secretAccessKey);
//        URL url = null;
//        try {
//            // 设置签名URL过期时间，单位为秒，本示例以设置过期时间为5分钟 为例。您可以根据实际业务场景，设置合理的过期时间。
//            Date expiration = new Date(new Date().getTime() +  1000L*60*60*24*365*2);
//            // 生成以GET方法访问的签名URL，在签名URL有效期内访客可以直接通过浏览器访问相关内容。
//            url = ossClient.generatePresignedUrl(bucketName, objectPath, expiration);
//            System.out.println(url);
//            return url.toString();
//        } catch (OSSException oe) {
//            System.out.println("Caught an OSSException, which means your request made it to OSS, "
//                + "but was rejected with an error response for some reason.");
//            System.out.println("Error Message:" + oe.getErrorMessage());
//            System.out.println("Error Code:" + oe.getErrorCode());
//            System.out.println("Request ID:" + oe.getRequestId());
//            System.out.println("Host ID:" + oe.getHostId());
//        } catch (ClientException ce) {
//            System.out.println("Caught an ClientException, which means the client encountered "
//                + "a serious internal problem while trying to communicate with OSS, "
//                + "such as not being able to access the network.");
//            System.out.println("Error Message:" + ce.getMessage());
//        } finally {
//            if (ossClient != null) {
//                ossClient.shutdown();
//            }
//        }
//        return null;
//    }
//
//
//    public static void upload(byte[] bytes, String path) {
//
//        // 创建OSSClient实例。
//        OSS ossClient = new OSSClientBuilder().build(endpoint,  accessKeyId,secretAccessKey);
//
//        try {
//            // 创建PutObject请求。
//            ossClient.putObject(bucketName, path, new ByteArrayInputStream(bytes));
//        } catch (OSSException oe) {
//            System.out.println("Caught an OSSException, which means your request made it to OSS, "
//                + "but was rejected with an error response for some reason.");
//            System.out.println("Error Message:" + oe.getErrorMessage());
//            System.out.println("Error Code:" + oe.getErrorCode());
//            System.out.println("Request ID:" + oe.getRequestId());
//            System.out.println("Host ID:" + oe.getHostId());
//        } catch (ClientException ce) {
//            System.out.println("Caught an ClientException, which means the client encountered "
//                + "a serious internal problem while trying to communicate with OSS, "
//                + "such as not being able to access the network.");
//            System.out.println("Error Message:" + ce.getMessage());
//        } finally {
//            if (ossClient != null) {
//                ossClient.shutdown();
//            }
//        }
//    }
//
//
//}