⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mymmreceiver.java

📁 彩信开发一般应用好了不?彩信开发一般应用好了不?彩信开发一般应用好了不?彩信开发一般应用好了不?彩信开发一般应用好了不?
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
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: 彩信发送接收项目</p>
 * <p>Description: 处理接收彩信</p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author tomato
 * @version 1.0
 */
public class MyMMReceiver extends MM7Receiver {
    /**
     * 2.创建接收代理(参见华为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());
    /**
     * 构造函数 - 主要用于初始化log发生器
     */
    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());
        }

        //如果存在内容体
        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);

                    //文本信息储存(-注意 可能会出现编码问题)
                    if (mmContentType.getPrimaryType().trim().equalsIgnoreCase("text")) {
                        try
                        {
                            strTxt = mmContent.getContentAsString();
                        }
                        catch (Exception ex)
                        {}


                        //保存其它格式内容
                    } 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();
                        }
                    }
                }
                //如果是单内容
            } 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";

                //如果是文本信息才储存(-注意 可能会出现编码问题)
                try {
                    strTxt = parentContent.getContentAsString();
                } catch (Exception ex) {}
                }

                //保存其它格式内容
                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);

        //将获取的信息存入数据库
        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的发送报告
     * @param mm7DeliveryReportReq MM7DeliveryReportReq
     * @return MM7VASPRes

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -