我用模拟网管看话大于70个字符MessageContent中就没值了~,
发到真实的网关也不报错但手机收不到
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import com.huawei.smproxy.comm.sgip.message.SGIPDeliverMessage;
import com.huawei.smproxy.comm.sgip.message.SGIPMessage;
import com.huawei.smproxy.comm.sgip.message.SGIPReportMessage;
import com.huawei.smproxy.comm.sgip.message.SGIPSubmitMessage;
import com.huawei.smproxy.util.Args;
public class Sgip12 {
private static Logger logger = LogManager.getLogger(Sgip12.class);
private static Sgip12 ins = null;
private SgipProxy12 smp = null;
private static String SPNumber = "10655021999999";
private static String ChargeNumber = "000000000000000000000";
private static String ServiceType = "SHGRP";
private static String host = "127.0.0.1";
private static int port = 8801;
private static String CorpId = "111111";
private static String login_Name = "111111111";
private static String login_PassWord = "rrrrr";
public static final int MAX_LENGTH = 67;
public static final int MSG_MAX_LEN = 67;
private static Random rand = new Random(System.currentTimeMillis());
private Sgip12() {
this.reConn();
}
public static Sgip12 getInstance() {
if (ins == null) {
synchronized (Sgip12.class) {
if (ins == null)
ins = new Sgip12();
}
}
return ins;
}
public void ProcessRecvDeliverMsg(SGIPMessage msg) {
SGIPDeliverMessage deliverMsg = (SGIPDeliverMessage) msg;
logger.info("deliverMsg.getCommandId() : " + deliverMsg.getSequenceId());
}
public void ProcessRecvReportMsg(SGIPMessage msg) {
SGIPReportMessage reportMessage = (SGIPReportMessage) msg;
logger.info("reportMessage.getCommandId() : "
+ reportMessage.getSequenceId()+" : "
+ reportMessage.getState());
}
public void Terminate() {
logger.info("SSSSS!!!!!");
}
private SGIPSubmitMessage[] createSGIPMessages(String[] mobiles,
String[] msgs) throws Exception {
SGIPSubmitMessage[] ret = new SGIPSubmitMessage[msgs.length];
byte uid = (byte) rand.nextInt(256);
for (int i = 0; i < msgs.length; i++) {
byte[] msgBytes = msgs[i].getBytes("ISO-10646-UCS-2");
SGIPSubmitMessage msg = new SGIPSubmitMessage(SPNumber, // SPNumber
ChargeNumber, // ChargeNumber
mobiles, // UserNumber
CorpId, // CorpId
ServiceType, // ServiceType
0, // FeeType
"0", // FeeValue
"0", // GivenValue
0, // AgentFlag
2, // MorelatetoMTFlag
0, // Priority
null, // xpireTime
null, // ScheduleTime
1, // ReportFlag
0, // TP_pid
msgs.length > 1 ? 1 : 0,// TP_udhi
8, // MessageCoding
1, // MessageType
msgs.length > 1 ? (msgBytes.length + 6) : msgBytes.length, // MessageLength
msgs.length > 1 ? appendLongMsgHead(uid,
(byte) msgs.length, (byte) i, msgBytes) : msgBytes, // MessageContent
"abc" // reserve
);
ret[i] = msg;
}
return ret;
}
private static byte[] appendLongMsgHead(byte uid, byte total, byte idx,
byte[] msg) {
byte[] ret = new byte[6 + msg.length];
ret[0] = 0x05; //
ret[1] = 0x00; //
ret[2] = 0x03; //
ret[3] = uid; //
ret[4] = total; //
ret[5] = ++idx; //
System.arraycopy(msg, 0, ret, 6, msg.length);
return ret;
}
private synchronized boolean reConn() {
try {
if (smp == null) {
Args args = new Args();
int srcnode = new BigInteger("3000099999").intValue();
args.set("host", host);
args.set("port", port);
args.set("transaction-timeout", 10);
args.set("read-timeout", 15);
args.set("source-addr", srcnode);
args.set("login-name", login_Name);
args.set("login-pass", login_PassWord);
args.set("debug", "true");
smp = new SgipProxy12(this, args);
}
if (smp.getConnState() == null)
return true;
if (smp.connect(login_Name, login_PassWord)) {
logger.info("dsadsa!");
return true;
} else {
logger.info("dsadsa!");
return false;
}
} catch (Exception e) {
logger.error("dsadas!", e);
return false;
}
}
public void sendMsg(String mobile, String content) throws Exception {
this.sendMsg(new String[] { mobile }, content);
}
public void sendMsg(String[] mobiles, String content) throws Exception {
try {
content = new String (content.getBytes("ISO-10646-UCS-2"));
String[] strMsg = splitMsg(content);
SGIPSubmitMessage[] aa = createSGIPMessages(mobiles,strMsg);
for (int i = 0; i < aa.length; i++) {
this.smp.send(aa[i]);
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw e;
}
}
private static String[] splitMsg(String content) {
List<String> list = new ArrayList<String>();
String ss = null;
while (content.length() >= MSG_MAX_LEN) {
ss = content.substring(0, MSG_MAX_LEN);
content = content.substring(MSG_MAX_LEN, content.length());
list.add(ss);
}
if (content.length() > 0) {
list.add(content);
}
return list.toArray(new String[] {});
}
public SgipProxy12 getSmp() {
return smp;
}
}
1 个解决方案
#1
参考一下这个?http://tech.it168.com/d/2008-07-07/200807071629278.shtml
#1
参考一下这个?http://tech.it168.com/d/2008-07-07/200807071629278.shtml