zoukankan      html  css  js  c++  java
  • 联通SGIP1.2网关对接

    一.联通SGIP网络架构图

    wpsC27A.tmp

    SMG是具有短消息转发功能的短消息网关。全国可以有多个SMG网关,SMG网关之间通过互联网等方式实现网络互联。每一个SMG同时与多个SMSC以及多个SP连接。全网具有唯一有效的GNS,GNS负责全局路由表的维护与更新;为了确保路由表存储的安全性,网络中设置主备用GNS,两个GNS要保持一致性。每一个SMG都和GNS连接。SMG与SP、SMG与GNS以及SMG与SMG之间的通信协议为SGIP协议。SMG与SMSC之间的通信统一采用SMPP3.3协议。

    其中,短信接入商以SP的角色接入:

    @``NIQ$S(P__OA1P7DN4V1S

    二.开发工具包

    https://gitee.com/cww-knight/SMSGate

    三.和联通侧的约定

    1.SMG 的host,port,LoginName,LoginPassword.

    2.SP 的IP,PORT  NodeId(节点编码)

    3.企业编码(corp_id),接入号(sp_number)

    四.代码开发

    SpClient 初始化

    final EndpointManager manager = EndpointManager.INS;
            SgipClientEndpointEntity client = new SgipClientEndpointEntity();
            client.setId("sgip-client");
    
            client.setNodeId(1l);//sp node_id
            client.setHost("smg_server");
            client.setPort(8882);//smg_server port
            client.setLoginName("smg_loginname");
            client.setLoginPassowrd("smg_loginpassword");
            client.setChannelType(EndpointEntity.ChannelType.DUPLEX);
            client.setIdleTimeSec((short)300);
            client.setMaxChannels((short)1);
            client.setRetryWaitTimeSec((short)100);
            client.setUseSSL(false);
            client.setReSendFailMsg(true);
            List<BusinessHandlerInterface> clienthandlers = new ArrayList<BusinessHandlerInterface>();
            client.setBusinessHandlerSet(clienthandlers);
            try{
                manager.addEndpointEntity(client);
                manager.openEndpoint(client);
    
            }catch (Exception e){
    
            }
            manager.startConnectionCheckTask();

    SpClient 发消息

    SgipSubmitRequestMessage msg = new SgipSubmitRequestMessage();
            msg.setSequenceNo(sendMsgDto.getMsgId());
            msg.setSpnumber("#接入号#");
            msg.setUsernumber("#目标手机号(86开头)#");
            msg.setCorpid("#企业编号#");
            msg.setServicetype("1");
            short feeType=0;
            msg.setFeetype(feeType);
            msg.setFeevalue("0");
            msg.setGivenvalue("0");
            msg.setAgentflag(feeType);
            msg.setMsgContent("短信内容");
     ChannelUtil.syncWriteLongMsgToEntity("sgip-client", msg);

    SpServer 初始化

    final EndpointManager manager = EndpointManager.INS;
            SgipServerEndpointEntity server = new SgipServerEndpointEntity();
            server.setId("spserver");
            server.setHost("0.0.0.0");
            server.setPort(9999);//Sp Server port
            server.setValid(true);
            server.setUseSSL(false);
    
            SgipServerChildEndpointEntity child = new SgipServerChildEndpointEntity();
            child.setId("spnode");
            child.setNodeId(1l);//节点编码
            child.setLoginName("");
            child.setLoginPassowrd("");
    
            child.setValid(true);
            child.setChannelType(EndpointEntity.ChannelType.DUPLEX);
            child.setMaxChannels((short)10);
            child.setRetryWaitTimeSec((short)30);
            child.setMaxRetryCnt((short)3);
            child.setReSendFailMsg(false);
            child.setIdleTimeSec((short)300);
            child.setSupportLongmsg(EndpointEntity.SupportLongMessage.SEND);  //接收长短信时不自动合并
            List<BusinessHandlerInterface> serverhandlers = new ArrayList<BusinessHandlerInterface>();
            serverhandlers.add(spSgipReportRequestMessageHandler);
            serverhandlers.add(spSgipMessageReceiveHandler);
    
            child.setBusinessHandlerSet(serverhandlers);
            server.addchild(child);
            try{
                manager.addEndpointEntity(server);
                manager.openEndpoint(server);
            }catch (Exception e){
    
            }

    SpServer 处理Report(短信发送状态)和Deliver(上行短信)消息

    以Report消息为例:spSgipReportRequestMessageHandler

    package com.sms.demo.service.handler;
    
    import com.alibaba.fastjson.JSON;
    import com.sms.demo.datamodel.ReportMsgDto;
    import com.zx.sms.codec.sgip12.msg.SgipReportRequestMessage;
    import com.zx.sms.codec.sgip12.msg.SgipReportResponseMessage;
    import com.zx.sms.handler.sgip.SgipReportRequestMessageHandler;
    import io.netty.channel.ChannelHandler;
    import io.netty.channel.ChannelHandlerContext;
    import lombok.extern.slf4j.Slf4j;
    import org.springframework.stereotype.Component;
    
    import javax.annotation.Resource;
    import java.util.Date;
    
    @ChannelHandler.Sharable
    @Slf4j
    @Component
    public class SpSgipReportRequestMessageHandler extends SgipReportRequestMessageHandler {
        @Resource
        private KafkaTemplate<String,String> kafkaTemplate;
        @Override
        public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
            if(msg instanceof SgipReportRequestMessage){
    //            System.out.println("收到report:"+msg);
                log.info("收到report消息:{}",msg);
                SgipReportRequestMessage reportMsg= (SgipReportRequestMessage) msg;
                if(reportMsg.getReporttype()==0){
                 //TODO 处理submit消息的状态报告
                }
                SgipReportResponseMessage resp = new SgipReportResponseMessage((reportMsg).getHeader());
                resp.setResult((short)0);
                resp.setTimestamp(((SgipReportRequestMessage)msg).getTimestamp());
                ctx.channel().writeAndFlush(resp);
            }else{
                ctx.fireChannelRead(msg);
            }
    
        }
    
        @Override
        public String name() {
            return "SgipReportRequestMessageHandler";
        }
    
       
    }

    如果,您认为阅读这篇博客让您有些收获,不妨点击一下右下角的【推荐】。
    如果,您希望更容易地发现我的新博客,不妨点击一下左下角的【关注我】。
    如果,您对我的博客所讲述的内容有兴趣,请继续关注我的后续博客,我是【Arli】。

    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    python 绘制所有线条、散点等 可用的标记符号(marker)
    Maximal InformMaximal Information Coefficient (MIC)最大互信息系数详解与实现 https://blog.csdn.net/FontThrone/article/details/85227239
    python画图,等间距坐标距离表示不等间距数据值
    机器学习数据库 http://archive.ics.uci.edu/ml/datasets.php https://www.openml.org/d/179
    Matplotlib.pyplot.plot图形符号、风格及颜色简写形式速查表https://blog.csdn.net/Treasure99/article/details/106044114/
    Pycharm 2017.3 永久激活教程https://www.bilibili.com/read/cv11643882/
    学习资源http://imada.huel.edu.cn/resource.html# 数据库/机器学习/安全领域顶会论文
    Python的知识点 plt.plot()函数细节
    原因是标题默认输出英文,如果输出中文,要对字体进行调整。需要在程序定义前输入:
    会讲故事助你成功
  • 原文地址:https://www.cnblogs.com/arli/p/14798474.html
Copyright © 2011-2022 走看看