SP 短信开发-PROVISION接口实现-正向订购实例代码

实例代码:MYprovision.jsp ,用JSP方式实现。

<?xml version="1.0" encoding="UTF-8"?>
<%@ page contentType="text/xml; charset=UTF-8" %>
<%@ page import="com.AAAA.appn.*" %>
<%@ page import="java.io.*" %>
<%@ page import="org.jdom.xpath.*" %>//当然分析XML数据大把库可以用。
<%@ page import="org.jdom.*" %>
<%@ page import="java.util.*" %>
<%
//用户通过手机发送定制或取消指令到相应的SP特服号,网关收到MO消息后向MISC发起MO鉴权批价请求,
//MISC收到MO鉴权批价请求后进行订购、取消点播指令匹配;
//如果判断指令是定制或取消指令,则MISC会向SP发送订购关系同步请求包SyncOrderRelationReq

    boolean resultStr = true;
    String XMLData = null;
    StringBuffer tempStringBuffer = new StringBuffer();
    String tempString = null;
    BufferedReader reader = request.getReader();//接受MISC的订购关系同步请求包SyncOrderRelationReq
   
    while ((tempString = reader.readLine()) != null){
        tempStringBuffer.append(tempString);//读取订购关系同步请求包SyncOrderRelationReq内容
    }
    XMLData = tempStringBuffer.toString();//转换订购关系同步请求包SyncOrderRelationReq内容为STRING,存储到XMLDATA里


   if(XMLData == null && XMLData.length()<10){
   resultStr = false;
   }
    tempStringBuffer.setLength(0);//清空tempStringBuffer
    tempString = null;

    //out.println("xml:="+(XMLData.equals("")));

org.jdom.input.SAXBuilder sb=new org.jdom.input.SAXBuilder();
org.jdom.Document doc=null;
//xmldata为非空字符
if(XMLData.equals("")){
 //doc=sb.build("/home/web/provision.xml");
 return ;
}else{
//调用下面的函数,写入PROVISION.XML和PROVISION.LOG文件了。
 write("/home/web/provision.xml",XMLData);//本地的provision.xml为一个临时文件;
 append("/home/web/provision.log",XMLData);//provision.log为一个同步信息的纪录文件;
 doc=sb.build("/home/web/provision.xml");//读取PROVISION.XML文件,SB和DOC的使用方法不是很明白;
 
}
//以下是读取PROVISION.XML的信息,解释XML文件的各部分定义,和读取数值到变量里。
org.jdom.Element root=doc.getRootElement();
Element SyncOrderRelationReq=null;
Element Send_Address=null;
Element Dest_Address=null;
Element FeeUser_ID=null;
Element DestUser_ID=null;

String TransactionID=null;
String MsgType=null;
String hRet=null;
String Version=null;
//--------------------
String LinkID=null;
String ActionID=null;
String ActionReasonID=null;
String SPID=null;
String SPServiceID=null;
String AccessMode=null;
String FeatureStr=null;
//----------------------
String Send_Address_DeviceType=null;
String Send_Address_DeviceID=null;
String Dest_Address_DeviceType=null;
String Dest_Address_DeviceID=null;
String FeeUser_ID_UserIDType=null;
String FeeUser_ID_MSISDN=null;
String FeeUser_ID_PseudoCode=null;
String DestUser_ID_UserIDType=null;
String DestUser_ID_MSISDN=null;
String DestUser_ID_PseudoCode=null;
//读取header信息;
Element header=(Element)XPath.selectSingleNode(root,"/SOAP-ENV:Envelope/SOAP-ENV:Header");
List ns=header.getChildren();
for(Iterator i=ns.iterator();i.hasNext();){
  Object n=i.next();
  if(n instanceof Element){
    Element e=(Element)n;
    if(e.getName().equals("TransactionID")){
      TransactionID=e.getTextNormalize();
    }
  }
}
//读取body信息;
Element body=(Element)XPath.selectSingleNode(root,"/SOAP-ENV:Envelope/SOAP-ENV:Body");
ns=body.getChildren();
for(Iterator i=ns.iterator();i.hasNext();){
  Object n=i.next();
  if(n instanceof Element){
    Element e=(Element)n;
    if(e.getName().equals("SyncOrderRelationReq")){
      SyncOrderRelationReq=e;
    }
  }
}

//取得数据包的所有孩子。
if(SyncOrderRelationReq!=null){
  ns=SyncOrderRelationReq.getChildren();
  for(Iterator i=ns.iterator();i.hasNext();){
    Object n=i.next();
    if(n instanceof Element){
      Element e=(Element)n;
      //------------------------------------
      if(e.getName().equals("Send_Address")){
        Send_Address=e;
      }
      if(e.getName().equals("Dest_Address")){
        Dest_Address=e;
      }
      if(e.getName().equals("FeeUser_ID")){
        FeeUser_ID=e;
      }
      if(e.getName().equals("DestUser_ID")){
        DestUser_ID=e;
      }
      //------------------------------------
      if(e.getName().equals("Version")){
        Version=e.getTextNormalize();
      }
      if(e.getName().equals("MsgType")){
        MsgType=e.getTextNormalize();
      }
      if(e.getName().equals("LinkID")){
        LinkID=e.getTextNormalize();
      }
      if(e.getName().equals("ActionID")){
        ActionID=e.getTextNormalize();
      }
      if(e.getName().equals("ActionReasonID")){
        ActionReasonID=e.getTextNormalize();
      }
      if(e.getName().equals("SPID")){
        SPID=e.getTextNormalize();
      }
      if(e.getName().equals("SPServiceID")){
        SPServiceID=e.getTextNormalize();
      }
      if(e.getName().equals("AccessMode")){
        AccessMode=e.getTextNormalize();
      }
      if(e.getName().equals("FeatureStr")){
        FeatureStr=e.getTextNormalize();
      }
    }
  }
}

//分析数据包的

if(Send_Address!=null){
  ns=Send_Address.getChildren();
  for(Iterator i=ns.iterator();i.hasNext();){
    Object n=i.next();
    if(n instanceof Element){
      Element e=(Element)n;
      if(e.getName().equals("DeviceType")){
        Send_Address_DeviceType=e.getTextNormalize();
      }
      if(e.getName().equals("DeviceID")){
        Send_Address_DeviceID=e.getTextNormalize();
      }
    }
  }
}
if(Dest_Address!=null){
  ns=Dest_Address.getChildren();
  for(Iterator i=ns.iterator();i.hasNext();){
    Object n=i.next();
    if(n instanceof Element){
      Element e=(Element)n;
      if(e.getName().equals("DeviceType")){
        Dest_Address_DeviceType=e.getTextNormalize();
      }
      if(e.getName().equals("DeviceID")){
        Dest_Address_DeviceID=e.getTextNormalize();
      }
    }
  }
}
if(FeeUser_ID!=null){
  ns=FeeUser_ID.getChildren();
  for(Iterator i=ns.iterator();i.hasNext();){
    Object n=i.next();
    if(n instanceof Element){
      Element e=(Element)n;
      if(e.getName().equals("UserIDType")){
        FeeUser_ID_UserIDType=e.getTextNormalize();
      }
      if(e.getName().equals("MSISDN")){
        FeeUser_ID_MSISDN=e.getTextNormalize();
      }
      if(e.getName().equals("PseudoCode")){
        FeeUser_ID_PseudoCode=e.getTextNormalize();
      }
    }
  }
}
if(DestUser_ID!=null){
  ns=DestUser_ID.getChildren();
  for(Iterator i=ns.iterator();i.hasNext();){
    Object n=i.next();
    if(n instanceof Element){
      Element e=(Element)n;
      if(e.getName().equals("UserIDType")){
        DestUser_ID_UserIDType=e.getTextNormalize();
      }
      if(e.getName().equals("MSISDN")){
        DestUser_ID_MSISDN=e.getTextNormalize();
      }
      if(e.getName().equals("PseudoCode")){
        DestUser_ID_PseudoCode=e.getTextNormalize();
      }
    }
  }
}
//以上的内容是由移动定义好的SOAP XML字段,主要解释和读取数据到变量

//以下是业务逻辑部分,现在写到JSP里面了,可以用直接传递给业务层用SERVLET等方式做业务处理。


//如果要增加同步的业务信息,只需要修改以下部分代码;
if(TransactionID!=null&&ActionID!=null&&DestUser_ID_MSISDN!=null&&SPServiceID!=null){
  sun.misc.BASE64Decoder b=new sun.misc.BASE64Decoder();
        byte[] bb=b.decodeBuffer(FeatureStr); //服务订购参数(base64加密),内容是长号码+空格+用户发送内容,并用DECODEBASE64Decoder()整成BYTE[]

        String content=new String(bb,"gb2312");//转换为STRING;
 String sql_="insert into provision(content,actionid,provisiontime,MSISDN,PServiceID)  values('"+content+"',"+ActionID+",now(),'"+DestUser_ID_MSISDN+"','"+SPServiceID+"')";
DBUtil.exe(sql_);//把provision的订购信息写入到数据表里;数据库写操作函数
 content=content.trim().toUpperCase();
 ActionID=ActionID.trim().toUpperCase();
 SPServiceID=SPServiceID.trim().toUpperCase();
 
 int userid = BizLogicUtil.getUserID(DestUser_ID_MSISDN);
 //分析用户的同步订购信息内容,并更新相应的SP注册数据库表;
 if (content.startsWith("AA")) {
    BizLogicUtil.registerUser(userid, 3, 1, null);
                NVSHService.register(userid);  //注册男女字典用户;
 }else if (content.startsWith("A")) {
    BizLogicUtil.registerUser(userid, 2, 1, null);
//以下三个if的代码意义在于,不管用户发送的定制信息是否"AA"和“A”,只要同步订购信息的SPServiceID的业务代码,就进行操作,
//ActionID,服务状态管理动作代码,具体值如下:
//1: 开通服务;
//2: 停止服务;
//3: 激活服务;
//4: 暂停服务;
    
 }else if (SPServiceID.startsWith("-TEST1")&&ActionID.startsWith("1")) {
    BizLogicUtil.registerUser(userid, 1, 1, null);//注册用户函数
 }else if (SPServiceID.startsWith("-TEST2")&&ActionID.startsWith("2")) {//停止服务;
                BizLogicUtil.registerUser(userid, 1, 2, null);//注销用户函数。
            } else if (SPServiceID.startsWith("-QTYX")&&ActionID.startsWith("2")) {//停止服务;
                BizLogicUtil.registerUser(userid, 2, 2, null);
                BizLogicUtil.registerUser(userid, 3, 2, null);
            }
 //写入群发信息表,对订购用户信息发送订购成功相应的欢迎SMS或菜单;
 sql_="insert into pushsms(content,MSISDN,PServiceID,FeeType,FeeCode,Sended,ActionID,revtime)  values('"+content+"','"+DestUser_ID_MSISDN+"','"+SPServiceID+"','01','00',0,"+ActionID+",now())";
 DBUtil.exe(sql_);

}

/*
String TransactionID=null;
String MsgType=null;
String hRet=null;
String Version=null;
//--------------------
String LinkID=null;
String ActionID=null;
String ActionReasonID=null;
String SPID=null;
String SPServiceID=null;
String AccessMode=null;
String FeatureStr=null;
//----------------------
String Send_Address_DeviceType=null;
String Send_Address_DeviceID=null;
String Dest_Address_DeviceType=null;
String Dest_Address_DeviceID=null;
String FeeUser_ID_UserIDType=null;
String FeeUser_ID_MSISDN=null;
String FeeUser_ID_PseudoCode=null;
String DestUser_ID_UserIDType=null;
String DestUser_ID_MSISDN=null;
String DestUser_ID_PseudoCode=null;
*/
  hRet="0" ;
%>
<%!
//覆盖写入content到文件file;
//
//
  public static void write ( String file , String content )
    {
        FileWriter writer = null ;
        try
        {
            if ( file != null && content != null )
            {
                writer = new FileWriter ( file ) ;
                writer.write ( new String ( content.getBytes ( "GBK" ) ) ) ;
            }
        }
        catch ( IOException ex )
        {
        }
        finally
        {
            if ( writer != null )
            {
                try
                {
                    writer.close () ;
                }
                catch ( IOException ex1 )
                {
                }
            }
        }
    }

//添加COMTENT到文件file

 public static void append(String file, String content) {
        FileOutputStream fo = null;
        BufferedWriter fout = null;
        String contents = "";
        try {

            fo = new FileOutputStream(file, true);
            fout = new BufferedWriter(new OutputStreamWriter(fo));
            contents = content + "/n";
            fout.write(contents, 0, contents.length());
            fout.close();
            fo.close();
        } catch (Exception e) {

        } finally {
            try {
                fout.close();
                fo.close();
            } catch (Exception e1) {
            }
        }

    }

%>
//该部分代码基本上满足要求,可以不作改动;
//SP收到同步请求包后,对订购请求做相应的订购关系处理,并返回订购关系同步应答SyncOrderRelationResp
//MISC收到应答包后,根据返回结果是否正确,在系统中生成正式的订购关系或者取消订购关系,并由1862系统给用户下发订购成功或取消成功的提醒消息
//SyncOrderRelationResp消息字段描述:
//字段名 重要性 类型 说明
//MsgType 必须 string 消息类型
//TransactionID 必须 string 该消息编号
//Version 必须 string  该接口消息的版本号,本次所有的接口消息的版本都为“1.5.0”
//hRet 必须 integer 返回值,主要错误如下:
//0:成功
//4007: MISC 同步开通服务,但SP 端已存在订购关系,且状态为开通
//4008: MISC 同步开通服务,且SP 端不存在订购关系,但开通服务失败
//4010: MISC 同步停止服务, 且SP 端存在订购关系, 但取消服务失败
//4011: MISC 同步停止服务, 但SP 端不存在订购关系
//4012: MISC 同步暂停服务, 且SP 端存在订购关系, 但暂停服务失败
//4013: MISC 同步暂停服务, 但SP 端不存在订购关系
//4015: MISC 同步激活服务, 但SP 端已存在订购关系, 且状态为开通
//4016: MISC 同步激活服务, 但SP 端不存在订购关系
//其它错误请参见《MISC系统短信SP接入指南-接口改造分册》。

<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:dsmp="http://www.monternet.com/dsmp/schemas/">
<SOAP-ENV:Header>
<dsmp:TransactionID xmlns:dsmp="http://www.monternet.com/dsmp/schemas/">
<%=TransactionID %>
</dsmp:TransactionID>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<dsmp:SyncOrderRelationResp xmlns:dsmp="http://www.monternet.com/dsmp/schemas/">
<MsgType>SyncOrderRelationResp</MsgType>
<Version><%=Version %></Version>
<hRet><%=hRet %></hRet>
</dsmp:SyncOrderRelationResp>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值