?? mymmreceiver.java~22~
字號:
package mmsproject;
import java.util.*;
import java.io.*;
import java.sql.*;
import javax.swing.*;
//import java.awt.*;
import java.net.*;
import java.text.*;
import com.cmcc.mm7.vasp.service.*;
import com.cmcc.mm7.vasp.message.*;
import com.cmcc.mm7.vasp.conf.*;
import com.cmcc.mm7.vasp.common.*;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.DailyRollingFileAppender;
import org.apache.log4j.Level;
import mmsproject.common.*;
import mmsproject.model.*;
/**
* <p>Title: 彩信發(fā)送接收項(xiàng)目</p>
* <p>Description: 處理接收彩信</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author tomato
* @version 1.0
*/
public class MyMMReceiver extends MM7Receiver {
/**
* 2.創(chuàng)建接收代理(參見華為api)
*/
//MM7DeliverRes res = new MM7DeliverRes();
/**
* 文本信息的編碼
*/
String charset = "UTF-8";
/**
* 獲取Log對象
*/
static Logger loggerReceive = Logger.getLogger(MyMMReceiver.class.getName());
private String printTime=new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date());
/**
* 構(gòu)造函數(shù) - 主要用于初始化log發(fā)生器
*/
public MyMMReceiver() {
PatternLayout layout = new PatternLayout("%-d{yyyy-MM-dd HH:mm:ss} %m%n");
DailyRollingFileAppender appenderReceive = null;
try {
//appenderReceive = new DailyRollingFileAppender(layout, "receive.log", "yyyy-MM-dd'.'log");
appenderReceive = new DailyRollingFileAppender(layout, "receive.log", "'.'yyyy-MM-dd");
loggerReceive.addAppender(appenderReceive);
loggerReceive.setLevel((Level) Level.INFO);
} catch (Exception e) {
e.printStackTrace();
}
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* 處理到VASP的傳送(deliver)多媒體消息
*/
public MM7VASPRes doDeliver(MM7DeliverReq mm7DeliverReq ) {
int nMMContentType = 0;
String strTransactionid = null;
String strTitle = null;
String strPhoneNum = null;
String strReceiveNum = null;
String strTxt = null;
String strLinkId = null;
MM7DeliverRes res = new MM7DeliverRes();
int i = 0;
System.out.println("transactionid=" + mm7DeliverReq.getTransactionID());
try {
strTransactionid = mm7DeliverReq.getTransactionID();
} catch (Exception ex) {
}
if (mm7DeliverReq.isToExist()) {
List to = mm7DeliverReq.getTo();
for (i = 0; i < to.size(); i++) {
System.out.println("to=" + to.get(i));
strReceiveNum = to.get(i).toString();
}
}
if (mm7DeliverReq.isCcExist()) {
List cc = mm7DeliverReq.getCc();
for (i = 0; i < cc.size(); i++) {
System.out.println("cc=" + cc.get(i));
}
}
if (mm7DeliverReq.isBccExist()) {
List bcc = mm7DeliverReq.getBcc();
for (i = 0; i < bcc.size(); i++) {
System.out.println("bcc=" + bcc.get(i));
}
}
if (mm7DeliverReq.isLinkedIDExist()) {
System.out.println("linkedid=" + mm7DeliverReq.getLinkedID());
strLinkId = mm7DeliverReq.getLinkedID();
}
if (mm7DeliverReq.isMMSRelayServerIDExist()) {
System.out.println("mmsrelayserverid=" + mm7DeliverReq.getMMSRelayServerID());
}
if (mm7DeliverReq.isPriorityExist()) {
System.out.println("priority=" + mm7DeliverReq.getPriority());
}
if (mm7DeliverReq.isReplyChargingIDExist()) {
System.out.println("replycharging=" + mm7DeliverReq.getReplyChargingID());
}
if (mm7DeliverReq.isSenderExist()) {
System.out.println("sender=" + mm7DeliverReq.getSender());
strPhoneNum = mm7DeliverReq.getSender();
}
if (mm7DeliverReq.isSubjectExist()) {
System.out.println("subject=" + mm7DeliverReq.getSubject());
strTitle = mm7DeliverReq.getSubject();
}
if (mm7DeliverReq.isTimeStampExist()) {
System.out.println("timestamp=" + mm7DeliverReq.getTimeStamp());
}
//如果存在內(nèi)容體
if (mm7DeliverReq.isContentExist()) {
MMContent parentContent = mm7DeliverReq.getContent();
if (parentContent.isMultipart()) {
System.out.println("multipart");
List contentList = parentContent.getSubContents();
System.out.println("i=" + contentList.size());
for (i = 0; i < contentList.size(); i++) {
MMContent mmContent = (MMContent) contentList.get(i);
String contentID = mmContent.getContentID();
//contentID = "zxme" + i;
MMContentType mmContentType = mmContent.getContentType();
//System.out.println("contenttype=" + mmContentType.getPrimaryType() + "/" + mmContentType.getSubType());
if (mmContentType.getSubType().trim().equalsIgnoreCase("jpeg"))
contentID = contentID + ".jpg";
else if (mmContentType.getSubType().trim().equalsIgnoreCase("gif"))
contentID = contentID + ".gif";
else if (mmContentType.getSubType().trim().equalsIgnoreCase("midi"))
contentID = contentID + ".mid";
else if (mmContentType.getSubType().trim().equalsIgnoreCase("png"))
contentID = contentID + ".png";
else if (mmContentType.getPrimaryType().trim().equalsIgnoreCase("text"))
contentID = contentID + ".txt";
System.out.println("contentID=" + contentID);
//文本信息儲(chǔ)存(-注意 可能會(huì)出現(xiàn)編碼問題)
if (mmContentType.getPrimaryType().trim().equalsIgnoreCase("text")) {
try
{
strTxt = mmContent.getContentAsString();
}
catch (Exception ex)
{}
//保存其它格式內(nèi)容
} else {
try {
byte[] buffer = mmContent.getContent();
String strFullPath = MMSManage.strReceivePath + "\\" + contentID;
File file = new File(strFullPath);
if (file.exists()) {
Random r = new Random();
strFullPath = r.nextInt() + strFullPath;
}
file = null;
RandomAccessFile raf = new RandomAccessFile(strFullPath, "rw");
raf.write(buffer);
raf.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
//如果是單內(nèi)容
} else {
System.out.println("singlepart");
String contentID = parentContent.getContentID();
System.out.println("contentID=" + contentID);
if (contentID == null || contentID.length() == 0)
contentID = "zxme.";
MMContentType mmContentType = parentContent.getContentType();
if (mmContentType.getSubType().equalsIgnoreCase("jpeg"))
contentID = contentID + "jpg";
else if (mmContentType.getSubType().equalsIgnoreCase("gif"))
contentID = contentID + "gif";
else if (mmContentType.getSubType().equalsIgnoreCase("mid"))
contentID = contentID + "mid";
else if (mmContentType.getSubType().equalsIgnoreCase("png"))
contentID = contentID + "png";
else if (mmContentType.getPrimaryType().equalsIgnoreCase("txt"))
{
contentID = contentID + "txt";
//如果是文本信息才儲(chǔ)存(-注意 可能會(huì)出現(xiàn)編碼問題)
try {
strTxt = parentContent.getContentAsString();
} catch (Exception ex) {}
}
//保存其它格式內(nèi)容
else {
try {
byte[] buffer = parentContent.getContent();
String strFullPath = MMSManage.strReceivePath + "\\" + contentID;
File file = new File(strFullPath);
if (file.exists()) {
Random r = new Random();
strFullPath = r.nextInt() + strFullPath;
}
file = null;
RandomAccessFile raf = new RandomAccessFile(strFullPath, "rw");
raf.write(buffer);
raf.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
res.setTransactionID(mm7DeliverReq.getTransactionID());
res.setStatusCode(1000);
//將獲取的信息存入數(shù)據(jù)庫
addMMSData(strTransactionid, nMMContentType, strTitle, strPhoneNum, strReceiveNum,
strLinkId, strTxt);
loggerReceive.info("\r\n"
+ "MMContentType" + nMMContentType + "\r\n"
+ "Transactionid" + strTransactionid + "\r\n"
+ "title=" + strTitle + "\r\n"
+ "sender=" + strPhoneNum + "\r\n"
+ "receicer=" + strReceiveNum + "\r\n"
+ "linkid=" + strLinkId + "\r\n"
+ "content" + strTxt+ "\r\n"
);
FrmMMSManage.m_txtStatus.setText(
"收到" + strPhoneNum
+ "上行 :"+printTime
+ "\r\n"
+ FrmMMSManage.m_txtStatus.getText()
);
return res;
}
/**
* 處理到VASP的發(fā)送報(bào)告
* @param mm7DeliveryReportReq MM7DeliveryReportReq
* @return MM7VASPRes
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -