华为云Stack运维侧对接第三方短信网关探索
        【摘要】 华为云Stack运维侧已经支持直接对接多种常见协议的短信网关,比如CMPP2_x,CMPP3_x,SMGP,SGIP,SMPP3_4,SMPP3_3等。但部分客户有专属的短信网关,需要通过特定的接口进行对接,比如可能是restful/webservice/soap等协议,因此可以通过开发适配程序,先以ManageOne支持的协议接收短信内容,然后再调用第三方的接口发送短信。
    
    
    
    ManageOne运维侧已经支持直接对接多种常见协议的短信网关,比如CMPP2_x,CMPP3_x,SMGP,SGIP,SMPP3_4,SMPP3_3等。
但部分客户有专属的短信网关,需要通过特定的接口进行对接,比如可能是restful/webservice/soap等协议,
因此可以通过开发适配程序,先以ManageOne支持的协议接收短信内容,然后再调用第三方的接口发送短信。

详细开发指导可以私信交流,demo选择smpp3_4协议接收告警,打印短信内容,开发者拿到短信内容后再根据项目实际情况调用第三方短信接口。
主要步骤如下:
1、引用smpp组件,封装了具体通信相关的功能
|  
     
      1 
      
    
      2 
      
    
      3 
      
    
      4 
      
    
      5 
      
    
      6 
      |  
    
    添加Maven引用  
    <dependency> 
         
     <groupId>org.jsmpp</groupId> 
         
     <artifactId>jsmpp</artifactId> 
         
     <version> 
     2.3 
     . 
     10 
     </version> 
    </dependency> 
     |  
  
2、启动smpp服务端
|  
     
      1 
      
    
      2 
      
    
      3 
      
    
      4 
      
    
      5 
      
    
      6 
      
    
      7 
      
    
      8 
      
    
      9 
      
    
      10 
      
    
      11 
      
    
      12 
      
    
      13 
      
    
      14 
      
    
      15 
      
    
      16 
      
    
      17 
      
    
      18 
      
    
      19 
      
    
      20 
      |  
    
    SMPPServerSessionListener sessionListener =  
     new  
     SMPPServerSessionListener(port); 
    LOGGER.info( 
     "Start SMPP server... sessionListenerPort -> {}" 
     , port); 
    while  
     ( 
     true 
     ) { 
         
     SMPPServerSession serverSession = sessionListener.accept(); 
         
     LOGGER.info( 
     "Accepting connection for session:{}" 
     , serverSession.getSessionId()); 
         
     serverSession.setMessageReceiverListener( 
     this 
     ); 
         
     Future<Boolean> bindResult = execService.submit( 
     new  
     WaitBindTask(serverSession, systemId, password)); 
         
     try  
     { 
             
     boolean  
     bound = bindResult.get( 
     60000 
     , TimeUnit.MILLISECONDS); 
             
     if  
     (bound) { 
                 
     LOGGER.info( 
     "The session is now in state:{}" 
     , serverSession.getSessionState()); 
             
     } 
         
     }  
     catch  
     (InterruptedException e) { 
             
     LOGGER.error( 
     "Interrupted WaitBind task:{}" 
     , e.getMessage()); 
         
     }  
     catch  
     (ExecutionException e) { 
             
     LOGGER.error( 
     "Exception on execute WaitBind task:{}" 
     , e.getMessage()); 
         
     }  
     catch  
     (TimeoutException e) { 
             
     LOGGER.error( 
     "Timeout on bind result:{}" 
     , e.getMessage()); 
         
     } 
    } 
     |  
  
3、重写消息接收事件,获取短信内容
|  
     
      1 
      
    
      2 
      
    
      3 
      
    
      4 
      
    
      5 
      
    
      6 
      
    
      7 
      
    
      8 
      
    
      9 
      
    
      10 
      |  
    
    public  
     MessageId onAcceptSubmitSm(SubmitSm submitSm, SMPPServerSession smppServerSession) 
         
     throws  
     ProcessRequestException { 
         
     MessageId messageId = messageIDGenerator.newMessageId(); 
         
     String sourceAddr = submitSm.getSourceAddr(); 
         
     String destAddress = submitSm.getDestAddress(); 
         
     String shortMessage =  
     new  
     String(submitSm.getShortMessage(), StandardCharsets.UTF_16); 
         
     LOGGER.info( 
     "Receiving submit_sm, sourceAddr:{},destAddress:{},shortMessage:'{}', and return message id:{}" 
     , 
             
     sourceAddr,destAddress,shortMessage,messageId.getValue()); 
         
     return  
     messageId; 
    } 
     |  
  
4、页面配置对接协议,验证消息发送内容

到这里就成功了。
            【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
                cloudbbs@huaweicloud.com
                
            
        
        
        
        
        
        
        - 点赞
 - 收藏
 - 关注作者
 
            
           
评论(0)