package com;import java.io.UnsupportedEncodingException;
import java.math.BigInteger;import com.huawei.insa2.comm.sgip.message.SGIPMessage;
import com.huawei.insa2.comm.sgip.message.SGIPSubmitMessage;
import com.huawei.insa2.comm.sgip.message.SGIPSubmitRepMessage;
import com.huawei.insa2.util.Args;
import com.huawei.smproxy.SGIPSMProxy;public class Send {
// private static Logger log = LogManager.getLogger("send");
private static String SPNumber = "3010012345";//接入号码
private static String ChargeNumber = "000000000000000000000"; // 计费号码,我们是白名单
private static String ServiceType = "3010012345";//服务类型
private static String host = "xxxxxxxxxxx"; // 主机名,网关IP
private static int port = 8001; // 端口号,这里特别注意下,接入协议中写的是8804,害得我调了很久,后来才知道改了,所以,这个在接入前,建议与网关人员确定//原来的只是8881
private static String CorpId = "99999"; // 企业代码
private static String login_Name = "xxx"; // 登陆名
private static String login_PassWord = "xxxx"; // 登陆密码 public static void main(String[] args) throws UnsupportedEncodingException {
int srcnode =new BigInteger("30000"+"99999").intValue();    //源节点编号,这一步非常重要,华为包中,该字段类型为int,而接入协议中要求在企业代码前加上30000,这样就超过了int的取值范围,所以需要用BigInteger转一下就可以了
Args argstr = new Args();
argstr.set("host", host);
argstr.set("port", port);
argstr.set("transaction-timeout", 10); // 操作超时时间(单位:秒)
argstr.set("read-timeout", 15); // 物理连接读操作超时时间(单位:秒)
argstr.set("source-addr",  srcnode); // SP…ID(最大为六位字符)
argstr.set("login-name", login_Name);
argstr.set("login-pass", login_PassWord);
argstr.set("debug", "true");

// 连接登陆zhuxiao5
SGIPSMProxy sgipsmp = new SGIPSMProxy(argstr); // 这里
try {
boolean reslut = sgipsmp.connect(login_Name, login_PassWord); // 登陆得到true和false System.out.println("reslut:::::::" + reslut);
if (reslut) {
System.out.println("连接成功...........");
} else {
System.out.println("连接失败(用户名或密码错误)...........");
return;
}
} catch (Exception ex) {
System.out.println("网络异常...........");
ex.printStackTrace();
return;
} String[] UserNumber = { "86xxxxxxxxxx"};//接收短信的手机号码,前边要加上86 String content = "短信测试来自zzz";
byte[] MessageContent = content.getBytes("GB2312"); try {
// 下发短息
SGIPSubmitMessage sgipsubmit = new SGIPSubmitMessage(
SPNumber, // SP的接入号码
ChargeNumber, // 付费号码 string
UserNumber, // 接收该短消息的手机号,最多100个号码 string[]
CorpId, // 企业代码,取值范围为0~99999 string
ServiceType, // 业务代码,由SP定义 stirng
03, // 计费类型 int
"0", // 该条短消息的收费值 stirng
"0", // 赠送用户的话费 string
0, // 代收费标志0:应收1:实收 int
0, // 引起MT消息的原因 int
06, // 优先级0~9从低 到高,默认为0 int
null, // 短消息寿命的终止时间 date
null, // 短消息定时发送的时间 date
1, // 状态报告标记 int
0, // GSM协议类型 int
0, // GSM协议类型 int
15, // 短消息的编码格式 int
0, // 信息类型 int
MessageContent.length, // 短消息内容长度 int
MessageContent, // 短消息的内容 btye[]
"0" // 保留,扩展用 string
);
// 收到的响应消息转换成rep
int status = ProcessSubmitRep(sgipsmp.send(sgipsubmit));
System.out.println(status);
if (status == 0) {
System.out.println("消息发送成功..........");
} else {
System.out.println("消息发送失败..........");
}
} catch (Exception ex) {
// log.error("发送消息异常:"+ex.getMessage(),ex);
ex.printStackTrace();
} } private static int ProcessSubmitRep(SGIPMessage msg) {
// 收到的响应消息转换成repMsg
SGIPSubmitRepMessage repMsg = (SGIPSubmitRepMessage) msg;
System.out.println(repMsg.getSrcNodeId());
System.out.println("status:::::::" + repMsg.getResult());
if (repMsg != null && repMsg.getResult() == 0) {
System.out.println("发送成功:::");
}
return repMsg.getResult();
}}我用SGIP模拟网关发送短信时,程序报错:
11:33:43.671(SGIPTransaction.java:80) SGIP_BIND: Sequence_Id=1,login_Type=1,login_Name=xxx,login_Password=xxx 11:33:43.671(SGIPTransaction.java:59) SGIP_BIND_REP: Sequence_Id=1,Result=0
reslut:::::::true
连接成功...........
11:33:43.687(SGIPTransaction.java:80) SGIP_Submit: Sequence_Id=2,SPNumber=3010012345,ChargeNumber=000000000000000000000,UserCount=1,UserNumber[0]=86xxxxxxxxxxx,CorpId=99999,ServiceType=3010012345,FeeType=3,FeeValue=0,GivenValue=0,AgentFlag=0,MorelatetoMTFlag=0,Priority=6,ExpireTime=null,ScheduleTime=null,ReportFlag=1,ExpireTime=null,ScheduleTime=null,ReportFlag=1,TP_pid=0,TP_udhi=0,MessageCoding=15,MessageType=0,MessageLength=15,MessageContent=短信测试来自xxx,reserve=0
11:33:43.687(SGIPTransaction.java:59) SGIP_SUBMIT_REP: Sequence_Id=2,Result=0
-1294867297
status:::::::0
发送成功:::
0
消息发送成功..........

解决方案 »

  1.   

    看了一下SGIPTransaction类的源码也没发现有什么问题啊
      

  2.   

    SGIPTransaction这个类的第80行就是个这啊,没有别的,private int src_nodeid;
    59行是这个方法里的
    public boolean isChildOf(PLayer connection)   
    {   
            if(super.parent == null)   
    59行             return false;   
            else   
                return connection == super.parent;   
    }