欢迎来到Doc100.Net免费学习资源知识分享平台!
您的位置:首页 > 程序异常 >

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

更新时间: 2014-01-05 02:52:16 责任编辑: Author_N1

 

(急)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());
        }
    }

 			
			
		
上一篇:上一篇
下一篇:下一篇

 

随机推荐程序问答结果

 

 

如对文章有任何疑问请提交到问题反馈,或者您对内容不满意,请您反馈给我们DOC100.NET论坛发贴求解。
DOC100.NET资源网,机器学习分类整理更新日期::2014-01-05 02:52:16
如需转载,请注明文章出处和来源网址:http://www.doc100.net/bugs/t/15545/
本文WWW.DOC100.NET DOC100.NET版权所有。