package com.ruoyi.common.utils.qiniu;

import com.qiniu.util.Auth;
import com.qiniu.util.StringMap;
import com.ruoyi.common.utils.spring.SpringUtils;

/**
 * 七牛云工具类
 * @author qzz
 * 2024/3/26
 */
public class QiNiuUtils {

    public static final String ACCESS_KEY = SpringUtils.getRequiredProperty("qiniu.accessKey");
    public static final String SECRET_KEY = SpringUtils.getRequiredProperty("qiniu.secretKey");
    public static final String BUCKET = SpringUtils.getRequiredProperty("qiniu.bucket");
    public static final Long EXPIRE_SECONDS = Long.parseLong(SpringUtils.getRequiredProperty("qiniu.expireSeconds"));   // 过期时间（秒）
    public static final String DOMAIN = SpringUtils.getRequiredProperty("qiniu.domain");   // 域名

    /**
     * 获取文件上传的token
     * @return token
     */
    public static String getToken() {
        StringMap putPolicy = new StringMap();
        Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY);
        return auth.uploadToken(BUCKET,null, EXPIRE_SECONDS, putPolicy);
    }

//    public static void main(String[] args) {
//        StringMap putPolicy = new StringMap();
//        Auth auth = Auth.create("MI4PDg9LYWXJyahzx5ec6-Ih0YNwQhew_BQUhttS", "Lk3fHHEnJuf0jD_Zte1xhtv7BTvjvmaWVCKd7O0J");
//        String s = auth.uploadToken("autosprout", null, 600L, putPolicy);
//        System.out.println(s);
//    }

}
