公  告
 
  站点日历
 
  日志分类
 
  最新日志
 
  最新评论
 
  最新留言
 
  用户登陆
 
  日志搜索
 
  统计信息
 

  友情连接
 
  移动梦网 MISC1.6 的定购接口程序
[ 2006-6-30 18:27:37 | By: myfamily ]
 
 

移动公司使用卓望公司提供的MISC1.6平台,来管理SP的短信定制和退定。不象以前SP程序,通过短信可以直接指定业务,而是所有的定制数据都通过MISC系统的HTTP SOAP接口发送同步数据(XML格式)给SP,SP处理完毕同步信息后,应答一个XML格式的信息给MISC系统,完成整个定制过程。

定制业务的同步信息格式:

SyncOrderRelationReq包:

<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header>
    <TransactionID xmlns="http://www.monternet.com/dsmp/schemas/">00240301659556</TransactionID>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<SyncOrderRelationReq xmlns="http://www.monternet.com/dsmp/schemas/">
 <Version>1.5.0</Version>
 <MsgType>SyncOrderRelationReq</MsgType>
 <Send_Address>
  <DeviceType>0</DeviceType>
  <DeviceID>0024</DeviceID>
 </Send_Address>
 <Dest_Address>
  <DeviceType>400</DeviceType>
  <DeviceID>0</DeviceID>
 </Dest_Address>
 <FeeUser_ID>
  <UserIDType>1</UserIDType>
  <MSISDN>13805002425</MSISDN>
  <PseudoCode></PseudoCode>
 </FeeUser_ID>
 <DestUser_ID>
  <UserIDType>1</UserIDType>
  <MSISDN>13805002425</MSISDN>
  <PseudoCode></PseudoCode>
 </DestUser_ID>
 <LinkID>SP</LinkID>
 <ActionID>1</ActionID>
 <ActionReasonID>1</ActionReasonID>
 <SPID>911005</SPID>
 <SPServiceID>-0000000122</SPServiceID>
 <AccessMode>2</AccessMode>
 <FeatureStr>YWJjZGVm</FeatureStr>
</SyncOrderRelationReq>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

如果成功,SP应该反馈以下格式的信息:

<?xml version="1.0" encoding="UTF-8"?>
<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/">
00240301801050
</dsmp:TransactionID>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<dsmp:SyncOrderRelationResp xmlns:dsmp="http://www.monternet.com/dsmp/schemas/">
<MsgType>SyncOrderRelationResp</MsgType>
<Version>1.5.0</Version>
<hRet>0</hRet>
</dsmp:SyncOrderRelationResp>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

如果失败了,就应该反馈以下格式的信息:

<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:xsd= "http://www.w3.org/2001/XMLSchema"
   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
   xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
   <SOAP-ENV:Header>
     <TransactionID xmlns="http://www.monternet.com/dsmp/schemas/">
      00240301659556
     </TransactionID>
   </SOAP-ENV:Header>
   <SOAP-ENV:Body>
   <SyncOrderRelationResp xmlns='yourdomain.com'>
     <Version>1.5.0</Version>
     <MsgType>SyncOrderRelationResp</MsgType>
     <hRet>0</hRet>   
   </SyncOrderRelationResp>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

看到没有,成功和失败的信息的去表就在于SyncOrderRelationResp 节点包含的信息不一样。

 

 

下面是具体的处理程序:

<%@ Language=VBScript %>
<%    
  Response.Buffer = True 
  Response.ExpiresAbsolute = Now() - 1 
  Response.Expires = 0 
  Response.CacheControl = "no-cache"


dim objdom,TransactionID,ACTIONID,SPServiceID,mobilenum,FeatureStr
set objdom = server.CreateObject("microsoft.xmldom")
objdom.async = false
objdom.load request '获取发送过来的同步信息XML数据,
'objdom.load("c:\SyncOrderRelationReq.xml") '取得xml文件中的数据
if   objdom.parseerror.errorcode<> 0 then   '如何不是正确的XML格式,就返回失败的XML信息(见上面的格式说明)
    outErr()
else  '如果是正确的XML格式,我们需要把一个个的节点信息取出来(见上面的格式说明)。

 set objtofind=objdom.documentElement.SelectSingleNode("//SOAP-ENV:Header/TransactionID")
 TransactionID=trim(objtofind.text) '事务ID
 set objnodes=objdom.documentElement.SelectSingleNode("//SOAP-ENV:Body/SyncOrderRelationReq").ChildNodes  '取出字节点集合
 ACTIONID=trim(objnodes(7).text)  '1: 开通服务;2: 停止服务;3: 激活服务;4: 暂停服务;
 SPServiceID=trim(objnodes(10).text)  '业务代码
 SPServiceID=replace(SPServiceID,"-","")  '去掉“-”号。 
 mobilenum=mid(replace(objnodes(5).text," ",""),2,11)   '手机号码
 FeatureStr=Base64Decode(trim(objnodes(12).text))  '附加的参数值   该参数是base64加密的,要解密。
 
 'Response.Write mobilenum
 'domlength=objnodes.length
 '总共13项,依次为:
 '版本号码
 '消息类型
 '发送地址设备类型、发送地址设备ID
 '目的地址设备类型、目的地址设备ID
 '收费用户类型、收费用户号码
 '目的用户类型、目的用户号码
 'LINKID
 'ACTIONID
 'ActionReasonID
 'SPID
 'SPServiceID
 'AccessMode
 'FeatureStr
 'for i = 0 to domlength-1
  'response.write element.Text   '字节点名
  'response.write objnodes(i).text&"<BR>"
 'next
 
 '根据获得的参数SPServiceID,ACTIONID处理包月定购**********************************************
 '**********************************************************************  

    '**********加入你自己的处理代码

    '处理....
    if Err.number<>0 then
        outErr()
        Err.Clear()
    else
        outSuc()
    end if
end if 
 

sub outErr()
 Response.Write "<?xml version='1.0' encoding='utf-8'?>"&chr(13)
 Response.Write "<SOAP-ENV:Envelope "&chr(13)
 Response.Write "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"&chr(13)
 Response.Write " xmlns:xsd= 'http://www.w3.org/2001/XMLSchema'"&chr(13)
 Response.Write " xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'"&chr(13)
 Response.Write " xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/'>"&chr(13)
 Response.Write "<SOAP-ENV:Header>"&chr(13)
 Response.Write "<TransactionID xmlns='http://www.monternet.com/dsmp/schemas/'>"&chr(13)
 Response.Write TransactionID&chr(13)
 Response.Write "</TransactionID>"&chr(13)
 Response.Write "</SOAP-ENV:Header>"&chr(13)
 Response.Write "<SOAP-ENV:Body>"&chr(13)
 Response.Write "<SyncOrderRelationResp xmlns='www.zjcm.com'>"&chr(13)
 Response.Write "<Version>1.5.0</Version>"&chr(13)
 Response.Write "<MsgType>SyncOrderRelationResp</MsgType>"&chr(13)
 Response.Write "<hRet>0</hRet>"&chr(13)
 Response.Write "</SyncOrderRelationResp>"&chr(13)
 Response.Write "</SOAP-ENV:Body>"&chr(13)
 Response.Write "</SOAP-ENV:Envelope>"
end sub


sub outSuc()
 Response.Write "<?xml version='1.0' encoding='UTF-8'?>"&chr(13)
 Response.Write "<SOAP-ENV:Envelope "&chr(13)
 Response.Write "xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' "&chr(13)
 Response.Write "xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/' "&chr(13)
 Response.Write "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "&chr(13)
 Response.Write "xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:dsmp='http://www.monternet.com/dsmp/schemas/'>"&chr(13)
 Response.Write "<SOAP-ENV:Header>"&chr(13)
 Response.Write "<dsmp:TransactionID xmlns:dsmp='http://www.monternet.com/dsmp/schemas/'>"&chr(13)
 Response.Write TransactionID&chr(13)
 Response.Write "</dsmp:TransactionID>"&chr(13)
 Response.Write "</SOAP-ENV:Header>"&chr(13)
 Response.Write "<SOAP-ENV:Body>"&chr(13)
 Response.Write "<dsmp:SyncOrderRelationResp xmlns:dsmp='http://www.monternet.com/dsmp/schemas/'>"&chr(13)
 Response.Write "<MsgType>SyncOrderRelationResp</MsgType>"&chr(13)
 Response.Write "<Version>1.5.0</Version>"&chr(13)
 Response.Write "<hRet>0</hRet>"&chr(13)
 Response.Write "</dsmp:SyncOrderRelationResp>"&chr(13)
 Response.Write "</SOAP-ENV:Body>"&chr(13)
 Response.Write "</SOAP-ENV:Envelope>"
end sub


Function Base64Decode(ByVal base64String)
  'rfc1521
  '1999 Antonin Foller, PSTRUH Software, http://pstruh.cz
  Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
  Dim dataLength, sOut, groupBegin
 
  'remove white spaces, If any
  base64String = Replace(base64String, vbCrLf, "")
  base64String = Replace(base64String, vbTab, "")
  base64String = Replace(base64String, " ", "")
 
  'The source must consists from groups with Len of 4 chars
  dataLength = Len(base64String)
  If dataLength Mod 4 <> 0 Then
    Err.Raise 1, "Base64Decode", "Bad Base64 string."
    Exit Function
  End If

 
  ' Now decode each group:
  For groupBegin = 1 To dataLength Step 4
    Dim numDataBytes, CharCounter, thisChar, thisData, nGroup, pOut
    ' Each data group encodes up To 3 actual bytes.
    numDataBytes = 3
    nGroup = 0

    For CharCounter = 0 To 3
      ' Convert each character into 6 bits of data, And add it To
      ' an integer For temporary storage.  If a character is a '=', there
      ' is one fewer data byte.  (There can only be a maximum of 2 '=' In
      ' the whole string.)

      thisChar = Mid(base64String, groupBegin + CharCounter, 1)

      If thisChar = "=" Then
        numDataBytes = numDataBytes - 1
        thisData = 0
      Else
        thisData = InStr(1, Base64, thisChar, vbBinaryCompare) - 1
      End If
      If thisData = -1 Then
        Err.Raise 2, "Base64Decode", "Bad character In Base64 string."
        Exit Function
      End If

      nGroup = 64 * nGroup + thisData
    Next
   
    'Hex splits the long To 6 groups with 4 bits
    nGroup = Hex(nGroup)
   
    'Add leading zeros
    nGroup = String(6 - Len(nGroup), "0") & nGroup
   
    'Convert the 3 byte hex integer (6 chars) To 3 characters
    pOut = Chr(CByte("&H" & Mid(nGroup, 1, 2))) + _
      Chr(CByte("&H" & Mid(nGroup, 3, 2))) + _
      Chr(CByte("&H" & Mid(nGroup, 5, 2)))
   
    'add numDataBytes characters To out string
    sOut = sOut & Left(pOut, numDataBytes)
  Next

  Base64Decode = sOut
End Function


%>

 把我的源代码存为一个asp文件,放到一个站点下面,然后在移动MISC管理平台中指定处理地址为放的这个站点地址。

记得用域名,不要用IP,如果你IP地址变化的话,定制就会失败,除非你变更业务,那就很麻烦了。

卓望提供了一个测试工具:UploadFiles/2006-6/630389678.rar。可以下载使用。要能够顺利的使用以上代码,需要具备一定的XML基础知识。

 

发表评论:

    昵称:
    密码: (游客无须输入密码)
    主页:
    标题:
 
 
 
Powered by Oblog.