陈奇
2019-05-29 c5bf501d8b507d1e3e79541e7ac9b45910860b4d
app/src/main/java/com/moral/yunfushao/httputils/HttpUtils.java
@@ -26,6 +26,7 @@
public class HttpUtils {
    /**
     * Get请求
     *
     * @param url
     * @param params
     * @param cacheMode
@@ -53,13 +54,14 @@
                    public void onSuccess(String s, Call call, Response response) {
                        XLog.e("result:" + s);
                        try {
                            JSONObject jsonObject = new JSONObject(s);
                            JSONObject resJosn = new JSONObject(s);
                            JSONObject jsonObject = resJosn.getJSONObject("data");
                            int errno = jsonObject.optInt("code");
                            String message = jsonObject.optString("desc");
                            if(errno == 0){
                                httpCallBack.onSuccess(jsonObject.optString("content"),message);
                            }else{
                                httpCallBack.onFail(errno,message);
                            String message = jsonObject.optString("msg");
                            if (errno == 0) {
                                httpCallBack.onSuccess(jsonObject.optString("info"), message);
                            } else {
                                httpCallBack.onFail(errno, message);
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
@@ -108,6 +110,7 @@
    /**
     * Post请求
     *
     * @param url
     * @param params
     * @param cacheMode
@@ -135,15 +138,22 @@
                    public void onSuccess(String s, Call call, Response response) {
                        XLog.e("result:" + s);
                        try {
                            JSONObject jsonObject = new JSONObject(s);
                            int errno = jsonObject.optInt("code");
                            String message = jsonObject.optString("desc");
                            if(errno == 0){
                                httpCallBack.onSuccess(jsonObject.optString("content"),message);
                            }else{
                                httpCallBack.onFail(errno,message);
                            JSONObject resJosn = new JSONObject(s);
                            if (resJosn.has("data")) {
                                JSONObject jsonObject = resJosn.getJSONObject("data");
                                int errno = jsonObject.optInt("code");
                                String message = jsonObject.optString("msg");
                                if (jsonObject.length() == 0 || errno == 0) {
                                    httpCallBack.onSuccess(jsonObject.optString("info"), message);
                                } else {
                                    httpCallBack.onFail(errno, message);
                                }
                            } else {
                                XLog.e("result jsonObject:");
                            }
                        } catch (JSONException e) {
                            httpCallBack.onFail(503, e.getMessage());
                            XLog.e("result jsonObject:" + e);
                            e.printStackTrace();
                        }
@@ -186,6 +196,7 @@
    /**
     * 上传文件
     *
     * @param url
     * @param params
     * @param uploadCallBack
@@ -209,12 +220,13 @@
                    public void onSuccess(String s, Call call, Response response) {
                        XLog.e("result:" + s);
                        try {
                            JSONObject jsonObject = new JSONObject(s);
                            int errno = jsonObject.optInt("errno");
                            String message = jsonObject.optString("message");
                            if(errno == 0){
                                uploadCallBack.onSuccess(jsonObject.optString("data"),message);
                            }else{
                            JSONObject resJosn = new JSONObject(s);
                            JSONObject jsonObject = resJosn.getJSONObject("data");
                            int errno = jsonObject.optInt("code");
                            String message = jsonObject.optString("msg");
                            if (errno == 0) {
                                uploadCallBack.onSuccess(jsonObject.optString("info"), message);
                            } else {
                                uploadCallBack.onFail(message);
                            }
                        } catch (JSONException e) {
@@ -265,6 +277,7 @@
    /**
     * 上传文件
     *
     * @param url
     * @param params
     * @param uploadCallBack
@@ -290,12 +303,13 @@
                    public void onSuccess(String s, Call call, Response response) {
                        XLog.e("result:" + s);
                        try {
                            JSONObject jsonObject = new JSONObject(s);
                            int errno = jsonObject.optInt("errno");
                            String message = jsonObject.optString("message");
                            if(errno == 0){
                                uploadCallBack.onSuccess(jsonObject.optString("data"),message);
                            }else{
                            JSONObject resJosn = new JSONObject(s);
                            JSONObject jsonObject = resJosn.getJSONObject("data");
                            int errno = jsonObject.optInt("code");
                            String message = jsonObject.optString("msg");
                            if (errno == 0) {
                                uploadCallBack.onSuccess(jsonObject.optString("info"), message);
                            } else {
                                uploadCallBack.onFail(message);
                            }
                        } catch (JSONException e) {