qq_32697113 2018-07-10 13:29 采纳率: 0%
浏览 589
已结题

请大家看下如下代码?

package com.asiainfo.remind.channel.vasp;

import com.asiainfo.remind.channel.vasp.common.MMConstants;
import com.asiainfo.remind.channel.vasp.common.MMContent;
import com.asiainfo.remind.channel.vasp.conf.MM7Config;
import com.asiainfo.remind.channel.vasp.message.MM7RSRes;
import com.asiainfo.remind.channel.vasp.message.MM7SubmitReq;
import com.asiainfo.remind.channel.vasp.message.MM7SubmitRes;
import com.asiainfo.remind.channel.vasp.service.MM7Sender;
import com.asiainfo.remind.msg.MmsBeanTest;
import com.asiainfo.remind.utils.StringUtil;

import java.io.DataInputStream;
import java.util.HashMap;
import java.util.Map;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class MmsSenderForTest
{
private transient static Log log = LogFactory.getLog(MmsSenderForTest.class);
private static final String MM7_CONFIG = "mm7Config.xml";
private static final String CONN_CONFIG = "ConnConfig.xml";
private static MM7Config mm7Config = null;

static {
    if (mm7Config == null) {
        try {
            mm7Config = new MM7Config(MM7_CONFIG);
            mm7Config.setConnConfigName(CONN_CONFIG);
        } catch (Exception e) {
            log.error("初始化mm7Config失败!", e);
        }

    }
}

public static void send(MmsBeanTest MmsBeanTest) throws Exception {
    MM7Sender mm7Sender = new MM7Sender(mm7Config);
    MM7SubmitReq submit = getSubmit(MmsBeanTest);
    MM7RSRes res = mm7Sender.send(submit);
    if (res instanceof MM7SubmitRes) {
        MM7SubmitRes subRes = (MM7SubmitRes) res;
        if (log.isErrorEnabled())
            log.error("messageid=" + subRes.getMessageID() + ";res.statuscode=" + res.getStatusCode() + ";res.statusText=" + res.getStatusText());
    }
}


private static MM7SubmitReq getSubmit(MmsBeanTest MmsBeanTest) throws Exception{
    MM7SubmitReq submit = new MM7SubmitReq();
    submit.setTransactionID(StringUtil.getSeq7() + "");
    submit.addTo(MmsBeanTest.getBillId());
    submit.setVASID("10086");
    submit.setVASPID("801306");
    submit.setServiceCode("106001");
    submit.setSenderAddress("801306");
    submit.setChargedPartyID("10086");
    submit.setSubject(MmsBeanTest.getSubject());
    submit.setContent(getContent(MmsBeanTest));
    return submit;
}


 private static MMContent getContent(MmsBeanTest mmsBean) throws Exception{
    String[] subType = mmsBean.getSubType();
    DataHandler[] affix = mmsBean.getAffix();
    byte[][] subContent = new byte[affix.length][];
    for (int i = 0; i < subContent.length; i++) {
      byte[] data = (byte[])null;
      DataHandler dh = affix[i];
      DataInputStream input = new DataInputStream(dh.getInputStream());
      data = new byte[input.available()];
      input.read(data, 0, data.length);
      subContent[i] = data;
    }

    MMContent content = new MMContent();
    //content.setContentType(MMConstants.ContentType.MULTIPART_MIXED);
    content.setContentType(MMConstants.ContentType.MULTIPART_RELATED);
    content.setContentID("main");
    for (int i = 0; i < subType.length; i++) {
      MMContent sub = MMContent.createFromBytes(subContent[i]);
      subType[i] = subType[i].toLowerCase();
      if (subType[i].equals("gif")) {
        sub.setContentType(MMConstants.ContentType.GIF);
        sub.setContentID("<"+i + ".gif>");
        sub.setContentLocation(i + ".gif");
      } else if (subType[i].equals("txt")) {
        sub.setContentType(MMConstants.ContentType.TEXT);
        sub.setCharset("UTF-8");
        sub.setContentID("<"+i + ".txt>");
        sub.setContentLocation(i + ".txt");
      } else if (subType[i].equals("jpg")) {
        sub.setContentType(MMConstants.ContentType.JPEG);
        sub.setContentID("<"+i + ".jpg>");
        sub.setContentLocation(i + ".jpg");
      } else if (subType[i].equals("smil")) {
        //content.setContentType(MMConstants.ContentType.MULTIPART_RELATED);
        sub.setContentType(MMConstants.ContentType.SMIL);
        sub.setCharset("UTF-8");
        sub.setContentID("<"+i + ".smil>");
        sub.setContentLocation(i + ".smil");
      } else {
        log.error("[1002]subType exist illegal type!");
        throw new Exception("subType exist illegal type!");
      }
      content.addSubContent(sub);
    }
    return content;
  }

public static void main(String[] args) throws Exception {
    String url = Thread.currentThread().getContextClassLoader().getResource(".").getPath();
    System.out.print(url);
    MmsBeanTest mmsBean = new MmsBeanTest();
    //mmsBean.setBillId("13810256053");
    mmsBean.setBillId("13693652411");
    mmsBean.setSubject("测试");

    DataHandler dh = new DataHandler(new FileDataSource(url+"1.smil"));
    DataHandler dh1 = new DataHandler(new FileDataSource(url+"2.txt"));
    DataHandler dh2 = new DataHandler(new FileDataSource(url+"3.jpg"));
    DataHandler dh3 = new DataHandler(new FileDataSource(url+"4.txt"));

    String type[] = new String[]{"smil","txt","jpg","txt"};
    DataHandler[] content = {dh,dh1,dh2,dh3};
    mmsBean.setAffix(content);
    mmsBean.setSubType(type);

    Map map =new HashMap();
    map.put("dh",content);
    MmsSenderForTest.send(mmsBean);

}

}

smil内容:

<?xml version='1.0' encoding='GB2312'?>


















  • 写回答

6条回答 默认 最新

  • 「已注销」 2018-07-10 14:52
    关注

    就看代码,没说有啥问题呀

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算