标签:解析 idt 域名 mis null 3.5 manager htm operator
implementation ‘com.squareup.okhttp3:okhttp:3.8.0‘
implementation ‘com.squareup.okio:okio:1.13.0‘
implementation ‘com.qiniu:qiniu-android-sdk:7.3.12‘
implementation ‘com.squareup.okhttp3:okhttp:3.8.0‘
implementation ‘com.squareup.okio:okio:1.13.0‘
implementation ‘com.qiniu:qiniu-android-sdk:7.3.12‘
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
public class QiNiuUtils {
private static final String ACCESSKEY = "m1-qhAIzfk6_rNdWfvf5ngaybQva5CmzHl9-pccg";
private static final String SECRETKEY = "ZMFhkutPPZj86BbjV9O7RtDEs0XOQNlkPUYc-kIV";
private static final String BUCKET_NAME = "temp";//存储空间的名字
private static final String MAC_NAME = "HmacSHA1";
private static final String ENCODING = "UTF-8";
public static void upLoad(File file, String key,Configuration config,UpCompletionHandler handler) {
String token = QiNiuUtils.getToken();
new UploadManager(config).put(file, key, token, handler, null);
}
//获取Token
private static String getToken() {
JSONObject json = new JSONObject();
long deadline = System.currentTimeMillis() / 1000 + 3600 * 12;
try {
json.put("deadline", deadline);
json.put("scope", BUCKET_NAME);
} catch (JSONException e) {
e.printStackTrace();
}
String encodedPutPolicy = UrlSafeBase64.encodeToString(json.toString());
byte[] sign = null;
try {
sign = hmacsha1encrypt(encodedPutPolicy, SECRETKEY);
} catch (Exception e) {
e.printStackTrace();
}
String encodedSign = UrlSafeBase64.encodeToString(sign);
return ACCESSKEY + ‘:‘ + encodedSign + ‘:‘ + encodedPutPolicy;
}
private static byte[] hmacsha1encrypt(String encryptText, String encryptKey) throws Exception {
byte[] data = encryptKey.getBytes(ENCODING);
SecretKeySpec secretKey = new SecretKeySpec(data, MAC_NAME);
Mac mac = Mac.getInstance(MAC_NAME);
mac.init(secretKey);
byte[] text = encryptText.getBytes(ENCODING);
return mac.doFinal(text);
}
}
x
public class QiNiuUtils {
private static final String ACCESSKEY = "m1-qhAIzfk6_rNdWfvf5ngaybQva5CmzHl9-pccg";
private static final String SECRETKEY = "ZMFhkutPPZj86BbjV9O7RtDEs0XOQNlkPUYc-kIV";
private static final String BUCKET_NAME = "temp";//存储空间的名字
private static final String MAC_NAME = "HmacSHA1";
private static final String ENCODING = "UTF-8";
public static void upLoad(File file, String key,Configuration config,UpCompletionHandler handler) {
String token = QiNiuUtils.getToken();
new UploadManager(config).put(file, key, token, handler, null);
}
//获取Token
private static String getToken() {
JSONObject json = new JSONObject();
long deadline = System.currentTimeMillis() / 1000 + 3600 * 12;
try {
json.put("deadline", deadline);
json.put("scope", BUCKET_NAME);
} catch (JSONException e) {
e.printStackTrace();
}
String encodedPutPolicy = UrlSafeBase64.encodeToString(json.toString());
byte[] sign = null;
try {
sign = hmacsha1encrypt(encodedPutPolicy, SECRETKEY);
} catch (Exception e) {
e.printStackTrace();
}
String encodedSign = UrlSafeBase64.encodeToString(sign);
return ACCESSKEY + ‘:‘ + encodedSign + ‘:‘ + encodedPutPolicy;
}
private static byte[] hmacsha1encrypt(String encryptText, String encryptKey) throws Exception {
byte[] data = encryptKey.getBytes(ENCODING);
SecretKeySpec secretKey = new SecretKeySpec(data, MAC_NAME);
Mac mac = Mac.getInstance(MAC_NAME);
mac.init(secretKey);
byte[] text = encryptText.getBytes(ENCODING);
return mac.doFinal(text);
}
}
Configuration config = new Configuration.Builder().build();
String fileName = file.getName();
QiNiuUtils.upLoad(file, fileName, config, (key, info, response) -> {
//用户自定义的内容上传完成后处理动作必须实现的方法,建议用户自己处理异常。若未处理,抛出的异常被直接丢弃。
Log.i("bqt", "文件上传保存名称:" + key);
Log.i("bqt", "上传完成返回日志信息:\n" + new Gson().toJson(info));
Log.i("bqt", "上传完成的回复内容:\n" + response);
});
x
Configuration config = new Configuration.Builder().build();
String fileName = file.getName();
QiNiuUtils.upLoad(file, fileName, config, (key, info, response) -> {
//用户自定义的内容上传完成后处理动作必须实现的方法,建议用户自己处理异常。若未处理,抛出的异常被直接丢弃。
Log.i("bqt", "文件上传保存名称:" + key);
Log.i("bqt", "上传完成返回日志信息:\n" + new Gson().toJson(info));
Log.i("bqt", "上传完成的回复内容:\n" + response);
});
文件上传保存名称:sms_2018.09.08-16_02_09.txt
上传完成返回日志信息
{
"duration": 923,
"host": "upload.qiniup.com",
"id": "1536393734861932",
"ip": "111.177.9.136",
"path": "/",
"port": 80,
"reqId": "BwMAAOKFEJb2XVIV",
"response": {
"nameValuePairs": {
"hash": "FhX-pWNc1ThcCCVIryzKZQyRQhsq",
"key": "sms_2018.09.08-16_02_09.txt"
}
},
"sent": 422819,
"statusCode": 200,
"timeStamp": 1536393736,
"totalSize": 422098,
"upToken": {
"accessKey": "m1-qhAIzfk6_rNdWfvf5ngaybQva5CmzHl9-pccg",
"returnUrl": "",
"token": "..."
},
"xlog": "...",
"xvia": "vdn-hbxy-tel-1-1"
}
上传完成的回复内容
{
"hash": "FhX-pWNc1ThcCCVIryzKZQyRQhsq",
"key": "sms_2018.09.08-16_02_09.txt"
}
文件上传保存名称:sms_2018.09.08-16_02_09.txt
上传完成返回日志信息
{
"duration": 923,
"host": "upload.qiniup.com",
"id": "1536393734861932",
"ip": "111.177.9.136",
"path": "/",
"port": 80,
"reqId": "BwMAAOKFEJb2XVIV",
"response": {
"nameValuePairs": {
"hash": "FhX-pWNc1ThcCCVIryzKZQyRQhsq",
"key": "sms_2018.09.08-16_02_09.txt"
}
},
"sent": 422819,
"statusCode": 200,
"timeStamp": 1536393736,
"totalSize": 422098,
"upToken": {
"accessKey": "m1-qhAIzfk6_rNdWfvf5ngaybQva5CmzHl9-pccg",
"returnUrl": "",
"token": "..."
},
"xlog": "...",
"xvia": "vdn-hbxy-tel-1-1"
}
上传完成的回复内容
{
"hash": "FhX-pWNc1ThcCCVIryzKZQyRQhsq",
"key": "sms_2018.09.08-16_02_09.txt"
}
sago
m1-qhAIzfk6_rNdWfvf5ngaybQva5CmzHl9-pccg
ZMFhkutPPZj86BbjV9O7RtDEs0XOQNlkPUYc-kIV
oxns24xcm.bkt.clouddn.com
如:http://oxns24xcm.bkt.clouddn.com/bqt.jpg
x
sago
m1-qhAIzfk6_rNdWfvf5ngaybQva5CmzHl9-pccg
ZMFhkutPPZj86BbjV9O7RtDEs0XOQNlkPUYc-kIV
oxns24xcm.bkt.clouddn.com
如:http://oxns24xcm.bkt.clouddn.com/bqt.jpg
标签:解析 idt 域名 mis null 3.5 manager htm operator
原文地址:https://www.cnblogs.com/baiqiantao/p/9610093.html