Search in sources :

Example 1 with LongSMSMessage

use of com.zx.sms.LongSMSMessage in project SMSGate by Lihuanghe.

the class AbstractLongMessageHandler method encode.

@Override
protected void encode(ChannelHandlerContext ctx, T requestMessage, List<Object> out) throws Exception {
    if ((entity == null || entity.getSupportLongmsg() == SupportLongMessage.BOTH || entity.getSupportLongmsg() == SupportLongMessage.SEND) && requestMessage instanceof LongSMSMessage && needHandleLongMessage(requestMessage)) {
        SmsMessage msgcontent = ((LongSMSMessage) requestMessage).getSmsMessage();
        List<LongMessageFrame> frameList = LongMessageFrameHolder.INS.splitmsgcontent(msgcontent);
        boolean first = true;
        LongSMSMessage lmsg = (LongSMSMessage) requestMessage;
        for (LongMessageFrame frame : frameList) {
            T t = (T) lmsg.generateMessage(frame);
            out.add(t);
        }
    } else {
        out.add(requestMessage);
    }
}
Also used : LongSMSMessage(com.zx.sms.LongSMSMessage) SmsMessage(org.marre.sms.SmsMessage)

Example 2 with LongSMSMessage

use of com.zx.sms.LongSMSMessage in project SMSGate by Lihuanghe.

the class ChannelUtil method syncWriteLongMsgToEntity.

public static <T extends BaseMessage> List<Promise<T>> syncWriteLongMsgToEntity(EndpointEntity e, BaseMessage msg) throws Exception {
    EndpointConnector connector = e.getSingletonConnector();
    if (connector == null)
        return null;
    if (msg instanceof LongSMSMessage) {
        LongSMSMessage<BaseMessage> lmsg = (LongSMSMessage<BaseMessage>) msg;
        if (!lmsg.isReport()) {
            // 长短信拆分
            SmsMessage msgcontent = lmsg.getSmsMessage();
            List<LongMessageFrame> frameList = LongMessageFrameHolder.INS.splitmsgcontent(msgcontent);
            // 保证同一条长短信,通过同一个tcp连接发送
            List<BaseMessage> msgs = new ArrayList<BaseMessage>();
            for (LongMessageFrame frame : frameList) {
                BaseMessage basemsg = (BaseMessage) lmsg.generateMessage(frame);
                msgs.add(basemsg);
            }
            return connector.synwrite(msgs);
        }
    }
    Promise promise = connector.synwrite(msg);
    if (promise == null) {
        // 为空,可能是连接断了,直接返回
        return null;
    }
    List<Promise<T>> arrPromise = new ArrayList<Promise<T>>();
    arrPromise.add(promise);
    return arrPromise;
}
Also used : EndpointConnector(com.zx.sms.connect.manager.EndpointConnector) LongSMSMessage(com.zx.sms.LongSMSMessage) Promise(io.netty.util.concurrent.Promise) SmsMessage(org.marre.sms.SmsMessage) BaseMessage(com.zx.sms.BaseMessage) LongMessageFrame(com.zx.sms.codec.cmpp.wap.LongMessageFrame) ArrayList(java.util.ArrayList)

Aggregations

LongSMSMessage (com.zx.sms.LongSMSMessage)2 SmsMessage (org.marre.sms.SmsMessage)2 BaseMessage (com.zx.sms.BaseMessage)1 LongMessageFrame (com.zx.sms.codec.cmpp.wap.LongMessageFrame)1 EndpointConnector (com.zx.sms.connect.manager.EndpointConnector)1 Promise (io.netty.util.concurrent.Promise)1 ArrayList (java.util.ArrayList)1