| | |
| | | public class HttpUtils { |
| | | /** |
| | | * Get请求 |
| | | * |
| | | * @param url |
| | | * @param params |
| | | * @param cacheMode |
| | |
| | | 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(); |
| | |
| | | |
| | | /** |
| | | * Post请求 |
| | | * |
| | | * @param url |
| | | * @param params |
| | | * @param cacheMode |
| | |
| | | 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(); |
| | | } |
| | | |
| | |
| | | |
| | | /** |
| | | * 上传文件 |
| | | * |
| | | * @param url |
| | | * @param params |
| | | * @param uploadCallBack |
| | |
| | | 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) { |
| | |
| | | |
| | | /** |
| | | * 上传文件 |
| | | * |
| | | * @param url |
| | | * @param params |
| | | * @param uploadCallBack |
| | |
| | | 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) { |