package com.hjx.personalcenter.http; import android.app.Activity; import android.app.ProgressDialog; import android.content.Context; import android.content.Intent; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.KeyEvent; import android.widget.Toast; import com.google.gson.Gson; import com.hjx.personalcenter.R; import com.hjx.personalcenter.activity.LoginAndRegisterActivity; import com.hjx.personalcenter.activity.TheStartPageActivity; import com.hjx.personalcenter.db.Content; import com.hjx.personalcenter.db.SaveParam; import com.hjx.personalcenter.gson.GsonTool; import com.hjx.personalcenter.model.AppVersion; import com.hjx.personalcenter.model.CardInfo; import com.hjx.personalcenter.model.ChildsInfo; import com.hjx.personalcenter.model.CityInfo; import com.hjx.personalcenter.model.CountyInfo; import com.hjx.personalcenter.model.DefautPublishInfo; import com.hjx.personalcenter.model.GradeInfo; import com.hjx.personalcenter.model.PesonalInfo; import com.hjx.personalcenter.model.ProvinceInfo; import com.hjx.personalcenter.model.SchoolInfo; import com.hjx.personalcenter.model.SignInfo; import com.hjx.personalcenter.model.VersionInfo; import com.hjx.personalcenter.model.VideoInfo; import com.hjx.personalcenter.util.AlertUtils; import com.hjx.personalcenter.util.DialogPermission; import com.loopj.android.http.AsyncHttpResponseHandler; import com.loopj.android.http.JsonHttpResponseHandler; import com.loopj.android.http.RequestParams; import org.apache.http.Header; import org.apache.http.entity.ByteArrayEntity; import org.apache.http.message.BasicHeader; import org.apache.http.protocol.HTTP; import org.json.JSONException; import org.json.JSONObject; import java.io.File; import java.io.FileNotFoundException; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; public class HttpManager { private static HttpManager instance; private ProgressDialog mProgress = null; public static HttpManager getInstance() { if (instance == null) { instance = new HttpManager(); } return instance; } //登录接口 public void login(final String username, final String password, final Context mContext, final Handler handler) { mProgress = DialogPermission.showProgress(mContext, null, "正在登录...", false, true, null); HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); HttpClient.getInstance().get(HttpUrl.loginUrl + "?username=" + username + "&password=" + password, new AsyncHttpResponseHandler() { @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { closeProgress(); Message msg = Message.obtain(); msg.what = HttpCode.LOGIN_SUCESS; msg.obj = new String(arg2); handler.sendMessage(msg); } @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { closeProgress(); AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } //注册接口 public void register(final Context context, String username, String password, String smscode, String source, final Handler handler) { mProgress = DialogPermission.showProgress(context, null, "正在注册...", false, true, null); JSONObject jsonObject = new JSONObject(); ByteArrayEntity entity = null; try { jsonObject.put(HttpKey.USERNAME, username); jsonObject.put(HttpKey.PASSWORD, password); jsonObject.put(HttpKey.SMSCODE, smscode); jsonObject.put(HttpKey.SOURCE, source); Log.e("test", "jsonObject" + jsonObject); entity = new ByteArrayEntity(jsonObject.toString().getBytes("UTF-8")); entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); } catch (JSONException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } HttpClient.getInstance().addHeader("Accept", "*/*"); HttpClient.getInstance().post(context, HttpUrl.registeredUrl, entity, "application/json", new JsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { super.onSuccess(statusCode, headers, response); closeProgress(); Log.e("test", "onSuccess" + response); Message msg = Message.obtain(); msg.what = HttpCode.REGISTERED_SUCESS; msg.obj = response; handler.sendMessage(msg); } @Override public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { super.onFailure(statusCode, headers, throwable, errorResponse); closeProgress(); Log.e("test", "onFailure" + errorResponse); AlertUtils.showToast(context, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } //注册验证码 public void authCode(final String type, final String mobile, final Handler handler, final Context mContext) { RequestParams params = new RequestParams(); params.put(HttpKey.TYPE, type); params.put(HttpKey.MOBIL, mobile); HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); HttpClient.getInstance().post(HttpUrl.authCodedUrl, params, new JsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { Log.e("test", "onSuccess-----" + response); Message msg = Message.obtain(); msg.what = HttpCode.AUTHCODE_SUCESS; msg.obj = response; handler.sendMessage(msg); } @Override public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } //手机号是否注册 public void isregistered(final String mobile, final Handler handler, final Context mContext) { RequestParams params = new RequestParams(); params.put(HttpKey.USERNAME, mobile); HttpClient.getInstance().get(HttpUrl.isRegiterUrl + "?mobile=" + mobile, new JsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { Log.e("test", "isregistered" + response.toString()); Message msg = Message.obtain(); msg.what = HttpCode.IS_REFISTER; msg.obj = response; handler.sendMessage(msg); } @Override public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } //修改密码 public void changepwd(final Context context, String username, String old_pwd1, String newpassword3) { RequestParams params = new RequestParams(); params.put(HttpKey.USERNAME, username); params.put(HttpKey.OLDPASS, old_pwd1); params.put(HttpKey.NEWPASS, newpassword3); HttpClient.getInstance().addHeader("Accept", "*/*"); HttpClient.getInstance().setTimeout(10 * 1000); HttpClient.getInstance().post(HttpUrl.changepassword, params, new AsyncHttpResponseHandler() { @Override public void onSuccess(int i, Header[] headers, byte[] bytes) { try { JSONObject jsonObject = new JSONObject(new String(bytes)); String status = jsonObject.optString("status"); if (status.equals("100")) { Log.e("test", "onSuccess" + new String(bytes)); Toast.makeText(context, "密码修改成功!", Toast.LENGTH_LONG).show(); SaveParam.getInstance().clearData((Activity) context); Intent intent = new Intent(); intent.setClass(context, LoginAndRegisterActivity.class); ((Activity) context).startActivity(intent); ((Activity) context).finish(); } else { Toast.makeText(context, "密码修改失败!", Toast.LENGTH_LONG).show(); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) { Log.e("test", "onFailure" + new String(bytes)); AlertUtils.showToast(context, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } //忘记密码 public void forgetpassword(final Context context, String forot_pwd_phone1, String forot_pwd_pwd3, String forot_pwd_anthcode1, Handler handler) { RequestParams params = new RequestParams(); params.put(HttpKey.USERNAME, forot_pwd_phone1); params.put(HttpKey.PASSWORD, forot_pwd_pwd3); params.put(HttpKey.AUTHCODE, forot_pwd_anthcode1); HttpClient.getInstance().addHeader("Accept", "*/*"); HttpClient.getInstance().post(HttpUrl.forgetpassword, params, new AsyncHttpResponseHandler() { @Override public void onSuccess(int i, Header[] headers, byte[] bytes) { try { JSONObject jsonObject = new JSONObject(new String(bytes)); String status = jsonObject.optString("status"); if (status.equals("100")) { Log.e("test", "onSuccess" + new String(bytes)); Toast.makeText(context, "密码修改成功!", Toast.LENGTH_LONG).show(); ((Activity) context).finish(); } else { Toast.makeText(context, "密码修改失败!", Toast.LENGTH_LONG).show(); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) { Log.e("test", "onFailure" + new String(bytes)); AlertUtils.showToast(context, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } //保存用户登录信息 public void saveLoginInfo(Context context, String username, String password, String access_token, String userId) { SaveParam.getInstance().saveLoginParam(context, "username", username); SaveParam.getInstance().saveLoginParam(context, "password", password); SaveParam.getInstance().saveLoginParam(context, "access_token", access_token); SaveParam.getInstance().saveLoginParam(context, "userId", userId); } //提交保卡信息 public void subcardinfo(final Context context, long userId, String customerName, String customerAddress, String buyAddress, String buyTime, String alterSaleCall, String productModel, String deviceNumber, String macAddress, String mobilePhone) { mProgress = DialogPermission.showProgress(context, null, "正在绑定保卡...", false, true, null); RequestParams params = new RequestParams(); params.put(HttpKey.USEID, userId); params.put(HttpKey.CUSTOMENAME, customerName); params.put(HttpKey.CUSTOMADRESS, customerAddress); params.put(HttpKey.BUYADREES, buyAddress); params.put(HttpKey.BUYTIME, buyTime); params.put(HttpKey.ALTERSALECALL, alterSaleCall); params.put(HttpKey.PRODUCTMODEL, productModel); params.put(HttpKey.DEVICENUMBER, deviceNumber); params.put(HttpKey.MACADRESS, macAddress); params.put(HttpKey.MOBILPHONE, mobilePhone); HttpClient.getInstance().addHeader("Accept", "*/*"); Log.e("test", "params" + params); HttpClient.getInstance().setTimeout(5 * 1000); HttpClient.getInstance().post(context, HttpUrl.subcardinfo, params, new AsyncHttpResponseHandler() { @Override public void onSuccess(int i, Header[] headers, byte[] bytes) { JSONObject jsonObject = null; closeProgress(); try { jsonObject = new JSONObject(new String(bytes)); String status = jsonObject.optString("status"); if (status.equals("1")) { Log.e("test", "onSuccess" + jsonObject); Toast.makeText(context, "保卡绑定成功!", Toast.LENGTH_LONG).show(); Intent intent = new Intent(); intent.setClass((Activity) context, TheStartPageActivity.class); ((Activity) context).startActivity(intent); ((Activity) context).overridePendingTransition(R.anim.rightin, R.anim.rightout); ((Activity) context).finish(); } else { Toast.makeText(context, "保卡绑定失败!", Toast.LENGTH_LONG).show(); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) { Log.e("test", "onFailure" + (throwable)); closeProgress(); AlertUtils.showToast(context, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } //获取保卡信息 public void getcardinfo(final Context mContext, long userId, final Handler handler) { mProgress = DialogPermission.showProgress(mContext, null, "正在获取保卡信息...", false, true, null); HttpClient.getInstance().setTimeout(5 * 1000); HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); HttpClient.getInstance().get(HttpUrl.getcardinfo + "?userId=" + userId, new AsyncHttpResponseHandler() { @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { closeProgress(); Log.e("test", "保卡信息" + new String(arg2)); try { JSONObject jsonObject = new JSONObject(new String(arg2)); int status = jsonObject.optInt("status"); if (status == 1) { CardInfo cardInfo = GsonTool.getPerson(new String(arg2), CardInfo.class);//解析json数据 CardInfo.DataBean schoolInfoBeanList = cardInfo.getData(); Message msg = Message.obtain(); msg.what = HttpCode.SUCHCARDINFO; msg.obj = schoolInfoBeanList; handler.sendMessage(msg); } else { AlertUtils.showToast(mContext, "你好,服务器异常,请稍后重试!"); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { closeProgress(); AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } //修改保卡信息电话 public void changecardinfophone(final Context mContext, long userId, final String customerPhone, String authCode) { RequestParams params = new RequestParams(); params.put("userId", userId); params.put("customerPhone", customerPhone); params.put("authCode", authCode); HttpClient.getInstance().addHeader("Accept", "*/*"); HttpClient.getInstance().post(HttpUrl.changecardinfo, params, new AsyncHttpResponseHandler() { @Override public void onSuccess(int i, Header[] headers, byte[] bytes) { try { JSONObject jsonObject = new JSONObject(new String(bytes)); String status = jsonObject.optString("status"); if (status.equals("1")) { Toast.makeText(mContext, "手机号修改成功", Toast.LENGTH_LONG).show(); if (Content.authcodeflag==2){ SaveParam.getInstance().saveCustomizeParam(mContext, SaveParam.CARDPHONE, customerPhone); }else if (Content.authcodeflag==1){ SaveParam.getInstance().saveLoginParam(mContext, "username", customerPhone); }else { AlertUtils.showToast(mContext, "修改未知的手机号"); } ((Activity) mContext).finish(); } else if (status.equals("1001")) { Toast.makeText(mContext, "验证码输入错误", Toast.LENGTH_LONG).show(); } else { AlertUtils.showToast(mContext, "您好,服务器异常,请稍后重试"); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) { Log.e("test", "onFailure" + new String(bytes)); AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } //修改保卡信息地址 public void changecardadressinfo(final Context mContext, long userId, final String customerPhone, String authCode, final String customerAddress) { RequestParams params = new RequestParams(); params.put("userId", userId); params.put("customerPhone", customerPhone); params.put("authCode", authCode); params.put("customerAddress", customerAddress); HttpClient.getInstance().addHeader("Accept", "*/*"); HttpClient.getInstance().post(HttpUrl.changecardinfo, params, new AsyncHttpResponseHandler() { @Override public void onSuccess(int i, Header[] headers, byte[] bytes) { try { JSONObject jsonObject = new JSONObject(new String(bytes)); String status = jsonObject.optString("status"); if (status.equals("1")) { Toast.makeText(mContext, "修改成功", Toast.LENGTH_LONG).show(); SaveParam.getInstance().saveCustomizeParam(mContext, SaveParam.ADRESSCUNSTEM, customerAddress); ((Activity) mContext).finish(); } else { AlertUtils.showToast(mContext, "您好,服务器异常,请稍后重试"); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) { Log.e("test", "onFailure" + new String(bytes)); AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } //验证是否保卡信息 public void cardinfocheck(final Context mContext, long userId, final Handler handler) { mProgress = DialogPermission.showProgress(mContext, null, "正在验证保卡信息...", false, true, null); HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); HttpClient.getInstance().get(HttpUrl.cardcheck + "?userId=" + userId, new AsyncHttpResponseHandler() { @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { Log.e("test", "---" + new String(arg2)); closeProgress(); Message msg = Message.obtain(); msg.what = HttpCode.CHECKCARD; msg.obj = new String(arg2); handler.sendMessage(msg); } @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { closeProgress(); AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); //Toast.makeText(mContext, "请检查网络。。" + arg3, Toast.LENGTH_LONG).show(); } }); } ///获取年级 public void getgrade(final Context mContext, final Handler handler) { HttpClient.getInstance().addHeader("Accept", "application/json"); HttpClient.getInstance().get(HttpUrl.gradesUrl, new AsyncHttpResponseHandler() { @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { Log.e("test", "年级" + new String(arg2)); GradeInfo gradeInfo = GsonTool.getPerson(new String(arg2), GradeInfo.class);//解析json数据 List gradeInfoLists = new ArrayList(); for (int i = 0; i < gradeInfo.getData().size() - 2; i++) { String name = gradeInfo.getData().get(i).getName(); int id = gradeInfo.getData().get(i).getId(); List gradeinfoList = gradeInfo.getData().get(i).getChildren(); for (int j = 0; j < gradeinfoList.size(); j++) { String secondname = gradeinfoList.get(j).getName(); int secondid = gradeinfoList.get(j).getId(); GradeInfo.DataBean.ChildrenBean dataBean = new GradeInfo.DataBean.ChildrenBean(); dataBean.setName(secondname); dataBean.setId(secondid); gradeInfoLists.add(dataBean); } } Message message = Message.obtain(); message.what = HttpCode.GRADER; message.obj = gradeInfoLists; handler.sendMessage(message); } @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } /** * 获取学校 * * @param mContext * @param regionId * @param gradeId * @param handler */ public void getschool(final Context mContext, int regionId, int gradeId, final Handler handler) { HttpClient.getInstance().addHeader("Accept", "application/json"); HttpClient.getInstance().get(HttpUrl.schoolUrl + "?regionId=" + regionId + "&gradeId=" + gradeId, new AsyncHttpResponseHandler() { @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { Log.e("test", "学校" + new String(arg2)); try { JSONObject jsonObject = new JSONObject(new String(arg2)); int status = jsonObject.optInt("status"); if (status == 1) { SchoolInfo schoolInfo = GsonTool.getPerson(new String(arg2), SchoolInfo.class);//解析json数据 List schoolInfoBeanList = schoolInfo.getData(); Message message = Message.obtain(); message.what = HttpCode.SCHOOL; message.obj = schoolInfoBeanList; handler.sendMessage(message); } else { AlertUtils.showToast(mContext, "你好,服务器异常,请稍后重试!"); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } /** * 获取个人信息 * * @param mContext * @param userId * @param handler */ public void getpresonalinfo(final Context mContext, long userId, int type, final Handler handler) { // mProgress = DialogPermission.showProgress(mContext, null, "正在获取个人信息...", // false, true, null); HttpClient.getInstance().addHeader("Accept", "application/json"); HttpClient.getInstance().setConnectTimeout(5 * 1000); HttpClient.getInstance().get(HttpUrl.getpresonalinfo + "?userId=" + userId + "&type=" + type, new AsyncHttpResponseHandler() { @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { closeProgress(); Log.e("test", "个人信息" + new String(arg2)); try { JSONObject jsonObject = new JSONObject(new String(arg2)); int status = jsonObject.optInt("status"); if (status == 1) { PesonalInfo pesonalInfo = GsonTool.getPerson(new String(arg2), PesonalInfo.class);//解析json数据 PesonalInfo.DataBean pesonalInfoBeanList = pesonalInfo.getData(); Message message = Message.obtain(); message.what = HttpCode.GETINFO; message.obj = pesonalInfoBeanList; handler.sendMessage(message); } else { AlertUtils.showToast(mContext, "你好,服务器异常,请稍后重试!"); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { closeProgress(); AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } //修改个人信息 public void changepresonalinfo(final Context mContext, Long id, int type , String name, String birthday, int gradeId, long regionId, Object schoolId, String qq, String gender , String regionName, String devicenumber) throws UnsupportedEncodingException { mProgress = DialogPermission.showProgress(mContext, null, "正在保存个人信息...", false, true, null); RequestParams params = new RequestParams(); params.put(HttpKey.USEID, id); params.put(HttpKey.TYPE, type); params.put(HttpKey.NAME, name); params.put(HttpKey.BIRDays, birthday); params.put(HttpKey.GRADE, gradeId); params.put(HttpKey.REGION, regionId); params.put(HttpKey.SCHOOL, schoolId); params.put(HttpKey.QQ, qq); params.put(HttpKey.GENDER, gender); params.put(HttpKey.REGIONNAME, regionName); params.put(HttpKey.DEVINUMBER, devicenumber); Log.e("test", "个人信息" + params); HttpClient.getInstance().addHeader("Accept", "*/*"); HttpClient.getInstance().post(mContext, HttpUrl.changepresonalinfo, params, new JsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { super.onSuccess(statusCode, headers, response); closeProgress(); String status = response.optString("status"); if (status.equals("1")) { Toast.makeText(mContext, "个人信息保存成功", Toast.LENGTH_LONG).show(); ((Activity) mContext).finish(); } else { AlertUtils.showToast(mContext, "您好,服务器异常,请稍后重试"); } } @Override public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { super.onFailure(statusCode, headers, throwable, errorResponse); closeProgress(); Log.e("test", "onFailure" + errorResponse); AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } //提交注册信息 public void subregisterinfo(final Context mContext, Long userId , String name, int gradeId, long regionId, String regionName, Object schoolId, String math, String english, String physics, String chinese, String chemistry, String history, String geography, String political, String biology, String science, final Handler handler){ mProgress = DialogPermission.showProgress(mContext, null, "正在保存个人信息...", false, true, null); RequestParams params = new RequestParams(); params.put(HttpKey.USEID, userId); params.put(HttpKey.NAME, name); params.put(HttpKey.GRADE, gradeId); params.put(HttpKey.REGION, regionId); params.put(HttpKey.SCHOOL, schoolId); params.put(HttpKey.REGIONNAME, regionName); params.put(HttpKey.MATH, math); params.put(HttpKey.ENGLISH, english); params.put(HttpKey.PHYSICES, physics); params.put(HttpKey.CHINESE, chinese); params.put(HttpKey.CHEMISTRY, chemistry); params.put(HttpKey.HISTIRY, history); params.put(HttpKey.GEOGRAPHY, geography); params.put(HttpKey.POLITICAL, political); params.put(HttpKey.BIOLOGY, biology); params.put(HttpKey.SCIENCE, science); Log.e("test", "注册信息" + params); HttpClient.getInstance().addHeader("Accept", "*/*"); HttpClient.getInstance().post(mContext, HttpUrl.submitregisterURL, params, new JsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { super.onSuccess(statusCode, headers, response); closeProgress(); Message message = Message.obtain(); message.what = HttpCode.REGISTERINFO_SUCESS; message.obj = new String(String.valueOf(response)); handler.sendMessage(message); } @Override public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { super.onFailure(statusCode, headers, throwable, errorResponse); closeProgress(); Log.e("test", "onFailure" + errorResponse); AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } //修改版本信息 public void changepublishinfo(final Context mContext, String userId, String math, String english, String physics, String chinese, String chemistry, String history, String geography, String political, String biology, String science){ mProgress = DialogPermission.showProgress(mContext, null, "正在保存个人信息...", false, true, null); RequestParams params = new RequestParams(); params.put(HttpKey.USEID, userId); params.put(HttpKey.MATH, math); params.put(HttpKey.ENGLISH, english); params.put(HttpKey.PHYSICES, physics); params.put(HttpKey.CHINESE, chinese); params.put(HttpKey.CHEMISTRY, chemistry); params.put(HttpKey.HISTIRY, history); params.put(HttpKey.GEOGRAPHY, geography); params.put(HttpKey.POLITICAL, political); params.put(HttpKey.BIOLOGY, biology); params.put(HttpKey.SCIENCE, science); Log.e("test", "版本信息信息" + params); HttpClient.getInstance().addHeader("Accept", "*/*"); HttpClient.getInstance().post(mContext, HttpUrl.chagepublishURL, params, new JsonHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { super.onSuccess(statusCode, headers, response); closeProgress(); String status = response.optString("status"); if (status.equals("1")) { Toast.makeText(mContext, "版本信息修改成功", Toast.LENGTH_LONG).show(); ((Activity) mContext).finish(); } else { AlertUtils.showToast(mContext, "你好,服务器异常,请稍后重试"); } } @Override public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { super.onFailure(statusCode, headers, throwable, errorResponse); closeProgress(); Log.e("test", "onFailure" + errorResponse); AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } //修改个性签名 public void changsignature(final Context mContext, long userId, int type, final String signature) { RequestParams params = new RequestParams(); params.put("userId", userId); params.put("type", type); params.put("signature", signature); HttpClient.getInstance().addHeader("Accept", "*/*"); HttpClient.getInstance().post(HttpUrl.signature, params, new AsyncHttpResponseHandler() { @Override public void onSuccess(int i, Header[] headers, byte[] bytes) { try { JSONObject jsonObject = new JSONObject(new String(bytes)); String status = jsonObject.optString("status"); if (status.equals("1")) { Toast.makeText(mContext, "个性签名修改成功", Toast.LENGTH_LONG).show(); } else { AlertUtils.showToast(mContext, "你好,服务器异常,请稍后重试"); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) { Log.e("test", "onFailure" + new String(bytes)); AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } /** * 获取个性签名 * * @param mContext * @param userId * @param handler */ public void getsignatures(final Context mContext, long userId, int type, final Handler handler) { HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); HttpClient.getInstance().get(HttpUrl.getsignature + "?userId=" + userId + "&type=" + type, new AsyncHttpResponseHandler() { @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { Log.e("test", "个性签名" + new String(arg2)); try { JSONObject jsonObject = new JSONObject(new String(arg2)); int status = jsonObject.optInt("status"); if (status == 1) { SignInfo signInfo = GsonTool.getPerson(new String(arg2), SignInfo.class);//解析json数据 SignInfo.DataBean signInfoBeanList = signInfo.getData(); Message message = Message.obtain(); message.what = HttpCode.SIGN; message.obj = signInfoBeanList; handler.sendMessage(message); } else if (status == 1000) { //AlertUtils.showToast(mContext, "您还没有签名哦"); } else { AlertUtils.showToast(mContext, "你好,服务器异常,请稍后重试!"); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { Log.e("test", "失败原因" + arg3); AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } /** * 用户反馈 * * @param mContext * @param userId * @param content * @param contact * @param imgs * @param feedtype * @throws UnsupportedEncodingException */ public void feedback(final Context mContext, String userId, String content, String contact, String imgs, String feedtype) throws UnsupportedEncodingException { mProgress = DialogPermission.showProgress(mContext, null, "正在提交反馈内容...", false, true, null); File file = new File(imgs); if (file.exists() && file.length() > 0) { RequestParams params = new RequestParams(); try { params.put("userId", userId); params.put("content", content); params.put("contact", contact); params.put("imgs", file); params.put("feedtype", feedtype); } catch (FileNotFoundException e) { e.printStackTrace(); } Log.e("test", "onSuccess" + params); HttpClient.getInstance().post(HttpUrl.feedbackURL, params, new AsyncHttpResponseHandler() { @Override public void onSuccess(int i, Header[] headers, byte[] bytes) { closeProgress(); Log.e("test", "onSuccess" + new String(bytes)); try { JSONObject jsonObject = new JSONObject(new String(bytes)); String status = jsonObject.optString("status"); if (status.equals("1")) { Toast.makeText(mContext, "您的宝贵意见已经提交成功。", Toast.LENGTH_LONG).show(); ((Activity) mContext).finish(); } else { AlertUtils.showToast(mContext, "你好,服务器异常,请稍后重试"); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) { closeProgress(); Log.e("test", "错误信息" + new String(bytes)); AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } else { Toast.makeText(mContext, "文件不存在", Toast.LENGTH_LONG).show(); } } /** * 查询子账户信息 * * @param mContext * @param userId * @param handler */ public void getchildAccountinfo(final Context mContext, long userId, String deviceNumber, final Handler handler) { mProgress = DialogPermission.showProgress(mContext, null, "正在获取信息...", false, true, null); Log.e("test", "ID" + userId + "deviceNumber" + deviceNumber); HttpClient.getInstance().setTimeout(5 * 1000); HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); HttpClient.getInstance().get(HttpUrl.childUserURL + "?userId=" + userId + "&deviceNumber=" + deviceNumber, new AsyncHttpResponseHandler() { @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { closeProgress(); Log.e("test", "子账户信息" + new String(arg2)); try { JSONObject jsonObject = new JSONObject(new String(arg2)); int status = jsonObject.optInt("status"); if (status == 1) { ChildsInfo childsInfo = GsonTool.getPerson(new String(arg2), ChildsInfo.class);//解析json数据 Log.e("test", "子账户信息" + childsInfo); List schoolInfoBeanList = childsInfo.getData(); Log.e("test", "子账户信息" + schoolInfoBeanList); Message msg = Message.obtain(); msg.what = HttpCode.CHILDS_SUCESS; msg.obj = schoolInfoBeanList; handler.sendMessage(msg); }else { AlertUtils.showToast(mContext, "你好,服务器异常,请稍后再试!"); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { closeProgress(); // Log.e("test", "错误信息" + new String(arg2)); AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } /** * 删除子账户信息 * * @param mContext * @param subAccountId */ public void deletechildAccountinfo(final Context mContext, String subAccountId) { mProgress = DialogPermission.showProgress(mContext, null, "正在删除子账户...", false, true, null); HttpClient.getInstance().setTimeout(5 * 1000); HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); HttpClient.getInstance().get(HttpUrl.deletechildUserURL + "?subAccountId=" + subAccountId, new AsyncHttpResponseHandler() { @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { closeProgress(); Log.e("test", "子账户信息" + new String(arg2)); try { JSONObject jsonObject = new JSONObject(new String(arg2)); int status = jsonObject.optInt("status"); if (status == 1) { AlertUtils.showToast(mContext, "子账号删除成功!"); ((Activity) mContext).finish(); } else { AlertUtils.showToast(mContext, "你好,子账号删除失败!"); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { closeProgress(); Log.e("test", "错误信息" + new String(arg2)); AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } /** * 添加子账户信息 */ public void addchildAccountinfo(final Context mContext, long parentId, String image, String name, final Long grade, Object school, Long region , String deviceNumber, String regionName) { mProgress = DialogPermission.showProgress(mContext, null, "正在添加子账户...", false, true, null); RequestParams params = new RequestParams(); params.put(HttpKey.PARENTID, parentId); params.put(HttpKey.IMAGE, image); params.put(HttpKey.NAME, name); params.put(HttpKey.GRADE, grade); params.put(HttpKey.SCHOOL, school); params.put(HttpKey.REGION, region); params.put(HttpKey.DEVINUMBER, deviceNumber); params.put(HttpKey.REGIONNAME, regionName); Log.e("test", "子账户信息" + params); HttpClient.getInstance().addHeader("Accept", "*/*"); HttpClient.getInstance().setTimeout(5 * 1000); HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); HttpClient.getInstance().post(HttpUrl.addchildUserURL, params, new AsyncHttpResponseHandler() { @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { closeProgress(); Log.e("test", "子账户信息" + new String(arg2)); try { JSONObject jsonObject = new JSONObject(new String(arg2)); int status = jsonObject.optInt("status"); if (status == 1) { AlertUtils.showToast(mContext, "子账号添加成功!"); ((Activity) mContext).finish(); } else { AlertUtils.showToast(mContext, "你好,子账号添加失败!"); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { closeProgress(); Log.e("test", "错误信息" + new String(arg2)); AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } /** * 切换子账户信息 * * @param mContext * @param subAccountId */ public void changechildAccountinfo(final Context mContext, String subAccountId, long userId , String deviceNumber, int type) { mProgress = DialogPermission.showProgress(mContext, null, "正在切换子账户...", false, true, null); HttpClient.getInstance().setTimeout(5 * 1000); HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); HttpClient.getInstance().get(HttpUrl.changechildUserURL + "?subAccountId=" + subAccountId + "&userId=" + userId + "&deviceNumber=" + deviceNumber + "&type=" + type, new AsyncHttpResponseHandler() { @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { closeProgress(); Log.e("test", "子账户信息" + new String(arg2)); try { JSONObject jsonObject = new JSONObject(new String(arg2)); int status = jsonObject.optInt("status"); if (status == 1) { AlertUtils.showToast(mContext, "子账号切换成功!"); ((Activity) mContext).finish(); } else { AlertUtils.showToast(mContext, "你好,子账号切换失败!"); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { closeProgress(); Log.e("test", "错误信息" + new String(arg2)); AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } /** * 切换主账户信息 * * @param mContext * @param type */ public void Accountinfo(final Context mContext, long userId , String deviceNumber, int type) { mProgress = DialogPermission.showProgress(mContext, null, "正在切换主账户...", false, true, null); HttpClient.getInstance().setTimeout(5 * 1000); HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); HttpClient.getInstance().get(HttpUrl.changechildUserURL + "?userId=" + userId + "&deviceNumber=" + deviceNumber + "&type=" + type, new AsyncHttpResponseHandler() { @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { closeProgress(); Log.e("test", "子账户信息" + new String(arg2)); try { JSONObject jsonObject = new JSONObject(new String(arg2)); int status = jsonObject.optInt("status"); if (status == 1) { AlertUtils.showToast(mContext, "主账号切换成功!"); ((Activity) mContext).finish(); } else { AlertUtils.showToast(mContext, "你好,主账号切换失败!"); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { closeProgress(); Log.e("test", "错误信息" + new String(arg2)); AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } /** * 头像拍张 * * @param mContext * @param userId * @param img * @throws UnsupportedEncodingException */ public void header(final Context mContext, String userId, String type, String img) throws UnsupportedEncodingException { File file = new File(img); if (file.exists() && file.length() > 0) { RequestParams params = new RequestParams(); try { params.put("userId", userId); params.put("type", type); params.put("img", file); } catch (FileNotFoundException e) { e.printStackTrace(); } Log.e("test", "params" + params); HttpClient.getInstance().setTimeout(5 * 1000); HttpClient.getInstance().post(HttpUrl.headerURL, params, new AsyncHttpResponseHandler() { @Override public void onSuccess(int i, Header[] headers, byte[] bytes) { Log.e("test", "onSuccess" + new String(bytes)); try { JSONObject jsonObject = new JSONObject(new String(bytes)); String status = jsonObject.optString("status"); JSONObject jsonObject1 =jsonObject.getJSONObject("data"); String imagUrl = jsonObject1.optString("imgUrl"); SaveParam.getInstance().saveLoginParam(mContext,SaveParam.HEADURL,imagUrl); if (status.equals("1")) { Toast.makeText(mContext, "头像上传成功。", Toast.LENGTH_LONG).show(); } else { AlertUtils.showToast(mContext, "你好,服务器异常,请稍后重试"); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) { closeProgress(); Log.e("test", "错误信息" + new String(bytes)); AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } else { Toast.makeText(mContext, "文件不存在", Toast.LENGTH_LONG).show(); } } /** * 头像默认 * * @param mContext * @param userId * @param * @throws UnsupportedEncodingException */ public void headerdeft(final Context mContext, String userId, String type,String defaultImg) throws UnsupportedEncodingException { RequestParams params = new RequestParams(); params.put("userId", userId); params.put("type", type); params.put("defaultImg", defaultImg); Log.e("test", "params" + params); HttpClient.getInstance().setTimeout(5 * 1000); HttpClient.getInstance().post(HttpUrl.headerdefaultURL, params, new AsyncHttpResponseHandler() { @Override public void onSuccess(int i, Header[] headers, byte[] bytes) { Log.e("test", "onSuccess" + new String(bytes)); try { JSONObject jsonObject = new JSONObject(new String(bytes)); String status = jsonObject.optString("status"); JSONObject jsonObject1 =jsonObject.getJSONObject("data"); String imagUrl = jsonObject1.optString("imgUrl"); SaveParam.getInstance().saveLoginParam(mContext,SaveParam.HEADURL,imagUrl); if (status.equals("1")) { Toast.makeText(mContext, "头像上传成功。", Toast.LENGTH_LONG).show(); } else { AlertUtils.showToast(mContext, "你好,服务器异常,请稍后重试"); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) { closeProgress(); Log.e("test", "错误信息" + new String(bytes)); AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } /** * 检查注册信息是否完整 * @param mContext * @param userId */ public void registerinfocheck(final Context mContext, long userId, final Handler handler) { mProgress = DialogPermission.showProgress(mContext, null, "正在检查注册信息是否完整...", false, true, null); HttpClient.getInstance().setTimeout(5 * 1000); HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); HttpClient.getInstance().get(HttpUrl.isRegisterInfoCompleteURL + "?userId=" + userId , new AsyncHttpResponseHandler() { @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { closeProgress(); Log.e("test", "注册信息" + new String(arg2)); Message msg = Message.obtain(); msg.what = HttpCode.REGISTER_SUCESS; msg.obj = new String(arg2); handler.sendMessage(msg); } @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { closeProgress(); // Log.e("test", "错误信息" + new String(arg2)); AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } /** * 获取最近学习视频 * @param mContext * @param userId */ public void getstuyvidioinfo(final Context mContext, long userId, final Handler handler) { mProgress = DialogPermission.showProgress(mContext, null, "正在获取最近学习视频...", false, true, null); HttpClient.getInstance().setTimeout(5 * 1000); HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); HttpClient.getInstance().get(HttpUrl.getvidioURL + "?userId=" + userId , new AsyncHttpResponseHandler() { @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { closeProgress(); Log.e("test", "近学习视频" + new String(arg2)); try { JSONObject jsonObject = new JSONObject(new String(arg2)); int status = jsonObject.optInt("status"); if (status == 1) { VideoInfo videoInfo = GsonTool.getPerson(new String(arg2), VideoInfo.class);//解析json数据 List schoolInfoBeanList = videoInfo.getData(); Message msg = Message.obtain(); msg.what = HttpCode.GETVIDIO_SUCESS; msg.obj = schoolInfoBeanList; handler.sendMessage(msg); }else { AlertUtils.showToast(mContext, "你好,服务器异常,请稍后再试!"); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { closeProgress(); // Log.e("test", "错误信息" + new String(arg2)); AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } /** * 系统升级 * * @param mContext * @param pid appName */ public void updateAPP(final Context mContext, String pid, String appName, final Handler handler) { mProgress = DialogPermission.showProgress(mContext, null, "正在检测是否升级版本...", false, true, null); HttpClient.getInstance().setTimeout(5 * 1000); HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); HttpClient.getInstance().get(HttpUrl.updateappURL + "?pid=" + pid + "&appName=" + appName, new AsyncHttpResponseHandler() { @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { closeProgress(); Log.e("test", "版本升级信息" + new String(arg2)); AppVersion appVersion = GsonTool.getPerson(new String(arg2), AppVersion.class);//解析json数据 Message msg = Message.obtain(); msg.what = HttpCode.APPUPDATE_SUCESS; msg.obj = appVersion; handler.sendMessage(msg); } @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { closeProgress(); Log.e("test", "错误信息" + new String(arg2)); } }); } //版本信息 public void versioninfo(final Context mContext,String subjectName, final Handler handler) { HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); HttpClient.getInstance().get(HttpUrl.getversionURL+"?subjectName="+subjectName, new AsyncHttpResponseHandler() { @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { Log.e("test", "版本信息" + new String(arg2)); try { JSONObject jsonObject = new JSONObject(new String(arg2)); int status = jsonObject.optInt("status"); if (status == 1) { VersionInfo versionInfo = GsonTool.getPerson(new String(arg2), VersionInfo.class);//解析json数据 List versionInfoList = versionInfo.getData(); Message message = Message.obtain(); message.what = HttpCode.VERSION_SUCESS; message.obj = versionInfoList; handler.sendMessage(message); } else if(status == 1000){ AlertUtils.showToast(mContext, "你好,该科目没有版本信息"); }else { AlertUtils.showToast(mContext, "你好,服务器异常,请稍后重试!"); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } ///省级接口 public void provices(final Context mContext, final Handler handler) { HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); HttpClient.getInstance().get(HttpUrl.provinceUrl, new AsyncHttpResponseHandler() { @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { Log.e("test", "省" + new String(arg2)); try { JSONObject jsonObject = new JSONObject(new String(arg2)); int status = jsonObject.optInt("status"); if (status == 100) { ProvinceInfo provinceInfo = GsonTool.getPerson(new String(arg2), ProvinceInfo.class);//解析json数据 Log.e("test", "状态码" + provinceInfo.getStatus()); List provincesBeanList = provinceInfo.getProvinces(); Message message = Message.obtain(); message.what = HttpCode.PROVICES; message.obj = provincesBeanList; handler.sendMessage(message); } else { AlertUtils.showToast(mContext, "你好,服务器异常,请稍后重试!"); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } //获取版本信息接口 public void getpublishinfo(final Context mContext, long userId,int gradeId, final Handler handler) { HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); HttpClient.getInstance().get(HttpUrl.getpublishURL + "?userId=" + userId+ "&gradeId=" + gradeId, new AsyncHttpResponseHandler() { @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { Log.e("test", "获取版本信息接口" + new String(arg2)); try { JSONObject jsonObject = new JSONObject(new String(arg2)); int status = jsonObject.optInt("status"); if (status == 1) { Gson gson = new Gson(); DefautPublishInfo defautPublishInfo = gson.fromJson(new String(arg2), DefautPublishInfo.class); List defautPublishInfoBeanList = defautPublishInfo.getData(); Message message = Message.obtain(); message.what = HttpCode.PUBLISH_SUCESS; message.obj = defautPublishInfoBeanList; handler.sendMessage(message); } else { AlertUtils.showToast(mContext, "你好,服务器异常,请稍后重试!"); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } //市级接口 public void cityinfo(final Context mContext, long regionId, final Handler handler) { HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); HttpClient.getInstance().get(HttpUrl.cityUrl + "?regionId=" + regionId, new AsyncHttpResponseHandler() { @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { Log.e("test", "市" + new String(arg2)); try { JSONObject jsonObject = new JSONObject(new String(arg2)); int status = jsonObject.optInt("status"); if (status == 100) { Gson gson = new Gson(); CityInfo cityInfo = gson.fromJson(new String(arg2), CityInfo.class); List cityInfoBeanList = cityInfo.getCities(); Message message = Message.obtain(); message.what = HttpCode.CITYS; message.obj = cityInfoBeanList; handler.sendMessage(message); } else { AlertUtils.showToast(mContext, "你好,服务器异常,请稍后重试!"); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } //区县级接口 public void countyinfo(final Context mContext, int parentId, final Handler handler) { HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); HttpClient.getInstance().get(HttpUrl.countyUrl + "?regionId=" + parentId, new AsyncHttpResponseHandler() { @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { Log.e("test", "区" + new String(arg2)); try { JSONObject jsonObject = new JSONObject(new String(arg2)); int status = jsonObject.optInt("status"); if (status == 100) { Gson gson = new Gson(); CountyInfo countyInfo = gson.fromJson(new String(arg2), CountyInfo.class); List countyInfoInfoBeanList = countyInfo.getCounties(); Message message = Message.obtain(); message.what = HttpCode.COUNTRY; message.obj = countyInfoInfoBeanList; handler.sendMessage(message); } else { AlertUtils.showToast(mContext, "你好,服务器异常,请稍后重试!"); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { AlertUtils.showToast(mContext, "无法链接到服务器,请检查您的网络或稍后重试!"); } }); } private void closeProgress() { try { if (mProgress != null) { mProgress.dismiss(); mProgress = null; } } catch (Exception e) { e.printStackTrace(); } } public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK ) { HttpManager.getInstance().closeProgress(); } return false; } }