📄 mmtoolkit.java
字号:
/**
* <pre>
* 这里说明修改记录,包括修改人,修改时间和修改目的和内容
* ---修改时间---修改人---修改目的和内容----------------------
* 2006/2/24 刘华锋 主题为空时,不调用submit.setSubject()这个method
* 2006/2/26 刘华锋 修改后缀名为大写时,和contenttype的配套问题,行数为148行
* </pre>
*/
package com.sxit.mms.sender;
import java.io.File;
import java.util.HashMap;
import org.apache.log4j.Logger;
import com.cmcc.mm7.vasp.common.MMConstants;
import com.cmcc.mm7.vasp.common.MMContent;
import com.cmcc.mm7.vasp.common.MMContentType;
import com.cmcc.mm7.vasp.message.MM7SubmitReq;
import com.sxit.mms.MMSQueue;
/**
*
* @author HuaFeng
* @version 1.0 (2006-1-13 15:49:52)
*
*/
public class MMToolKit {
private final static Logger log = Logger.getLogger(MMToolKit.class);
private final static HashMap fileMap;
static {
fileMap = new HashMap();
fileMap.put("amr", MMConstants.ContentType.AMR);
fileMap.put("midi", MMConstants.ContentType.MIDI);
fileMap.put("mid", MMConstants.ContentType.MIDI);
fileMap.put("gif", MMConstants.ContentType.GIF);
fileMap.put("jpg", MMConstants.ContentType.JPEG);
fileMap.put("jpeg", MMConstants.ContentType.JPEG);
fileMap.put("png", MMConstants.ContentType.PNG);
fileMap.put("txt", MMConstants.ContentType.TEXT);
fileMap.put("imy", MMConstants.ContentType.I_MELODY);
fileMap.put("ime", MMConstants.ContentType.E_MELODY);
// E_MELODY可能为下面的emy后缀的
fileMap.put("emy", MMConstants.ContentType.E_MELODY);
// 要看看mmf格式的是啥子样子的了
fileMap.put("mmf", new MMContentType("application/vnd.smaf").lock());
fileMap.put("html", new MMContentType("text/html").lock());
fileMap.put("htm", new MMContentType("text/html").lock());
fileMap.put("shtml", new MMContentType("text/html").lock());
fileMap.put("wbmp", MMConstants.ContentType.WBMP);
fileMap.put("wml", new MMContentType("text/vnd.wap.wml").lock());
fileMap.put("tif", new MMContentType("image/tiff").lock());
//
fileMap.put("wav", new MMContentType("audio/x-wav").lock());
fileMap.put("smil", MMConstants.ContentType.SMIL);
}
/**
* 得到该目录下的所有文件,并组装成MM的内容
*
* @param mmdir
* @return
*/
public MM7SubmitReq createMM(MMSQueue queue, MM7SubmitReq tempSubmit, String tempDir) {
MM7SubmitReq submit = new MM7SubmitReq();
// 下发的时候,使用mmsc分配的接入号和企业代码
submit.setVASID(CommonProperties.mmsSPNumber); // 接入号
submit.setVASPID(CommonProperties.mmsCorpID);// 企业代码
// submit.setVASID(CommonProperties.mmsSPNumber);
// submit.setVASPID(CommonProperties.mmsCorpID);
System.out.println(submit.getVASID()+"---"+submit.getVASPID());
submit.setServiceCode(queue.getServiceCode()==null?"":queue.getServiceCode());// 计费的业务代码
// submit.setServiceCode(queue.getServiceCode());
System.out.println("******"+submit.getServiceCode()+"====");
submit.setSenderAddress(queue.getVasFrom());// 发送方地址,一般填接入号+业务代码+操作码
System.out.println("******"+submit.getSenderAddress()+"====");
submit.addTo(queue.getVasTO());// 接受方号码
submit.setTransactionID(String.valueOf(queue.getQueueID()));// 处理之流水好,submitresp消息会返回此
if (queue.getSubject() != null)
submit.setSubject(queue.getSubject());// 主题
// else
// submit.setSubject("无主题");
// 加上了下面,好像会导致状态报告回不来
// submit.setPriority((byte) queue.getPriority());// 优先级
// submit.setMessageClass(queue.getMessageClass());// auto?personal?等等
if (queue.getFeeMobile() != null && !"".equals(queue.getFeeMobile())) {
submit.setChargedPartyID(queue.getFeeMobile()); // 如果计费号码非空的话,则填入计费号码并类型字段填4
submit.setChargedParty((byte) 4);
}
else {// 计费号码为空的话,根据库中取得的计费类型即可
submit.setChargedParty((byte) queue.getFeeMobileType());
}
if (queue.getReportFlag() == 1)// 状态报告
submit.setDeliveryReport(true);
else
submit.setDeliveryReport(false);
if (queue.getReadReply() == 1)// 读后回复消息
submit.setReadReply(true);
else
submit.setReadReply(false);
// 如果mm的存储路径是一样的,则不再组装彩信内容,使用之前的submit消息同样的内容
if (log.isDebugEnabled()) {
log.debug("tempDir=" + tempDir + ",queue.getMMDir()=" + queue.getMMDir());
log.debug("tempDir.equals(queue.getMMDir()):" + tempDir.equals(queue.getMMDir()));
}
if (!tempDir.equals(queue.getMMDir())) {
createMMContent(queue.getMMDir(), submit);
}
else {
log.info("相同的彩信内容,不再组装彩信!");
submit.setContent(tempSubmit.getContent());
}
// if (log.isDebugEnabled())
// log.debug(submit);
return submit;
}
private void createMMContent(String submitdir, MM7SubmitReq submit) {
if (!submitdir.endsWith("/"))
submitdir = submitdir + "/";
File submitdirs = new File(submitdir);
if (!submitdirs.exists()) {
log.warn("彩信目录不存在,彩信内容为空!");
submit.setContent(null);
return;
}
File[] files = submitdirs.listFiles();
if (log.isDebugEnabled()) {
log.debug("files.length==" + files.length);
}
MMContent content = new MMContent();
MMContent subContent = null;
content.setContentType(MMConstants.ContentType.MULTIPART_MIXED);
content.setContentLocation(submit.getTransactionID());
content.setContentID(submit.getTransactionID());
for (int i = 0; i < files.length; i++) {
String name = files[i].getName();
String endfix = name.substring(name.lastIndexOf(".") + 1);
if (log.isDebugEnabled())
log.debug("名字=" + name + "-后缀=" + endfix);
// 如果是文本类型的,必须是utf-8字符集类型
subContent = MMContent.createFromFile(submitdir + name);
// System.out.println("submitdir + name="+submitdir + name);
// System.out.println(subContent.getSize());
if (endfix.equals("smil")) {
content.setContentType(MMConstants.ContentType.MULTIPART_RELATED);
content.setPresentionContent(subContent);
if (log.isDebugEnabled())
log.debug("SMIL类型的彩信!");
}
subContent.setContentType((MMContentType) fileMap.get(endfix.toLowerCase()));
//改为上面的,以免后缀名为大写时,找不到类型,2006/2/26修改
// subContent.setContentType((MMContentType) fileMap.get(endfix));
// if (log.isDebugEnabled())
// log.debug("文件类型=" + subContent.getContentType());
subContent.setContentID(name);
subContent.setContentLocation(name);
content.addSubContent(subContent);
}
submit.setContent(content);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -