首页 新闻 会员 周边

基于SGIP协议编写短信网关接口

0
悬赏园豆:200 [待解决问题]

基本上抄了这个帖子的代码http://www.oschina.net/bbs/thread/13041

package mj;  
  
import java.io.*;  
import com.huawei.smproxy.*;  
import com.huawei.insa2.util.Args;  
import com.huawei.insa2.comm.sgip.message.*;  
import java.math.BigInteger;  
  
public class Send {  
  
  private static String SPNumber = "xxxxxxxxx";//接入号码  
  private static String ChargeNumber = "000000000000000000000"; // 计费号码,白名单  
  private static String ServiceType = "";//服务类型  
  private static String host = "xxx.xx.xx.xxx"; // 主机名,网关IP  
  private static int port = 8881; // 端口号  
  private static String CorpId = "xxxxx"; // 企业代码  
  private static String login_Name = "xxxxxx"; // 登陆名  
  private static String login_PassWord = "xxxxxx"; // 登陆密码  
   
  public static void main(String[] args) throws UnsupportedEncodingException {  
  int srcnode = new BigInteger("30200xxxxx").intValue(); //源节点编号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");  
   
  // 连接登陆  
  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 = { "8618688899xxx"};//接收短信的手机号码,前边要加上86  
   
  String content = "短信测试内容";  
  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();  
  }  
   
}  
使用了华为的开发包,搜"smproxy.jar"即可,填上接入号等信息后编译运行,出现以下调试及异常信息

15:11:48.890(SGIPTransaction.java:80) SGIP_BIND: Sequence_Id=1,login_Type=1,logi
n_Name=xxxxxx,login_Password=xxxxxx
java.net.SocketException: Connection reset
  at java.net.SocketInputStream.read(SocketInputStream.java:168)
  at java.net.SocketInputStream.read(SocketInputStream.java:182)
  at java.io.DataInputStream.readInt(DataInputStream.java:351)
  at com.huawei.insa2.comm.sgip.SGIPReader.read(SGIPReader.java:37)
  at com.huawei.insa2.comm.sgip.SGIPConnection.connect(SGIPConnection.java
:249)
  at com.huawei.insa2.comm.sgip.SGIPSocketConnection$1$ReceiveThread.task(
SGIPSocketConnection.java:199)
  at com.huawei.insa2.util.WatchThread.run(WatchThread.java:48)
15:11:48.890(SGIPTransaction.java:80) SGIP_UNBIND: Sequence_Id=2
java.net.SocketException: Connection reset
  at java.net.SocketInputStream.read(SocketInputStream.java:168)
  at java.net.SocketInputStream.read(SocketInputStream.java:182)
  at java.io.DataInputStream.readInt(DataInputStream.java:351)
  at com.huawei.insa2.comm.sgip.SGIPReader.read(SGIPReader.java:37)
  at com.huawei.insa2.comm.sgip.SGIPConnection.connect(SGIPConnection.java
:249)
  at com.huawei.insa2.comm.sgip.SGIPSocketConnection$1$ReceiveThread.task(
SGIPSocketConnection.java:199)
  at com.huawei.insa2.util.WatchThread.run(WatchThread.java:48)
网络异常...........
java.lang.IllegalStateException: 登录不成功
  at com.huawei.smproxy.SGIPSMProxy.connect(SGIPSMProxy.java:68)
  at mj.Send.main(Send.java:36)

请问谁有相关开发经验,帮我看看怎么解决?

cloud00001的主页 cloud00001 | 初学一级 | 园豆:0
提问于:2011-01-17 10:30
< >
分享
所有回答(1)
0

java的问题,建议你去javaeye问问看.

I,Robot | 园豆:9783 (大侠五级) | 2011-01-17 20:42
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册