package com.tofly.ghrq_route.module.message.service;

import android.content.Context;
import android.text.TextUtils;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.gaoyuan.weixinrecord.example.Record;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.tofly.ghrq_route.base.BaseApp;
import com.tofly.ghrq_route.base.url.NetRequestURL;
import com.tofly.ghrq_route.base.URLResponseCode;
import com.tofly.ghrq_route.module.message.controller.MessageCallBack;
import com.tofly.ghrq_route.module.message.domain.InMessageBean;
import com.tofly.ghrq_route.module.message.domain.MessageDeatilBean;
import com.tofly.ghrq_route.module.message.domain.OutMessageBean;
import com.tofly.ghrq_route.module.trouble.domain.TroubleBean;
import com.tofly.ghrq_route.module.trouble.domain.TroublePictureBean;
import com.tofly.ghrq_route.common.util.net.volley.JsonRequestConstant;
import com.tofly.ghrq_route.common.util.net.volley.MultiPartStringRequest;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Amu on 2017/5/3.
 */

public class MessageServiceImpl implements IMessageService {

    private Context mContext;

    public MessageServiceImpl(Context context) {
        mContext = context;
    }

    @Override
    public void getRecvMsgList(final String token, final int isread, final int pageindex, final int pagesize, final MessageCallBack messageCallBack) {
        String url = NetRequestURL.getRecvMessageListUrl();
        StringRequest postRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                URLResponseCode.URLResponse responseCode = new URLResponseCode.URLResponse(response);
                if (responseCode.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                    String rowsArray = responseCode.queryResult("records");
                    List<InMessageBean> messageBeanList = null;
                    int resCode = -1;
                    boolean result = false;
                    String parseErrMsg = "用户解析失败";
                    int total = 0;
                    String strTotal = responseCode.queryResult("total");
                    if (strTotal != null && !strTotal.isEmpty()) {
                        total = Integer.parseInt(strTotal);
                    }
                    if (rowsArray != null) {
                        try {
                            Gson gson = new Gson();
                            List<InMessageBean> messageBeens = gson.fromJson(rowsArray, new TypeToken<List<InMessageBean>>() {
                            }.getType());
                            if (messageBeens != null && messageBeens.size() >= 0) {
                                messageBeanList = messageBeens;
                                resCode = responseCode.getCode();
                                parseErrMsg = responseCode.getMessage();
                                result = true;
                            }
                        } catch (Exception e) {
                            messageCallBack.onGetRecvMsgList(false, resCode, parseErrMsg, null, 0);
                        }
                    }
                    messageCallBack.onGetRecvMsgList(result, resCode, parseErrMsg, messageBeanList, total);
                } else {
                    messageCallBack.onGetRecvMsgList(
                            false, responseCode.getCode(), responseCode.getMessage(), null, 0);
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                //登录失败
                if (error.networkResponse != null) {
                    try {
                        String errString = new String(error.networkResponse.data, "UTF-8");
                        messageCallBack.onGetRecvMsgList(
                                false, error.networkResponse.statusCode, errString, null, 0);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        messageCallBack.onGetRecvMsgList(
                                false, error.networkResponse.statusCode, null, null, 0);
                    }
                } else {
                    String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                    messageCallBack.onGetRecvMsgList(
                            false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString, null, 0);
                }
            }
        }) {

            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = NetRequestURL.newApi_dyrq.getHeaderParams();
                return params;
            }
        };
        BaseApp.addRequest(mContext.getClass().getName(), postRequest);
    }

    @Override
    public void getRecvMsgList1(final String token, final int isread, final int pageindex, final int pagesize, final String content, final MessageCallBack messageCallBack) {
        String url = NetRequestURL.getRecvMessageListUrl();
        if (!TextUtils.isEmpty(content)) {
            try {
                url = url + "?searchText=" + URLEncoder.encode(content, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        StringRequest postRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                URLResponseCode.URLResponse responseCode = new URLResponseCode.URLResponse(response);
                if (responseCode.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                    String rowsArray = responseCode.queryResult("records");
                    List<InMessageBean> messageBeanList = null;
                    int resCode = -1;
                    boolean result = false;
                    String parseErrMsg = "用户解析失败";
                    int total = 0;
                    String strTotal = responseCode.queryResult("total");
                    if (strTotal != null && !strTotal.isEmpty()) {
                        total = Integer.parseInt(strTotal);
                    }
                    if (rowsArray != null) {
                        try {
                            Gson gson = new Gson();
                            List<InMessageBean> messageBeens = gson.fromJson(rowsArray, new TypeToken<List<InMessageBean>>() {
                            }.getType());
                            if (messageBeens != null && messageBeens.size() >= 0) {
                                messageBeanList = messageBeens;
                                resCode = responseCode.getCode();
                                parseErrMsg = responseCode.getMessage();
                                result = true;
                            }
                        } catch (Exception e) {
                            messageCallBack.onGetRecvMsgList(false, resCode, parseErrMsg, null, 0);
                        }
                    }
                    messageCallBack.onGetRecvMsgList(result, resCode, parseErrMsg, messageBeanList, total);
                } else {
                    messageCallBack.onGetRecvMsgList(
                            false, responseCode.getCode(), responseCode.getMessage(), null, 0);
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                //登录失败
                if (error.networkResponse != null) {
                    try {
                        String errString = new String(error.networkResponse.data, "UTF-8");
                        messageCallBack.onGetRecvMsgList(
                                false, error.networkResponse.statusCode, errString, null, 0);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        messageCallBack.onGetRecvMsgList(
                                false, error.networkResponse.statusCode, null, null, 0);
                    }
                } else {
                    String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                    messageCallBack.onGetRecvMsgList(
                            false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString, null, 0);
                }
            }
        }) {

            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = NetRequestURL.newApi_dyrq.getHeaderParams();
                return params;
            }
        };
        BaseApp.addRequest(mContext.getClass().getName(), postRequest);
    }

    @Override
    public void getSendMsgList(final String token, final int pageindex, final int pagesize, final String content, final MessageCallBack messageCallBack) {
        String url = NetRequestURL.getSendMessageListUrl();
        if (!TextUtils.isEmpty(content)) {
            try {
                url = url + "?searchText=" + URLEncoder.encode(content, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        StringRequest postRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                URLResponseCode.URLResponse responseCode = new URLResponseCode.URLResponse(response);
                if (responseCode.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                    String rowsArray = responseCode.queryResult("records");
                    List<OutMessageBean> messageBeanList = null;
                    int resCode = -1;
                    boolean result = false;
                    String parseErrMsg = "用户解析失败";
                    int total = 0;
                    String strTotal = responseCode.queryResult("total");
                    if (strTotal != null && !strTotal.isEmpty()) {
                        total = Integer.parseInt(strTotal);
                    }
                    if (rowsArray != null) {
                        try {
                            Gson gson = new Gson();
                            List<OutMessageBean> messageBeens = gson.fromJson(rowsArray, new TypeToken<List<OutMessageBean>>() {
                            }.getType());
                            if (messageBeens != null && messageBeens.size() >= 0) {
                                messageBeanList = messageBeens;
                                resCode = responseCode.getCode();
                                parseErrMsg = responseCode.getMessage();
                                result = true;
                            }
                        } catch (Exception e) {
                            messageCallBack.onGetSendMsgList(false, resCode, parseErrMsg, null, 0);
                        }
                    }
                    messageCallBack.onGetSendMsgList(result, resCode, parseErrMsg, messageBeanList, total);
                } else {
                    messageCallBack.onGetSendMsgList(
                            false, responseCode.getCode(), responseCode.getMessage(), null, 0);
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                //登录失败
                if (error.networkResponse != null) {
                    try {
                        String errString = new String(error.networkResponse.data, "UTF-8");
                        messageCallBack.onGetSendMsgList(
                                false, error.networkResponse.statusCode, errString, null, 0);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        messageCallBack.onGetSendMsgList(
                                false, error.networkResponse.statusCode, null, null, 0);
                    }
                } else {
                    String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                    messageCallBack.onGetSendMsgList(
                            false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString, null, 0);
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = NetRequestURL.newApi_dyrq.getHeaderParams();
                return params;
            }
        };
        BaseApp.addRequest(mContext.getClass().getName(), postRequest);
    }

    @Override
    public void setRecvMsgReaded(final String token, final String ids, final MessageCallBack messageCallBack) {
        String url = NetRequestURL.getMarkReadMessageUrl() + "?ids=" + ids;
        StringRequest postRequest = new StringRequest(Request.Method.PUT,
                url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                URLResponseCode.URLResponse urlResponse = new URLResponseCode.URLResponse(response);
                if (urlResponse.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                    messageCallBack.onSetRecvMsgReaded(true, urlResponse.getCode(), urlResponse.getMessage());
                } else {
                    messageCallBack.onSetRecvMsgReaded(
                            false, urlResponse.getCode(), urlResponse.getMessage());
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                //登录失败
                if (error.networkResponse != null) {
                    try {
                        String errString = new String(error.networkResponse.data, "UTF-8");
                        messageCallBack.onSetRecvMsgReaded(
                                false, error.networkResponse.statusCode, errString);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        messageCallBack.onSetRecvMsgReaded(
                                false, error.networkResponse.statusCode, null);
                    }
                } else {
                    String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                    messageCallBack.onSetRecvMsgReaded(
                            false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString);
                }
            }
        }) {
//            @Override
//            public byte[] getBody() {
//                Gson gson = new Gson();
//                String json = gson.toJson(ids);
//                return json.getBytes();
//            }

            @Override
            public String getBodyContentType() {
                return JsonRequestConstant.PROTOCOL_CONTENT_TYPE;
            }

            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = NetRequestURL.newApi_dyrq.getHeaderParams();
                return params;
            }
        };
        BaseApp.addRequest(mContext.getClass().getName(), postRequest);
    }

    @Override
    public void deleteRecvMsg(final String token, final String ids, final MessageCallBack messageCallBack) {
        String url = NetRequestURL.getDeleteRecvMessageUrl() + "?ids=" + ids;
        StringRequest postRequest = new StringRequest(Request.Method.DELETE,
                url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                URLResponseCode.URLResponse urlResponse = new URLResponseCode.URLResponse(response);
                if (urlResponse.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                    messageCallBack.onDeleteRecvMsg(true, urlResponse.getCode(), urlResponse.getMessage());
                } else {
                    messageCallBack.onDeleteRecvMsg(
                            false, urlResponse.getCode(), urlResponse.getMessage());
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                //登录失败
                if (error.networkResponse != null) {
                    try {
                        String errString = new String(error.networkResponse.data, "UTF-8");
                        messageCallBack.onDeleteRecvMsg(
                                false, error.networkResponse.statusCode, errString);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        messageCallBack.onDeleteRecvMsg(
                                false, error.networkResponse.statusCode, null);
                    }
                } else {
                    String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                    messageCallBack.onDeleteRecvMsg(
                            false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString);
                }
            }
        }) {

//            @Override
//            public byte[] getBody() {
//                Gson gson = new Gson();
//                String json = gson.toJson(ids);
//                return json.getBytes();
//            }

            @Override
            public String getBodyContentType() {
                return JsonRequestConstant.PROTOCOL_CONTENT_TYPE;
            }

            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = NetRequestURL.newApi_dyrq.getHeaderParams();
                return params;
            }
        };
        BaseApp.addRequest(mContext.getClass().getName(), postRequest);
    }

    @Override
    public void deleteSendMsg(final String token, final String ids, final MessageCallBack messageCallBack) {
        String url = NetRequestURL.getDeleteSendMessageUrl() + "?ids=" + ids;
        StringRequest postRequest = new StringRequest(Request.Method.DELETE,
                url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                URLResponseCode.URLResponse urlResponse = new URLResponseCode.URLResponse(response);
                if (urlResponse.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                    messageCallBack.onDeleteSendMsg(true, urlResponse.getCode(), urlResponse.getMessage());
                } else {
                    messageCallBack.onDeleteSendMsg(
                            false, urlResponse.getCode(), urlResponse.getMessage());
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                //登录失败
                if (error.networkResponse != null) {
                    try {
                        String errString = new String(error.networkResponse.data, "UTF-8");
                        messageCallBack.onDeleteSendMsg(
                                false, error.networkResponse.statusCode, errString);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        messageCallBack.onDeleteSendMsg(
                                false, error.networkResponse.statusCode, null);
                    }
                } else {
                    String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                    messageCallBack.onDeleteSendMsg(
                            false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString);
                }
            }
        }) {
//            @Override
//            public byte[] getBody() {
//                Gson gson = new Gson();
//                String json = gson.toJson(ids);
//                return json.getBytes();
//            }

            @Override
            public String getBodyContentType() {
                return JsonRequestConstant.PROTOCOL_CONTENT_TYPE;
            }

            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = NetRequestURL.newApi_dyrq.getHeaderParams();
                return params;
            }
        };
        BaseApp.addRequest(mContext.getClass().getName(), postRequest);
    }

    @Override
    public void sendMsg(final int id, final String message, final String receipt, final List<TroublePictureBean> photos, final List<Record> audios, final MessageCallBack messageCallBack) {
        String url = NetRequestURL.getSendMessageUrl();
        MultiPartStringRequest postRequest = new MultiPartStringRequest(Request.Method.POST,
                url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                URLResponseCode.URLResponse responseCode = new URLResponseCode.URLResponse(response);
                if (responseCode.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                    messageCallBack.onSendMsg(true, responseCode.getCode(), responseCode.getMessage());
                } else {
                    messageCallBack.onSendMsg(false, responseCode.getCode(), responseCode.getMessage());
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                //登录失败
                if (error.networkResponse != null) {
                    try {
                        String errString = new String(error.networkResponse.data, "UTF-8");
                        messageCallBack.onSendMsg(false, error.networkResponse.statusCode, errString);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        messageCallBack.onSendMsg(false, error.networkResponse.statusCode, null);
                    }
                } else {
                    String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                    messageCallBack.onSendMsg(false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString);
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = NetRequestURL.newApi_dyrq.getHeaderParams();
                return params;
            }

            @Override
            public Map<String, String> getStringUploads() {
                Map<String, String> params = new HashMap<>();
                params.put("message", message);
                params.put("receipt", receipt);
                if (id != -1) {
                    params.put("replyId", String.valueOf(id));
                }
                return params;
            }

            @Override
            public Map<String, File> getFileUploads() {
                Map<String, File> params = new HashMap<>();
                //  int count = 1;
                if (photos != null && photos.size() > 0) {
                    for (int i = 0; i < photos.size(); i++) {
                        TroublePictureBean pictureBean = photos.get(i);
                        String file = pictureBean.getFilepath();
                        String time = pictureBean.getCreateTime();
                        int size = i + 1;
                        String key = "photos" + size;
                        if (file != null && !file.isEmpty())
                            params.put(key, new File(file));
                    }
                }
                if (audios != null && audios.size() > 0) {
                    for (int i = 0; i < audios.size(); i++) {
                        Record record = audios.get(i);
                        String file = record.getPath();
//                        int second = record.getSecond();
//                        String time = record.getCreateTime();
//                        String key = "file" + count + "," + second + "," + time;
                        int size = i + 1;
                        String key = "audios" + size;
                        if (file != null && !file.isEmpty()) {
                            params.put(key, new File(file));
                        }
                    }
                }
                return params;
            }
        };
        BaseApp.addMultiStatckRequest(mContext.getClass().getName(), postRequest);
    }

    @Override
    public void sendHelpMsg(final String token, final TroubleBean trouble, final List<TroublePictureBean> photos, final List<Record> audios, final MessageCallBack messageCallBack) {
        String url = NetRequestURL.getSendMessageUrl();
        MultiPartStringRequest postRequest = new MultiPartStringRequest(Request.Method.POST,
                url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                URLResponseCode.URLResponse responseCode = new URLResponseCode.URLResponse(response);
                if (responseCode.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                    messageCallBack.onSendMsg(true, responseCode.getCode(), responseCode.getMessage());
                } else {
                    messageCallBack.onSendMsg(false, responseCode.getCode(), responseCode.getMessage());
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                //登录失败
                if (error.networkResponse != null) {
                    try {
                        String errString = new String(error.networkResponse.data, "UTF-8");
                        messageCallBack.onSendMsg(false, error.networkResponse.statusCode, errString);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        messageCallBack.onSendMsg(false, error.networkResponse.statusCode, null);
                    }
                } else {
                    String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                    messageCallBack.onSendMsg(false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString);
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<String, String>();
                params.put("token", token);
                return params;
            }

            @Override
            public Map<String, String> getStringUploads() {
                Map<String, String> params = new HashMap<>();
                params.put("msgtype", OutMessageBean.MESSAGE_TYPE_HLEP + "");
                String lng = trouble.getLocationX();
                String lat = trouble.getLocationY();
                String addr = trouble.getAddress();
                String content = trouble.getNotes();
                params.put("lng", lng);
                params.put("lat", lat);
                if (addr != null && !addr.isEmpty())
                    params.put("address", addr);
                if (content != null && !content.isEmpty())
                    params.put("msgcontent", content);
                return params;
            }

            @Override
            public Map<String, File> getFileUploads() {
                Map<String, File> params = new HashMap<>();
                int count = 1;
                if (photos != null && photos.size() > 0) {
                    for (int i = 0; i < photos.size(); i++, count++) {
                        TroublePictureBean pictureBean = photos.get(i);
                        String file = pictureBean.getFilepath();
                        String time = pictureBean.getCreateTime();
                        String key = "file" + count + "," + 0 + "," + time;
                        if (file != null && !file.isEmpty())
                            params.put(key, new File(file));
                    }
                }
                if (audios != null && audios.size() > 0) {
                    for (int i = 0; i < audios.size(); i++, count++) {
                        Record record = audios.get(i);
                        String file = record.getPath();
                        int second = record.getSecond();
                        String time = record.getCreateTime();
                        String key = "file" + count + "," + second + "," + time;
                        if (file != null && !file.isEmpty()) {
                            params.put(key, new File(file));
                        }
                    }
                }
                return params;
            }
        };
        BaseApp.addMultiStatckRequest(mContext.getClass().getName(), postRequest);
    }

    @Override
    public void getMsgDetail(String id, MessageCallBack messageCallBack) {
        String url = NetRequestURL.getMsgDetail() + id;
        MultiPartStringRequest postRequest = new MultiPartStringRequest(Request.Method.GET,
                url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                URLResponseCode.URLResponse responseCode = new URLResponseCode.URLResponse(response);
                if (responseCode.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                    String rowsArray = responseCode.getResult();
                    MessageDeatilBean messageDeatilBeans = null;
                    int resCode = -1;
                    String parseErrMsg = "用户解析失败";
                    if (rowsArray != null) {
                        try {
                            Gson gson = new Gson();
                            MessageDeatilBean messageBeens = gson.fromJson(rowsArray, new TypeToken<MessageDeatilBean>() {
                            }.getType());
                            if (messageBeens != null) {
                                messageDeatilBeans = messageBeens;
                                resCode = responseCode.getCode();
                                parseErrMsg = responseCode.getMessage();
                            }
                        } catch (Exception e) {
                            messageCallBack.onDetailMsg(false, resCode, parseErrMsg, messageDeatilBeans);
                        }
                    }
                    messageCallBack.onDetailMsg(true, responseCode.getCode(), responseCode.getMessage(), messageDeatilBeans);
                } else {
                    messageCallBack.onDetailMsg(false, responseCode.getCode(), responseCode.getMessage(), null);
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                //登录失败
                if (error.networkResponse != null) {
                    try {
                        String errString = new String(error.networkResponse.data, "UTF-8");
                        messageCallBack.onDetailMsg(false, error.networkResponse.statusCode, errString, null);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        messageCallBack.onDetailMsg(false, error.networkResponse.statusCode, null, null);
                    }
                } else {
                    String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                    messageCallBack.onDetailMsg(false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString, null);
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = NetRequestURL.newApi_dyrq.getHeaderParams();
                return params;
            }
        };
        BaseApp.addMultiStatckRequest(mContext.getClass().getName(), postRequest);
    }
}
