CustomAttachParser.java 7.58 KB
Newer Older
konghaorui committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
package com.yidianling.im.session.extension;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.netease.nimlib.sdk.msg.attachment.MsgAttachment;
import com.netease.nimlib.sdk.msg.attachment.MsgAttachmentParser;

/**
 * Created by zhoujianghua on 2015/4/9.
 */
public class CustomAttachParser implements MsgAttachmentParser {

    private static final String KEY_TYPE = "type";
    private static final String KEY_DATA = "data";

    @Override
    public MsgAttachment parse(String json) {
        CustomAttachment attachment = null;
        try {
            JSONObject object = JSON.parseObject(json);
            int type = object.getInteger(KEY_TYPE);
            JSONObject data = object.getJSONObject(KEY_DATA);
            switch (type) {
                case CustomAttachmentType.Guess:
//                    attachment = new GuessAttachment();
                    break;
//                case CustomAttachmentType.SnapChat:
//                    return new SnapChatAttachment(data);
//                case CustomAttachmentType.Sticker:
//                    attachment = new StickerAttachment();
//                    break;
                case CustomAttachmentType.RTS:
//                    attachment = new RTSAttachment();
                    break;
                case CustomAttachmentType.TEST:
                    attachment = new CustomAttachmentTest();
                    break;
                case CustomAttachmentType.EVALUATE:
                    attachment = new CustomAttachmentEvaluate();
                    break;
                case CustomAttachmentType.CONSULT:
                    attachment = new CustomAttachConsult();
                    break;
                case CustomAttachmentType.ASSISTANT:
                    attachment = new CustomAttachmentRecommendAssistant();
                    break;
                case CustomAttachmentType.REDPACKET:
                    attachment = new CustomAttachRedPacket();
                    break;
                case CustomAttachmentType.REDSTATUS:
                case CustomAttachmentType.REDTIMEOUT:
                    attachment = new CustomAttachmentRedStatus();
                    break;
                case CustomAttachmentType.RECEIVEDMONEY:
                    //收款消息解析器
                    attachment = new CustomAttachReceivedMoney();
                    break;
                case CustomAttachmentType.RECEIVEDMONEY_STATUS:
                    //收款消息支付状态发生变化
                    attachment = new CustomAttachmentReceivedSuccess();
                    break;
                case CustomAttachmentType.RECEIVEDMONEY_TIMEOUT:
                    //收款消息超时未支付
                    attachment = new CustomAttachmentReceivedTimeout();
                    break;
                case CustomAttachmentType.ADD_SUBSCRIPT_TIME:
                    //添加预约时间提醒
                    attachment = new CustomAttachSubScriptTime();
                    break;
                case CustomAttachmentType.TIP_MSG:
                    //自定义样式提醒消息
                    attachment = new CustomAttachTipMsg();
                    break;
                case CustomAttachmentType.ORDER_TIP:
                    //订单状态
                    attachment = new CustomAttachmentOrderStatus();
                    break;
78
                //修改
konghaorui committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
                case CustomAttachmentType.MODIFY_TIME:
                    attachment = new CustomAttachModifyTime();
                    break;
                case CustomAttachmentType.TYPE_PHONE_CALL_RED_PACKET:
                    attachment = new CustomAttachmentPhoneCallRedPacket();
                    break;
                case CustomAttachmentType.TYPE_PHONE_CALL_SYSTEM_NOTICE:
                    attachment = new CustomAttachmentPhoneCallSystemNotice();
                    break;
                case CustomAttachmentType.TYPE_CUSTOM_SYSTEM_TIPS:
                    attachment = new CustomSystemTips();
                    break;
                case CustomAttachmentType.TYPE_RECOMMEND_EXPORTS:
                    attachment = new CustomRecommendExpertListMsg();
                    break;
                case CustomAttachmentType.TYPE_CONSULT_SUBSCRIBE_SURE:
                    //咨询预约时间确认
                    attachment = new CustomAttachConsultSubScript();
                    break;
                case CustomAttachmentType.TYPE_CONSULT_PERFECT_DATA:
                    //完善咨询资料消息
                    attachment = new CustomAttachConsultPerfectData();
                    break;
                case CustomAttachmentType.TYPE_PLEASE_SUBSCRIBE_CONSULT_DATE:
                    //请预约咨询时间
                    attachment = new CustomAttachPleaseSubscribeConsultDate();
                    break;
                case CustomAttachmentType.TYPE_CUSTOMER_SERVICE:
                    //客服小壹名片
                    attachment = new CustomCustomerServiceCardAttachment();
109
                    break;
konghaorui committed
110 111 112 113
                case CustomAttachmentType.TYPE_PUSH_SHARE:
                    //分享消息,倾诉推荐,课程,测评,文章
                    attachment = new CustomAttachmentShareMsg();
                    break;
114 115 116 117
                case CustomAttachmentType.TYPE_CUSTOMER_CONSULT_CALL_STATUS:
                    //咨询的声网拨打状态的自定义消息
                    attachment = new CustomAttachConsultCallStatus();
                    break;
严久程 committed
118 119 120
                case CustomAttachmentType.ASSISTANT_RECEIVEDMONEY:
                    attachment = new CustomAttachAssistantReceivedMoney();
                    break;
121 122 123 124
                case CustomAttachmentType.TYPE_EXPERT_DETAIL_CARD:
                    //专家自定义名片
                    attachment = new CustomAttachmentBusinessCard();
                    break;
125 126 127 128
                case CustomAttachmentType.TYPE_JUMPTO_DAOYI:
                    //跳转导医聊天界面
                    attachment = new CustomAttachmentJumpToDaoYi();
                    break;
129 130 131 132
                case CustomAttachmentType.TYPE_SWITCH_KEFU_TIPS:
                    //客服转介需求
                    attachment = new CustomAttachmentSwitchKeFuTips();
                    break;
YKai committed
133
                //41 42消息过滤掉
134 135
                case CustomAttachmentType.TYPE_FILTER_41:
                case CustomAttachmentType.TYPE_FILTER_42:
YKai committed
136
                    attachment = new CustomAttachmentFilter();
137
                    break;
138 139 140
                case CustomAttachmentType.TYPE_CONFIRM_ORDER://38  确认订单消息
                    attachment=new CustomAttachmentConfirmOrder();
                    break;
141 142 143
                case CustomAttachmentType.TYPE_ORDER_ALREADY_DONE://39  订单已完成
                    attachment=new CustomAttachmentOrderAlreadyDone();
                    break;
144 145 146
                case CustomAttachmentType.TYPE_LINGXI_WHICH_QUESTION://灵犀2.0-您想要咨询下列哪些问题
                    attachment=new CustomAttachLingxiWhichQuestion();
                    break;
konghaorui committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
                default:
                    attachment = new DefaultCustomAttachment();
                    break;
            }

            if (attachment != null) {
                attachment.fromJson(data);
            }
        } catch (Exception e) {
        }

        return attachment;
    }

    public static String packData(int type, JSONObject data) {
        JSONObject object = new JSONObject();
        object.put(KEY_TYPE, type);
        if (data != null) {
            object.put(KEY_DATA, data);
        }

        return object.toJSONString();
    }
}