OurPlay v5.5.9版本的 MD5 值为:d4e139798f4c2243a1145c8af5e21046
以下内容为反编译后的 a.java 源代码,内容仅作参考
package com.excelliance.kxqp.gs.qiniu;
import android.content.Context;
import android.graphics.Bitmap;
import android.text.TextUtils;
import com.excelliance.kxqp.gs.util.ab;
import com.excelliance.kxqp.gs.util.bd;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.apache.http.protocol.HTTP;
import org.json.JSONException;
import org.json.JSONObject;
public class a {
private static final String f7984a = UUID.randomUUID().toString();
private int f7985b;
private Map<String, Object> c;
private Bitmap d;
private String e;
private String f;
private a(C0324a c0324a) {
this.f7985b = c0324a.f7988a;
this.c = c0324a.f7989b;
this.d = c0324a.c;
this.e = c0324a.d;
this.f = c0324a.e;
}
public String a(Context context) {
CDNData a2;
QiniuToken a3 = a();
if (a3 == null || (a2 = a(context, a3)) == null) {
return null;
}
return a3.uploadDomain + a2.key;
}
private QiniuToken a() {
String b2;
if (this.d == null) {
return null;
}
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("userid", this.f7985b);
if (this.c != null) {
for (Map.Entry<String, Object> entry : this.c.entrySet()) {
jSONObject.put(entry.getKey(), entry.getValue());
}
}
} catch (JSONException e) {
e.printStackTrace();
}
String a2 = bd.a("http://api.ourplay.com.cn/user/getuploadtoken", jSONObject.toString());
if (a2 != null && (b2 = ab.b(a2, "utf-8")) != null) {
try {
QiniuResponse qiniuResponse = (QiniuResponse) new Gson().a(b2, new TypeToken<QiniuResponse<QiniuToken>>() {
}.getType());
if (qiniuResponse != null) {
com.excelliance.kxqp.util.b.a.i("QiniuUploadTask", "token is " + qiniuResponse.toString());
return (QiniuToken) qiniuResponse.data;
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
return null;
}
private CDNData a(Context context, QiniuToken qiniuToken) {
String b2 = b();
File a2 = a(context, this.d, this.e, b2);
if (a2 == null) {
return null;
}
com.excelliance.kxqp.util.b.a.d("QiniuUploadTask", "cache file: " + a2.getAbsolutePath());
HashMap hashMap = new HashMap();
hashMap.put("key", "xspace/" + this.f + "/" + b2);
hashMap.put("token", qiniuToken.token);
HashMap hashMap2 = new HashMap();
hashMap2.put(a2.getName(), a2);
String a3 = a(qiniuToken.uploadPath, hashMap, hashMap2);
if (a3 != null) {
try {
CDNData cDNData = (CDNData) new Gson().a(a3, new TypeToken<CDNData>() {
}.getType());
if (cDNData != null) {
com.excelliance.kxqp.util.b.a.i("QiniuUploadTask", "cdnData is " + cDNData.key + " and " + cDNData.hash);
return cDNData;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
private String b() {
return this.e + "_" + this.f7985b + "_" + String.valueOf(System.currentTimeMillis()) + ".jpg";
}
private File a(Context context, Bitmap bitmap, String str, String str2) {
File file = new File(context.getExternalCacheDir() + "/" + str);
if (!file.exists()) {
file.mkdirs();
}
File file2 = new File(context.getExternalCacheDir() + "/" + str + "/" + str2);
if (!file2.exists()) {
try {
file2.createNewFile();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
try {
FileOutputStream fileOutputStream = new FileOutputStream(file2);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
fileOutputStream.flush();
fileOutputStream.close();
return file2;
} catch (Exception unused) {
return null;
}
}
private String a(String str, Map<String, String> map, Map<String, File> map2) {
HttpURLConnection httpURLConnection;
try {
try {
httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
try {
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setReadTimeout(8000);
httpURLConnection.setConnectTimeout(8000);
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
httpURLConnection.setUseCaches(false);
httpURLConnection.setRequestProperty("Connection", HTTP.CONN_KEEP_ALIVE);
httpURLConnection.setRequestProperty("Charset", "UTF-8");
httpURLConnection.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + f7984a);
DataOutputStream dataOutputStream = new DataOutputStream(httpURLConnection.getOutputStream());
dataOutputStream.writeBytes(a(map).toString());
dataOutputStream.flush();
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, File> entry : map2.entrySet()) {
sb.append("--");
sb.append(f7984a);
sb.append("\r\n");
sb.append("Content-Disposition: form-data; name=\"file\"; filename=\"" + entry.getKey() + "\"\r\n");
sb.append("Content-Type: application/octet-stream\r\n");
sb.append("Content-Transfer-Encoding: binary\r\n");
sb.append("\r\n");
dataOutputStream.writeBytes(sb.toString());
dataOutputStream.flush();
FileInputStream fileInputStream = new FileInputStream(entry.getValue());
byte[] bArr = new byte[1024];
while (true) {
int read = fileInputStream.read(bArr);
if (read != -1) {
dataOutputStream.write(bArr, 0, read);
}
}
fileInputStream.close();
dataOutputStream.writeBytes("\r\n");
}
dataOutputStream.writeBytes("--" + f7984a + "--\r\n");
dataOutputStream.flush();
dataOutputStream.close();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
StringBuilder sb2 = new StringBuilder();
while (true) {
String readLine = bufferedReader.readLine();
if (readLine == null) {
break;
}
sb2.append(readLine);
}
String sb3 = sb2.toString();
if (httpURLConnection != null) {
httpURLConnection.disconnect();
}
return sb3;
} catch (Exception e) {
e = e;
e.printStackTrace();
if (httpURLConnection != null) {
httpURLConnection.disconnect();
}
return null;
}
} catch (Throwable th) {
th = th;
if (str != 0) {
str.disconnect();
}
throw th;
}
} catch (Exception e2) {
e = e2;
httpURLConnection = null;
} catch (Throwable th2) {
th = th2;
str = 0;
if (str != 0) {
}
throw th;
}
}
private StringBuilder a(Map<String, String> map) {
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, String> entry : map.entrySet()) {
sb.append("--");
sb.append(f7984a);
sb.append("\r\n");
sb.append("Content-Disposition: form-data; name=\"" + entry.getKey() + "\"\r\n");
sb.append("Content-Type: text/plain; charset=utf-8\r\n");
sb.append("Content-Transfer-Encoding: 8bit\r\n");
sb.append("\r\n");
sb.append(entry.getValue());
sb.append("\r\n");
}
return sb;
}
public static class C0324a {
int f7988a;
Map<String, Object> f7989b;
Bitmap c;
String d;
String e;
public C0324a a(int i) {
this.f7988a = i;
return this;
}
public C0324a a(Bitmap bitmap) {
this.c = bitmap;
return this;
}
public C0324a a(String str) {
this.d = str;
return this;
}
public C0324a b(String str) {
this.e = str;
return this;
}
public a a() {
if (TextUtils.isEmpty(this.d)) {
this.d = "qiniuimage";
}
if (TextUtils.isEmpty(this.e)) {
this.e = "qiniuimage";
}
return new a(this);
}
}
}