Commit d64ad425 by 郑娜伟

升级net 1.1.1

parent 532268f3
......@@ -12,7 +12,8 @@ import com.sobot.common.ui.base.SobotBaseActivity;
import com.sobot.common.ui.toast.SobotToastUtil;
import com.sobot.common.utils.SobotCommonApi;
import com.sobot.common.utils.SobotImageUtils;
import com.sobot.network.http.HttpUtils;
import com.sobot.network.apiUtils.SobotHttpUtils;
import com.sobot.network.http.HttpBaseUtils;
import com.sobot.network.http.db.SobotDownloadManager;
import com.sobot.pictureframe.SobotBitmapUtil;
import com.sobot.utils.SobotLogUtils;
......@@ -43,6 +44,7 @@ public class MainActivity extends SobotBaseActivity {
@Override
protected void initView() {
SobotToastUtil.showCustomToast(getSobotBaseActivity(), "sdafdsafsadfasdfsdaf");
SobotCommonApi.setSwitchMarkStatus(SobotMarkConfig.SHOW_PERMISSION_TIPS_POP, true);
setTitle("ddddd");
......@@ -54,7 +56,7 @@ public class MainActivity extends SobotBaseActivity {
// img2.setScaleType(ImageView.ScaleType.FIT_XY);
// SobotBitmapUtil.display(this,"https://img.sobot.com/chatres/75574e5fa29a48458d1f57ab5489a4c5/msg/20220421/34a466420d78fa1172bc0acd85166745/9410b53be86b4d589c61c60f6aee2461.jpeg",img2);
File save=new File(SobotSDCardUtils.getSDCardRootPath(MainActivity.this)+"/9410b53be86b4d589c61c60f6aee2461.jpeg");
HttpUtils.getInstance().download("https://img.sobot.com/chatres/75574e5fa29a48458d1f57ab5489a4c5/msg/20220421/34a466420d78fa1172bc0acd85166745/9410b53be86b4d589c61c60f6aee2461.jpeg", save, new HttpUtils.FileCallBack() {
HttpBaseUtils.getInstance().download("https://img.sobot.com/chatres/75574e5fa29a48458d1f57ab5489a4c5/msg/20220421/34a466420d78fa1172bc0acd85166745/9410b53be86b4d589c61c60f6aee2461.jpeg", save, new HttpBaseUtils.FileCallBack() {
@Override
public void onResponse(File result) {
Bitmap bitmap= SobotBitmapUtil.compress(result.getPath(),MainActivity.this,true);
......@@ -87,22 +89,22 @@ SobotLogUtils.i("下载进度:"+progress);
map.put("groupId", "36b0f8eb2de948d99e89c8f0c3d92e68_5");
map.put("agentPhoneNum", "18600978969");
// HttpUtils.getInstance().doPostByJsonString(this, "https://sobot.com/comm/api/4/call/agentOnWork?access_token=c273b74c-3b37-48cf-937f-9c46940cc19d", map, null, new HttpUtils.StringCallBack() {
// @Override
// public void onResponse(String result) {
// SobotLogUtils.i(result);
// }
//
// @Override
// public void onError(Exception e, String msg, int responseCode) {
//
// }
//
// @Override
// public void inProgress(int progress) {
//
// }
// });
SobotHttpUtils.doPostByJsonString(this, "https://sobot.com/comm/api/4/call/agentOnWork?access_token=c273b74c-3b37-48cf-937f-9c46940cc19d", map, null, new HttpBaseUtils.StringCallBack() {
@Override
public void onResponse(String result) {
SobotLogUtils.i(result);
}
@Override
public void onError(Exception e, String msg, int responseCode) {
}
@Override
public void inProgress(int progress) {
}
});
// selectPicFromLocal();
// selectVedioFromLocal();
// openCamera();
......
......@@ -5,9 +5,14 @@ import android.support.multidex.MultiDex;
import com.sobot.common.ui.SobotMarkConfig;
import com.sobot.common.utils.SobotCommonApi;
import com.sobot.network.http.SobotOkHttpUtils;
import com.sobot.network.http.log.SobotNetLogUtils;
import com.sobot.utils.SobotLogUtils;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;
/**
* @Description: java类作用描述
* @Author: znw
......@@ -20,7 +25,7 @@ public class MyApp extends Application {
super.onCreate();
// 主要是添加下面这句代码
MultiDex.install(this);
SobotCommonApi.init(this);
SobotCommonApi.init(this,"https://sobot.com");
SobotCommonApi.setShowLogDebug(true);
SobotCommonApi.setSwitchMarkStatus(SobotMarkConfig.LANDSCAPE_SCREEN,false);
......
......@@ -19,9 +19,9 @@ dependencies {
// api project(':sobot_network')
// api project(':sobot_json')
api 'com.sobot.library:utils:1.1'
api 'com.sobot.library:utils:1.1.0'
api 'com.sobot.library:picture:1.1'
api 'com.sobot.library:net:1.1.0'
api 'com.sobot.library:net:1.1.1'
api 'com.sobot.library:json:1.1'
// api 'com.sobot.library:utils:1.1'
......
......@@ -13,7 +13,7 @@ ext {
PUBLISH_GROUP_ID = "com.sobot.library" //项目包名
PUBLISH_ARTIFACT_ID = 'sobotcommon' //项目名
// PUBLISH_ARTIFACT_ID = 'sobotcommon_x' //项目名
PUBLISH_VERSION = '1.1.3' //版本号
PUBLISH_VERSION = '1.1.5' //版本号
}
......
......@@ -17,7 +17,20 @@ public class SobotCommonApi {
*/
public static void init(Application application) {
if (application != null) {
SobotHttpUtils.init(application);
SobotHttpUtils.init(application, "");
SobotGlobalContext.init(application);
}
}
/**
* 初始化 可以校验服务器域名
*
* @param application
* @param baseUrl 服务器接口的校验域名 例如(https://www.sobot.com)
*/
public static void init(Application application, String baseUrl) {
if (application != null) {
SobotHttpUtils.init(application, baseUrl);
SobotGlobalContext.init(application);
}
}
......
......@@ -11,7 +11,7 @@ android {
//这里就是打jar包
task makeJar(type: Copy) {
//删除旧的jar包
delete 'build/libs/sobot_net_1.1.0.jar'
delete 'build/libs/sobot_net_1.1.1.jar'
//原地址
from('build/intermediates/packaged-classes/release/')
//导出jar包的地址
......@@ -19,7 +19,7 @@ android {
//包含的jar包
include('classes.jar')
//重命名jar包为mysdk
rename ('classes.jar', 'sobot_net_1.1.0.jar')
rename ('classes.jar', 'sobot_net_1.1.1.jar')
}
makeJar.dependsOn(build)
}
......
......@@ -12,7 +12,7 @@ task androidSourcesJar(type: Jar) {
ext {
PUBLISH_GROUP_ID = "com.sobot.library" //项目包名
PUBLISH_ARTIFACT_ID = 'net' //项目名
PUBLISH_VERSION = '1.1.0' //版本号
PUBLISH_VERSION = '1.1.1' //版本号
}
......
......@@ -2,13 +2,19 @@ package com.sobot.network.apiUtils;
import android.content.Context;
import android.text.TextUtils;
import com.sobot.network.http.HttpUtils;
import com.sobot.network.http.HttpBaseUtils;
import com.sobot.network.http.SobotOkHttpUtils;
import com.sobot.network.http.log.SobotNetLogUtils;
import java.io.IOException;
import java.util.Map;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession;
import okhttp3.MediaType;
import okhttp3.Response;
......@@ -17,38 +23,38 @@ public class SobotHttpUtils {
// ##################### 网络请求 #########################
public static void doPost(Object cancelTag, String url, Map<String, String> paramsMap,
HttpUtils.StringCallBack call) {
HttpUtils.getInstance().doPost(cancelTag, url, paramsMap, null, call);
HttpBaseUtils.StringCallBack call) {
HttpBaseUtils.getInstance().doPost(cancelTag, url, paramsMap, null, call);
}
public static void doPost(Object cancelTag, String url, Map<String, String> paramsMap, Map<String, String> headerMap,
HttpUtils.StringCallBack call) {
HttpUtils.getInstance().doPost(cancelTag, url, paramsMap, headerMap, call);
HttpBaseUtils.StringCallBack call) {
HttpBaseUtils.getInstance().doPost(cancelTag, url, paramsMap, headerMap, call);
}
public static void doPostByString(Object cancelTag, String url, Map<String, String> paramsMap, Map<String, String> headerMap, MediaType mediaType,
HttpUtils.StringCallBack call) {
HttpUtils.getInstance().doPostByString(cancelTag, url, paramsMap, headerMap, mediaType, call);
HttpBaseUtils.StringCallBack call) {
HttpBaseUtils.getInstance().doPostByString(cancelTag, url, paramsMap, headerMap, mediaType, call);
}
public static void doPostByJsonString(Object cancelTag, String url, Map<String, String> paramsMap, Map<String, String> headerMap,
HttpUtils.StringCallBack call) {
HttpUtils.getInstance().doPostByJsonString(cancelTag, url, paramsMap, headerMap, call);
HttpBaseUtils.StringCallBack call) {
HttpBaseUtils.getInstance().doPostByJsonString(cancelTag, url, paramsMap, headerMap, call);
}
public static void doGet(Object cancelTag, String url, Map<String, String> paramsMap,
HttpUtils.StringCallBack call) {
HttpUtils.getInstance().doGet(cancelTag, url, paramsMap, null, call);
HttpBaseUtils.StringCallBack call) {
HttpBaseUtils.getInstance().doGet(cancelTag, url, paramsMap, null, call);
}
public static void doGet(Object cancelTag, String url, Map<String, String> paramsMap, Map<String, String> headerMap,
HttpUtils.StringCallBack call) {
HttpUtils.getInstance().doGet(cancelTag, url, paramsMap, headerMap, call);
HttpBaseUtils.StringCallBack call) {
HttpBaseUtils.getInstance().doGet(cancelTag, url, paramsMap, headerMap, call);
}
//同步请求
public static Response doPostSync(Object cancelTag, String url, Map<String, String> paramsMap, Map<String, String> headerMap) throws IOException {
return HttpUtils.getInstance().doPostSync(cancelTag, url, paramsMap, headerMap);
return HttpBaseUtils.getInstance().doPostSync(cancelTag, url, paramsMap, headerMap);
}
......@@ -61,7 +67,7 @@ public class SobotHttpUtils {
* @param callBack
*/
public static void uploadFile(Object cancelTag, String url, Map<String, String> paramsMap, Map<String, String> headerMap,
final String filePath, HttpUtils.StringCallBack callBack) {
final String filePath, HttpBaseUtils.StringCallBack callBack) {
///////////////////////////////////////////////////////
if (paramsMap != null) {
// 基本传递参数
......@@ -73,7 +79,7 @@ public class SobotHttpUtils {
SobotNetLogUtils.i(sb.toString().substring(0, sb.toString().length() - 2));
}
HttpUtils.getInstance().uploadFile(cancelTag, url, paramsMap, headerMap, filePath, callBack);
HttpBaseUtils.getInstance().uploadFile(cancelTag, url, paramsMap, headerMap, filePath, callBack);
}
......@@ -87,13 +93,26 @@ public class SobotHttpUtils {
* 初始化
*
* @param context
* @param baseUrl 服务器接口的校验域名 例如(http://www.sobot.com)
*/
public static void init(Context context) {
public static void init(Context context, final String baseUrl) {
if (context == null) {
SobotNetLogUtils.e("SobotHttpUtils init: context is null, please check!");
} else {
Context applicationContext = context.getApplicationContext();
SobotHttpGlobalContext.getInstance(applicationContext);
}
SobotOkHttpUtils.getInstance().setHostNameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
if (!TextUtils.isEmpty(baseUrl) && baseUrl.contains(hostname)) {
return true;
} else {
HostnameVerifier hv = HttpsURLConnection.getDefaultHostnameVerifier();
boolean verifyResult = hv.verify(hostname, session);
return verifyResult;
}
}
});
}
}
\ No newline at end of file
......@@ -23,15 +23,15 @@ import okhttp3.Call;
import okhttp3.MediaType;
import okhttp3.Response;
public class HttpUtils {
private static HttpUtils client = null;
public class HttpBaseUtils {
private static HttpBaseUtils client = null;
private HttpUtils() {
private HttpBaseUtils() {
}
public static HttpUtils getInstance() {
public static HttpBaseUtils getInstance() {
if (client == null) {
client = new HttpUtils();
client = new HttpBaseUtils();
}
return client;
}
......
......@@ -24,9 +24,7 @@ import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
......@@ -49,12 +47,6 @@ public class SobotOkHttpUtils {
OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder();
okHttpClientBuilder.addInterceptor(new SobotInternetPermissionExceptionInterceptor());
mDelivery = new Handler(Looper.getMainLooper());
okHttpClientBuilder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
try {
//优化X509TrustManager安全警告问题
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
......@@ -142,6 +134,7 @@ public class SobotOkHttpUtils {
public static PostFormBuilder post() {
return new PostFormBuilder();
}
public static PostMultipartFormBuilder postMultipart() {
return new PostMultipartFormBuilder();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment