号簿助手 v4.6.31版本的 MD5 值为:9d7ff98a6bb5cc178eac2df4d1b2f0e0
以下内容为反编译后的 SDKHttpUtils.java 源代码,内容仅作参考
package im.yixin.sdk.util;
import android.net.Uri;
import android.os.Build;
import android.util.Log;
import com.chinatelecom.pim.core.IConstant;
import com.yulore.superyellowpage.db.DatabaseStruct;
import im.yixin.sdk.api.IYXAPI;
import im.yixin.sdk.api.YXAPIFactory;
import im.yixin.sdk.api.YXFileMessageData;
import im.yixin.sdk.api.YXImageMessageData;
import im.yixin.sdk.api.YXMessage;
import im.yixin.sdk.api.YXMusicMessageData;
import im.yixin.sdk.api.YXTextMessageData;
import im.yixin.sdk.api.YXVideoMessageData;
import im.yixin.sdk.api.YXWebPageMessageData;
import java.util.Map;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpProtocolParams;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
public class SDKHttpUtils {
private static final String DEFAULT_AGENT = "yixin_sdk_httputils/0.00";
private static final String ERROR_LOG_URL = "http://open.yixin.im/sdk/log?log=";
private static final String TAG = "SDKHttpUtils";
private static SDKHttpUtils instance;
private DefaultHttpClient client;
private SDKHttpUtils() {
BasicHttpParams basicHttpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(basicHttpParams, 20000);
HttpConnectionParams.setSoTimeout(basicHttpParams, 60000);
HttpConnectionParams.setSocketBufferSize(basicHttpParams, 8192);
HttpProtocolParams.setUseExpectContinue(basicHttpParams, true);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme(HttpHost.DEFAULT_SCHEME_NAME, PlainSocketFactory.getSocketFactory(), 80));
this.client = new DefaultHttpClient(new ThreadSafeClientConnManager(basicHttpParams, schemeRegistry), basicHttpParams);
}
private HttpEntity getEntity(String str, Map<String, String> map) throws Exception {
HttpGet httpGet = new HttpGet(str);
httpGet.setHeader(HTTP.USER_AGENT, DEFAULT_AGENT);
if (map != null) {
for (String str2 : map.keySet()) {
httpGet.setHeader(str2, map.get(str2));
}
}
try {
HttpResponse execute = this.client.execute(httpGet);
StatusLine statusLine = execute.getStatusLine();
if (statusLine == null) {
Log.e(TAG, "StatusLine is null");
throw new Exception("SDKHttpUtils getEntity StatusLine is null");
}
int statusCode = statusLine.getStatusCode();
if (statusCode < 200 || statusCode > 300) {
throw new Exception("SDKHttpUtils getEntity statusCode=" + statusCode);
}
return execute.getEntity();
} catch (Exception e) {
Log.e(TAG, "SDKHttpUtils getEntity data error", e);
throw e;
}
}
public static synchronized SDKHttpUtils getInstance() {
SDKHttpUtils sDKHttpUtils;
synchronized (SDKHttpUtils.class) {
if (instance == null) {
instance = new SDKHttpUtils();
}
sDKHttpUtils = instance;
}
return sDKHttpUtils;
}
public String get(String str, Map<String, String> map) throws Exception {
try {
return EntityUtils.toString(getEntity(str, map));
} catch (Exception e) {
Log.e(TAG, "SDKHttpUtils get data error", e);
throw e;
}
}
public String get4ErrorLog(Class cls, Class cls2, String str) {
String str2 = "check error " + str;
SDKLogger.e(cls, str2);
StringBuilder sb = new StringBuilder();
sb.append("android").append(Build.VERSION.RELEASE).append(";");
sb.append("sdk").append(YixinConstants.VALUE_SDK_VERSION).append(";");
IYXAPI yXAPIFactory = YXAPIFactory.getInstance();
if (yXAPIFactory != null) {
sb.append(yXAPIFactory.getAppId()).append(";");
}
if (cls2 == YXFileMessageData.class) {
sb.append("file");
} else if (cls2 == YXTextMessageData.class) {
sb.append(IConstant.Message.Mms.Part.TEXT);
} else if (cls2 == YXImageMessageData.class) {
sb.append(DatabaseStruct.RECOGNIZE.IMAGE);
} else if (cls2 == YXMusicMessageData.class) {
sb.append("music");
} else if (cls2 == YXVideoMessageData.class) {
sb.append("video");
} else if (cls2 == YXWebPageMessageData.class) {
sb.append("webpage");
} else if (cls2 == YXMessage.class) {
sb.append("message");
}
sb.append(";");
sb.append(str2);
try {
return get(ERROR_LOG_URL + Uri.encode(sb.toString()), null);
} catch (Exception e) {
Log.e(TAG, "SDKHttpUtils getStream error: " + sb.toString(), e);
return null;
}
}
public String get4ErrorLog(Class cls, String str) {
return get4ErrorLog(cls, cls, str);
}
}