CustomAttachParser.java 5.78 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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
                case CustomAttachmentType.TYPE_PUSH_SHARE:
                    //分享消息,倾诉推荐,课程,测评,文章
                    attachment = new CustomAttachmentShareMsg();
                    break;
                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();
    }
}