package com.lyms.cm.qiniu;
import org.json.JSONException;
import javax.servlet.http.HttpServletRequest;
import java.util.UUID;
public class Uptoken {
public final static String makeUptoken(HttpServletRequest request) throws AuthException,
JSONException {
// System.out.println("请求路径:"+requestURL);
Mac mac = new Mac(Config.ACCESS_KEY, Config.SECRET_KEY);
String bucketName = Config.BUCKET_NAME;
PutPolicy putPolicy = new PutPolicy(bucketName);
// 可以根据自己需要设置过期时间,sdk默认有设置,具体看源码
// putPolicy.expires = getDeadLine();
putPolicy.returnUrl = "http://"+request.getServerName()+request.getContextPath()+"/ueditor/callBack";
System.out.println("请求路径:http://"+request.getServerName()+request.getContextPath()+"/ueditor/callBack");
putPolicy.returnBody = "{\"name\": $(fname),\"size\": \"$(fsize)\",\"w\": \"$(imageInfo.width)\",\"h\": \"$(imageInfo.height)\",\"key\":$(etag)}";
String uptoken = putPolicy.token(mac);
return uptoken;
}
/**
* 生成32位UUID 并去掉"-"
*/
public static String getUUID() {
return UUID.randomUUID().toString().replaceAll("-", "");
}
}