当前位置: 代码迷 >> 移动应用 >> (急)mm7怎样发送smil格式的彩信解决方案
  详细解决方案

(急)mm7怎样发送smil格式的彩信解决方案

热度:232   发布时间:2016-04-25 08:30:10.0
(急)mm7怎样发送smil格式的彩信
请大家帮帮忙,mm7协议怎样发送带smil格式的彩信,代码如下:
Java code
public void submitSmil2(MMessageWrapper wapper) {        System.out.println(":::::::用mm7协议发送smil内容彩信");        LogHelper.debug(":::::::用mm7协议发送smil内容彩信");        MMessageContent content = wapper.getContent();        MM7SubmitReq submit = new MM7SubmitReq();        submit.setTransactionID("" + SequnceNumber.getSequnceID());        submit.setVASPID(Constants.vaspId);        submit.setVASID(Constants.vasId);        String to = wapper.getDesTermId();        submit.addTo(to);        String submitId = content.getSubmitId();        submit.setServiceCode(submitId);        String srcTermId = content.getSrcTermId();        submit.setSenderAddress(replaceSrc(srcTermId, Constants.vasId,                        submitId));        submit.setSubject(content.getSubject());        submit.setChargedParty((byte) 4); // 计费方式0:Sender、1:Recipients、2:Both、3:Neither、4:ThirdParty        submit.setChargedPartyID(wapper.getFeeTermId()); // 计费方        submit.setDeliveryReport(true);        submit.setReadReply(true);        submit.setPriority((byte) 1);        submit.setLinkedID(wapper.getLinkID());        MMContent mmcontent = new MMContent();        mmcontent.setContentType(MMConstants.ContentType.MULTIPART_RELATED);        ArrayList atts = content.getAttachments();//smil、图片、文字、声音内容        for (int i = 0; i < atts.size(); i++) {            Attachment att = (Attachment) atts.get(i);            if (att != null) {                if (att.getBinary() == null || att.getBinary().length == 0) {                    System.out.println("内容有空");                    continue;                }                byte[] buf = att.getBinary();                MMContent mmc = null;                String ct = att.getContentType();                if ("application/smil".equalsIgnoreCase(ct)) {                    System.out.println("application/smil类型");                    try {                        String s = new String(buf, "GB2312");                        mmc = MMContent.createFromBytes(s.getBytes("UTF-8"));                    } catch (UnsupportedEncodingException e) {                        e.printStackTrace();                    }                    mmc.setContentType(MMConstants.ContentType.SMIL);                    mmc.setContentID(att.getContentId());                    mmc.setContentLocation(att.getContentLocation());                    mmc.setCharset("UTF-8");                    mmcontent.setPresentionContent(mmc);                    continue;                }                if ("text/plain".equalsIgnoreCase(ct)) {                    System.out.println("text/plainl类型");                    try {                        String s = new String(buf, "GB2312");                        mmc = MMContent.createFromBytes(s.getBytes("UTF-8"));                    } catch (UnsupportedEncodingException ex1) {                        ex1.printStackTrace();                    }                    System.out.println("MMContent setCharset UTF-8");                    mmc.setCharset("UTF-8");                } else {                    System.out.println("不是text/plain类型 ");                    mmc = MMContent.createFromBytes(buf);                }                if (mmc != null) {                    mmc.setContentType(ct);                    mmc.setContentID(att.getContentId());                    mmc.setContentLocation(att.getContentLocation());                }                mmcontent.addSubContent(mmc);            }        }        submit.setContent(mmcontent);        try {            MM7Sender mm7Sender = new MM7Sender(mm7Config);            MM7RSRes rsRes = mm7Sender.send(submit);            String statusText = rsRes.getStatusText();            if (rsRes instanceof MM7SubmitRes) {                MM7SubmitRes submitRes = (MM7SubmitRes) rsRes;                wapper.setMsgID(submitRes.getMessageID());            } else {                System.out.println("MM7RSRes toString(): " + rsRes.toString());            }            int statusCode = rsRes.getStatusCode();            wapper.setResultCode("" + statusCode);            wapper.setResultMsg(statusText);            wapper.setSubmitTime(System.currentTimeMillis());            System.out.println("SJ:" + content.getSubject() + " SRV:"                    + content.getServiceId() + " SUB:" + content.getSubmitId()                    + " FROM:" + wapper.getFeeTermId() + " TO:"                    + wapper.getDesTermId() + " MID:" + wapper.getMsgID()                    + " CODE:" + statusCode + " MSG:" + statusText + " LinkID:"                    + wapper.getLinkID());            // if (statusCode > 0) modified by chtm 2006.1.16            if (statusCode == 1000) {                Logger.logMT(wapper);            } else {                int retry = wapper.getRetry();                if (retry > 0) {                    wapper.setRetry(retry - 1);                    SubmitQueue.addMessage(wapper);                } else {                    Logger.logMT(wapper);                }            }        } catch (Exception e) {            e.printStackTrace();            System.out.println("send error::" + e.toString());        }    }
  相关解决方案