📄 mt_send.java
字号:
package com.hoten.communicate.mt;
import com.hoten.cmpp.*;
import com.hoten.cmpp.message.*;
import com.hoten.communicate.info.*;
import com.hoten.util.*;
import java.io.*;
import java.util.*;
import com.hoten.tail.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/
public class MT_Send implements Runnable {
private static boolean flag = true;
private MTInfoList mtList = MTInfoList.getInstance();
private com.hoten.cmpp.CMPP_Shell cmpp = null;
private static int i = 0;
private static int j = 0;
private String logFile = MOParam.getInstance().logFile;
private String errorFile = MOParam.getInstance().errorFile;
private DBAccess dbm = new DBAccess();
private String shellName = null;
private String area = null;
private String table = null;
private String pid = null;
private String msg = null;
private int sleepTime = 100;
public MT_Send(String shell, String sArea, String areaName) {
shellName = shell.toUpperCase();
area = sArea.toUpperCase();
if (area == null)
area = "JSYD";
if (area.equals("JSYD") || area.equals("ZJYD"))
table = "sendInfo";
else if (area.equals("AHYD"))
table = "sendinfo_ah";
else
table = "ui_sendinfo";
msg = areaName;
this.pid = shellName;
mtList.regedit(area);
try {
initSetI();
initCMPP(); //初始化连接
}
catch (Exception ex) {
Log.printError(ex, "ERROR", logFile);
stopThread(); //不成功停止线程的启动
}
}
public static void stopThread() {
flag = false;
}
private void initSetI() throws Exception {
String sql = "select max(xh) from " + table + " where substr(xh,1," +
pid.length() + ")='" + pid +
"' and qqfssj> to_char(Sysdate-3,'yymmdd')";
String xh = dbm.select(sql);
if (xh == null)
i = 0;
else {
if (xh.equals("")) {
i = 0;
}
else {
i = Integer.parseInt(xh.trim().substring(pid.length()));
}
}
}
public void run() {
Log.printEvent("------" + msg + "通信MT_Send启动------", logFile);
int sendNum = 0;
try {
while (flag) {
MTInfo mtInfo = mtList.remove(area); //取得一条数据
if (mtInfo == null || mtInfo.getXXNR() == null) {
try {
cmpp.submit(null);
}
catch (Exception ex) {
}
Thread.currentThread().sleep(sleepTime * 3);
j++;
if (j == 10) {
j = 0;
TailTools.dealTail(area, "1", "1",
"MT$$时间:" +
CTime.getTime(CTime.YYMMDDhhmmss) +
"$$手机号码:" + "$$特服号:" +
"$$消息:当前无待发送信息......");
}
continue;
}
try {
if (true) { //!isBlack(mtInfo.getSJHM(),mtInfo.getArea(),dbm)){
sendMT(mtInfo); //发生消息
}
else {
TailTools.dealTail(area, "1", "1",
"MT黑名单$$发送时间:" +
CTime.getTime(CTime.YYMMDDhhmmss) +
"$$手机号码:" + mtInfo.getSJHM() +
"$$特服号:" + mtInfo.getBZ3() + "$$消息:" +
mtInfo.getXXNR());
}
}
catch (Exception ex) {
Log.printError(ex, "", errorFile);
}
mtInfo = null;
Thread.currentThread().sleep(sleepTime);
}
}
catch (InterruptedException ex) {
}
quitCMPP();
Log.printEvent("------" + msg + "通信MT_Send关闭------", logFile);
}
private boolean isBlack(String mobile, String area, DBAccess dba) {
if (mobile.length() > 11)
return false;
try {
String sql = "select mobile from ws_blacklist where mobile='" +
mobile + "' and area = '" + area +
"' and blacklevel in ('1','2') ";
String check = dba.select(sql);
if (check != null)
return true;
}
catch (Exception ex) {
return false;
}
return false;
}
private void sendMT(MTInfo mtInfo) throws Exception {
com.hoten.cmpp.message.SubmitMsg cs = new com.hoten.cmpp.message.
SubmitMsg(); //下发消息
setSubmitMsg(cs, mtInfo); //封装mt消息
int stat = -1;
try {
CMPPHead head = cmpp.submit(cs); //提交下发的消息
stat = head.stat;
Log.printEvent("Time:" + CTime.getTime(12) + " STATE:" + stat,
logFile);
}
catch (Exception ex) {
Log.printError(ex, mtInfo.getJTLY(),
mtInfo.getXXNR() + " ERROR: submit error", errorFile);
}
if (mtInfo.getBZ2() != null && mtInfo.getBZ2().equals("JF"))
TailTools.dealTail(area, "1", "1",
"MT$$发送时间:" + CTime.getTime(CTime.YYMMDDhhmmss) +
"$$手机号码:" + mtInfo.getSJHM() + "$$发送状态:" + stat +
"$$计费金额:" + mtInfo.getFee() + "$$计费代码:" +
mtInfo.getYWDM());
else
TailTools.dealTail(area, "1", "1",
"MT$$发送时间:" + CTime.getTime(CTime.YYMMDDhhmmss) +
"$$手机号码:" + mtInfo.getSJHM() + "$$发送状态:" + stat + "$$特服号:" +
mtInfo.getBZ3() + "$$消息:" +
mtInfo.getXXNR());
if (mtInfo.getBZ2() != null && mtInfo.getBZ2().equals("JF") &&
stat == 0)
return;
saveState(stat, mtInfo); //记录下发的消息的状态
}
private void quitCMPP() {
cmpp.quit();
}
private void initCMPP() throws Exception {
cmpp = new CMPP_Shell(shellName);
cmpp.initCMPP(MOParam.getInstance().initPath + shellName +
".properties");
}
private void setSubmitMsg(com.hoten.cmpp.message.SubmitMsg msg2,
MTInfo mtInfo) throws Exception {
msg2.nDestUsrTl = 1;
msg2.nFeeUserType = 0;
msg2.nMsgFormat = 15;
msg2.nMsgLength = mtInfo.getXXNR().length();
msg2.nNeedReply = 0;
msg2.sDestTerminalId = mtInfo.getSJHM();
msg2.sFeeCode = mtInfo.getFee();
msg2.sFeeMobile = mtInfo.getJTLY();
if (mtInfo.getJTLY() != null)
msg2.nFeeUserType = 3;
if (mtInfo.getFlagFee().equals("1"))
msg2.sFeeType = "02";
if (mtInfo.getFlagFee().equals("2"))
msg2.sFeeType = "03";
if (mtInfo.getFlagFee().equals("3"))
msg2.sFeeType = "01";
msg2.sMsgContent = mtInfo.getXXNR();
msg2.sServiceId = mtInfo.getYWDM();
msg2.sSrcId = mtInfo.getBZ3();
if (mtInfo.getXXLX() != null && mtInfo.getXXLX().equals("0")) { //ASCII串,可以最多有160个字符
msg2.isSplit = false;
msg2.nMsgFormat = 0;
}
if (mtInfo.getXXLX() != null && mtInfo.getXXLX().equals("2")) { //诺基亚的图片
msg2.isSplit = false;
msg2.isPicOrRing = true;
msg2.nMsgFormat = 4;
msg2.nTPudhi = 1;
}
if (mtInfo.getXXLX() != null && mtInfo.getXXLX().equals("3")) { //诺基亚的铃声
msg2.isSplit = false;
msg2.isPicOrRing = true;
msg2.nMsgFormat = 4;
msg2.nTPudhi = 1;
}
if (mtInfo.getXXLX() != null && mtInfo.getXXLX().equals("4")) { //西门子的图片
msg2.isSplit = false;
msg2.isPicOrRing = true;
msg2.nMsgFormat = 0xf5;
}
if (mtInfo.getXXLX() != null && mtInfo.getXXLX().equals("5")) { //西门子的铃声
msg2.isSplit = false;
msg2.isPicOrRing = true;
msg2.nMsgFormat = 0xf5;
}
if (mtInfo.getXXLX() != null && mtInfo.getXXLX().equals("6")) { //Motorola的图片
msg2.isSplit = false;
msg2.isPicOrRing = true;
msg2.nMsgFormat = 4;
msg2.nTPudhi = 1;
}
if (mtInfo.getXXLX() != null && mtInfo.getXXLX().equals("7")) { //Motorola的铃声
msg2.isSplit = false;
msg2.isPicOrRing = true;
msg2.nMsgFormat = 4;
msg2.nTPudhi = 1;
}
if (mtInfo.getXXLX() != null && mtInfo.getXXLX().equals("8")) { //飞利浦的图片
msg2.isSplit = false;
msg2.isPicOrRing = true;
msg2.nMsgFormat = 0xf6;
}
if (mtInfo.getXXLX() != null && mtInfo.getXXLX().equals("9")) { //飞利浦的铃声
msg2.isSplit = false;
msg2.isPicOrRing = true;
msg2.nMsgFormat = 0xf6;
}
if (mtInfo.getXXLX() != null && mtInfo.getXXLX().equals("8")) { //爱立信的图片
msg2.isSplit = false;
msg2.isPicOrRing = true;
msg2.nMsgFormat = 0xf5;
msg2.nTPudhi = 1;
}
if (mtInfo.getXXLX() != null && mtInfo.getXXLX().equals("9")) { //爱立信的铃声
msg2.isSplit = false;
msg2.isPicOrRing = true;
msg2.nMsgFormat = 0xf5;
msg2.nTPudhi = 1;
}
if (mtInfo.getArea().equals("EXYD")) {
if (mtInfo.getBZ1().endsWith("YLY")) {
mtInfo.setFlagFee("2");
mtInfo.setYWDM("YLYDDT");
msg2.sFeeCode = "500";
msg2.sFeeType = "03";
msg2.sServiceId = "YLYDDT";
}
if (mtInfo.getBZ1().startsWith("KING")) {
mtInfo.setFlagFee("2");
mtInfo.setYWDM("YXKINGB");
msg2.sFeeCode = "800";
msg2.sFeeType = "03";
msg2.sServiceId = "YXKINGB";
}
if (mtInfo.getBZ1().startsWith("SEARCH")) {
mtInfo.setFlagFee("2");
mtInfo.setYWDM("YXTBY");
msg2.sFeeCode = "800";
msg2.sFeeType = "03";
msg2.sServiceId = "YXTBY";
}
}
if (mtInfo.getArea() == null)
mtInfo.setArea("JSYD");
if (mtInfo.getBZ2() != null && mtInfo.getBZ2().equals("JF"))
msg2.nNeedReply = 2;
}
private void saveState(int stat, MTInfo mtInfo) {
mtInfo.setXH(getXH());
try {
DBCommon.RecodeMT(stat, mtInfo, dbm, table);
}
catch (Exception ex) {
Log.printError(ex, mtInfo.getJTLY(), mtInfo.getXXNR() + " ERROR: 数据库操作发生错误",
errorFile);
}
}
private String getXH() {
synchronized (this.getClass()) {
i++;
if (i == 10000000)
i = 0;
}
return pid + getFormatTime(i, 7);
}
private String getFormatTime(int time, int format) {
StringBuffer numm = new StringBuffer();
int length = String.valueOf(time).length();
if (format < length)
return null;
for (int i = 0; i < format - length; i++) {
numm.append("0");
}
numm.append(time);
return numm.toString().trim();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -