📄 sendmanager.java
字号:
package com.mengzhong.mms;
/**
* <p>Title: </p>
* <p>Description: 完成发送管理工作,在发送前存盘,对发送进行缓存和流量控制</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/
import com.huawei.mms.pdu.MMSContent;
import com.huawei.mms.pdu.MMessage;
import com.huawei.mms.vas.*;
import java.io.FileInputStream;
import java.io.IOException;
public class SendManager {
public SendManager() {
rec = null;
setVASPara();
stratRecieveThread();
saveDB=new SaveDataBase();
}
public static synchronized SendManager instance() {
if(sendM == null)
sendM = new SendManager();
return sendM;
}
private void setVASPara()
{
VAS.VASP_ID = "801264";
VAS.VAS_ID = "08889";
VAS.Service_Code = "162109";
VAS.VAS_USER = "";
VAS.VAS_PASSWORD = "";
VAS.MMSC_URL = "http://218.200.244.197/vas";
VAS.From = "08889";
VAS.To = "+8613910634320/TYPE=PLMN";
}
private void stratRecieveThread()
{
rec = new MMReceiver();
rec.setListenIP("211.152.8.233");
rec.setListenPort(80);
rec.setMessageHandle(new RecieveManager());
rec.start();
}
public int send(String from,String to,String serviceCode,MMessage m)
{
MMSender s = new MMSender();
s.set("connection","keep-alive");
VAS.From=from;//计费手机号码 源手机号码
VAS.To = to;//目的手机号码
VAS.Service_Code=serviceCode;//业务代码
saveDB.saveSubmitMsg(from,to,serviceCode,m); //写库操作
int i=s.send(m);
com.mengzhong.mms.publics.PublicConstants.writeLog.info("返回状态:"+i);
System.out.println("MSG_id"+String.valueOf(m.getMessageId()));
System.out.println("MSG_desc"+m);
return i;
}
public int replyMsg(MMessage message){
MMessage newmsg = new MMessage();
String subject =String.valueOf(message.getSubject().trim());
byte[] subjectByte=subject.getBytes();
if(subject.startsWith("!")){
subject=subject.substring(1);
System.out.println("subject ! Recived convert:"+subject);
}
if(subjectByte[0]==63||subjectByte[1]==12){
subject=subject.substring(3);
System.out.println("subject Recived convert:"+subject);
}
newmsg.setSubject(subject);
newmsg.setContentType("application/vnd.wap.multipart.mixed");
MMSContent mmc = new MMSContent();
byte content[] = null;
try
{
content = (new String("标题测试回复")).getBytes("UTF8");
}
catch(Exception e)
{
content = new byte[0];
e.printStackTrace();
}
mmc.setContent(content, 0, content.length);
mmc.setType("text/plain");
mmc.setContentId("内容ID");
newmsg.addContent(mmc);
return send(String.valueOf(message.getFrom()),String.valueOf(message.getFrom()),"088890",newmsg);
}
public static byte[] readFromFile(String file_name)
throws IOException
{
FileInputStream fin = new FileInputStream(file_name);
byte buf[] = new byte[fin.available()];
fin.read(buf);
return buf;
}
private static SendManager sendM = null;
MMReceiver rec;
SaveDataBase saveDB;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -