点击这里给我发消息
17122013
基于SGIP协议编写短信网关接口

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

短信接口 |

我是在华为的短信开发包的基础上开发的,由于不知道该包是否涉及版权问题,所以本人暂不提供了,可以到网上自行解决;

下载后就是一个jar包

短信发送的代码如下:
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 Mt {

    private static String SPNumber = "1065579112";//接入号码
    private static String ChargeNumber = "000000000000000000000"; // 计费号码,我们是白名单
    private static String ServiceType = "JXHD";//服务类型
    private static String host = "192.168.88.156"; // 主机名,网关IP
    private static int port = 8801; // 端口号,这里特别注意下,接入协议中写的是8804,害得我调了很久,后来才知道改了,所以,这个在接入前,建议与网关人员确定
    private static String CorpId = "52322"; // 企业代码
    private static String login_Name = "fslt"; // 登陆名
    private static String login_PassWord = "fslt"; // 登陆密码

    public static void main(String[] args) throws UnsupportedEncodingException {
        int srcnode =new BigInteger("82322").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", "false");
       
        // 连接登陆
        SGIPSMProxy sgipsmp = new SGIPSMProxy(argstr); // 这里
        try {
            //connect表示向SMG登陆,登录名与密码分别是SMG向SP分配的用户名与密码,调用这个接口方法,向SMG发送Bind命令消息。
            //如果发送消息超时或通信异常则抛出异常,需要调用者捕获处理。
            boolean reslut = sgipsmp.connect(login_Name, login_PassWord); // 登陆得到true和false

            if (reslut) {
                System.out.println("连接成功...........");
            } else {
                System.out.println("连接失败(用户名或密码错误)...........");
                return;
            }
        } catch (Exception ex) {
      &nb