正在查看: 新暖心缘 v8.1.1 应用的 CdnManager.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: 新暖心缘 v8.1.1 应用的 CdnManager.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.qiniu.cdn;
import com.qiniu.cdn.CdnResult;
import com.qiniu.common.Constants;
import com.qiniu.common.QiniuException;
import com.qiniu.http.Client;
import com.qiniu.util.Auth;
import com.qiniu.util.Json;
import com.qiniu.util.StringMap;
import com.qiniu.util.StringUtils;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public final class CdnManager {
private static final int MAX_API_PREFETCH_URL_COUNT = 60;
private static final int MAX_API_REFRESH_DIR_COUNT = 10;
private static final int MAX_API_REFRESH_URL_COUNT = 60;
private final Auth auth;
private final Client client;
private final String server;
public CdnManager(Auth auth) {
this(auth, "http://fusion.qiniuapi.com");
}
public static String createTimestampAntiLeechUrl(URL url, String str, long j8) throws QiniuException {
String str2;
try {
String replaceAll = URLEncoder.encode(url.getPath(), "UTF-8").replaceAll("%2F", "/");
String query = url.getQuery();
if (query == null) {
str2 = replaceAll;
} else {
str2 = replaceAll + "?" + query;
}
URL url2 = new URL(url.getProtocol(), url.getHost(), url.getPort(), str2);
String hexString = Long.toHexString(j8);
String md5Lower = StringUtils.md5Lower(String.format("%s%s%s", str, replaceAll, hexString));
return url2.getQuery() != null ? String.format("%s&sign=%s&t=%s", url2, md5Lower, hexString) : String.format("%s?sign=%s&t=%s", url2, md5Lower, hexString);
} catch (Exception e8) {
throw new QiniuException(e8, "timestamp anti leech failed");
}
}
public CdnResult.BandwidthResult getBandwidthData(String[] strArr, String str, String str2, String str3) throws QiniuException {
HashMap hashMap = new HashMap();
hashMap.put("domains", StringUtils.join(strArr, ";"));
hashMap.put("startDate", str);
hashMap.put("endDate", str2);
hashMap.put("granularity", str3);
byte[] bytes = Json.encode(hashMap).getBytes(Constants.UTF_8);
String str4 = this.server + "/v2/tune/bandwidth";
return (CdnResult.BandwidthResult) this.client.post(str4, bytes, this.auth.authorizationV2(str4, "POST", bytes, "application/json"), "application/json").jsonToObject(CdnResult.BandwidthResult.class);
}
public CdnResult.LogListResult getCdnLogList(String[] strArr, String str) throws QiniuException {
HashMap hashMap = new HashMap();
hashMap.put("domains", StringUtils.join(strArr, ";"));
hashMap.put("day", str);
byte[] bytes = Json.encode(hashMap).getBytes(Constants.UTF_8);
String str2 = this.server + "/v2/tune/log/list";
return (CdnResult.LogListResult) this.client.post(str2, bytes, this.auth.authorizationV2(str2, "POST", bytes, "application/json"), "application/json").jsonToObject(CdnResult.LogListResult.class);
}
public CdnResult.FluxResult getFluxData(String[] strArr, String str, String str2, String str3) throws QiniuException {
HashMap hashMap = new HashMap();
hashMap.put("domains", StringUtils.join(strArr, ";"));
hashMap.put("startDate", str);
hashMap.put("endDate", str2);
hashMap.put("granularity", str3);
byte[] bytes = Json.encode(hashMap).getBytes(Constants.UTF_8);
String str4 = this.server + "/v2/tune/flux";
return (CdnResult.FluxResult) this.client.post(str4, bytes, this.auth.authorizationV2(str4, "POST", bytes, "application/json"), "application/json").jsonToObject(CdnResult.FluxResult.class);
}
public CdnResult.PrefetchResult prefetchUrls(String[] strArr) throws QiniuException {
if (strArr != null && strArr.length > 60) {
throw new QiniuException(new Exception("url count exceeds the max prefetch limit per request"));
}
HashMap hashMap = new HashMap();
hashMap.put("urls", strArr);
byte[] bytes = Json.encode(hashMap).getBytes(Constants.UTF_8);
String str = this.server + "/v2/tune/prefetch";
return (CdnResult.PrefetchResult) this.client.post(str, bytes, this.auth.authorizationV2(str, "POST", bytes, "application/json"), "application/json").jsonToObject(CdnResult.PrefetchResult.class);
}
public CdnResult.RefreshResult refreshDirs(String[] strArr) throws QiniuException {
return refreshUrlsAndDirs(null, strArr);
}
public CdnResult.RefreshResult refreshUrls(String[] strArr) throws QiniuException {
return refreshUrlsAndDirs(strArr, null);
}
public CdnResult.RefreshResult refreshUrlsAndDirs(String[] strArr, String[] strArr2) throws QiniuException {
if (strArr != null && strArr.length > 60) {
throw new QiniuException(new Exception("url count exceeds the max refresh limit per request"));
}
if (strArr2 != null && strArr2.length > 10) {
throw new QiniuException(new Exception("dir count exceeds the max refresh limit per request"));
}
HashMap hashMap = new HashMap();
if (strArr != null) {
hashMap.put("urls", strArr);
}
if (strArr2 != null) {
hashMap.put("dirs", strArr2);
}
byte[] bytes = Json.encode(hashMap).getBytes(Constants.UTF_8);
String str = this.server + "/v2/tune/refresh";
return (CdnResult.RefreshResult) this.client.post(str, bytes, this.auth.authorizationV2(str, "POST", bytes, "application/json"), "application/json").jsonToObject(CdnResult.RefreshResult.class);
}
private CdnManager(Auth auth, String str) {
this.auth = auth;
this.server = str;
this.client = new Client();
}
public CdnManager(Auth auth, String str, Client client) {
this.auth = auth;
this.server = str;
this.client = client;
}
public static String createTimestampAntiLeechUrl(String str, String str2, StringMap stringMap, String str3, long j8) throws QiniuException {
String format;
if (stringMap != null) {
try {
if (stringMap.size() > 0) {
ArrayList arrayList = new ArrayList();
for (Map.Entry<String, Object> entry : stringMap.map().entrySet()) {
arrayList.add(URLEncoder.encode(entry.getKey(), "utf-8") + "=" + URLEncoder.encode(entry.getValue().toString(), "utf-8"));
}
format = String.format("%s/%s?%s", str, str2, StringUtils.join(arrayList, "&"));
return createTimestampAntiLeechUrl(new URL(format), str3, j8);
}
} catch (Exception e8) {
throw new QiniuException(e8, "timestamp anti leech failed");
}
}
format = String.format("%s/%s", str, str2);
return createTimestampAntiLeechUrl(new URL(format), str3, j8);
}
}