ASP编写的MISC函数集 (转)
ASP编写的MISC函数集
抛砖引玉,可能有些错误,大概流程是这样
MISCFun.asp
<!--#include File="Const.asp"-->
<%
Function GetXmlNodevalue(XmlString,CurrentNode,NodeType)
dim n,xml
set xml = xmlString
if NodeType="1" Then
GetXmlNodevalue=xml.selectSingleNode("misc_command/command_name").text
else
set N = xml.selectsinglenode("misc_command/command_data_block")
if not N is nothing then
GetXmlNodevalue = N.selectsingleNode(CurrentNode).text
end if
end if
End Function
Function PostXmlAndGetResponse(PostToUrl,XmlBody)
set xhttp = createObject("msxml2.XMLHTTP")
xhttp.open "POST", PostToUrl, False
xhttp.send XmlBody
' set PostXmlAndGetResponse= xhttp.responseXML
PostXmlAndGetResponse= xhttp.responseText
set xhttp=nothing
' call writepostdata(PostXmlAndGetResponse)
End Function
' 发送SSO请求
function http_request(commandname,sid,service_id,sp_password,wapgateway)
xmlstr="<?xml version = ""1.0"" ?>"&vbcrlf
xmlstr=xmlstr+"<misc_command version=""1.5"">"&Vbcrlf
xmlstr=xmlstr+"<command_name>"+commandname+"</command_name>"&Vbcrlf
xmlstr=xmlstr+"<command_data_block>"&vbcrlf
xmlstr=xmlstr+"<sid>"+sid+"</sid>"&vbcrlf
xmlstr=xmlstr+"<service_id>"+service_id+"</service_id>"&vbcrlf
xmlstr=xmlstr+"<sp_id>"+sp_id+"</sp_id>"&vbcrlf
xmlstr=xmlstr+"<sp_password>"+sp_password+"</sp_password>"&vbcrlf
xmlstr=xmlstr+"</command_data_block>"&vbcrlf
xmlstr=xmlstr+"</misc_command>"
http_request=PostXmlAndGetResponse(wapgateway,XmlStr)
end function
'处理provision
function provision_return(actionid,serviceid,mid,mobileid,accessmode,gateway)
xmlstr="<?xml version = ""1.0"" ?>"&vbcrlf
xmlstr=xmlstr+"<misc_command version=""1.5"">"&Vbcrlf
xmlstr=xmlstr+"<command_name>provision</command_name>"&Vbcrlf
xmlstr=xmlstr+"<command_data_block>"&vbcrlf
xmlstr=xmlstr+"<action_id>"+actionid+"</action_id>"&vbcrlf
xmlstr=xmlstr+"<service_id>"+serviceid+"</service_id>"&vbcrlf
xmlstr=xmlstr+"<access_mode>"+accessmode+"</access_mode>"&vbcrlf
xmlstr=xmlstr+"<mid>"+mid+"</mid>"&vbcrlf
xmlstr=xmlstr+"<mobile_id>"+mobileid+"</mobile_id>"&vbcrlf
xmlstr=xmlstr+"<sp_id>"+sp_id+"</sp_id>"&vbcrlf
xmlstr=xmlstr+"<sp_password>"+sp_password+"</sp_password>"&vbcrlf
xmlstr=xmlstr+"</command_data_block>"&vbcrlf
xmlstr=xmlstr+"</misc_command>"
provision_return=PostXmlAndGetResponse(gateway,xmlstr)
'provision_return=xmlstr
end function
'服务状态正向管理时返回XML至广东移动网关
'取得移动网关POST过来的数据,并将参数返回出。
Function GetXmlPostData(command_name,action_ID,Service_ID,m_Id,Mobile_ID,Access_Mode)
dim nodes,ReturnData
Set xml = Server.CreateObject("msxml2.DOMdocument.quot;)
xml.async = False
xml.Load Request
command_name=getXmlNodevalue(xml,"command_name",1)
action_ID=getXmlNodevalue(xml,"action_id",2)
service_ID=getXmlNodevalue(xml,"service_id",2)
m_id=getXmlNodevalue(xml,"mid",2)
Mobile_ID=getXmlNodevalue(xml,"mobile_id",2)
access_mode=getXmlNodevalue(xml,"access_mode",2)
End Function
sub Provision_Response(byval result_id,byval result_string)
dim XmlStr,xhttp
Response.ContentType="text/xml"
XmlStr=XmlStr+"<?xml version = ""1.0"" ?>"&vbcrlf
XmlStr=XmlStr+"<misc_command version=""1.3"">"&Vbcrlf
XmlStr=XmlStr+"<command_name>provision_response</command_name>"&Vbcrlf
XmlStr=XmlStr+"<command_data_block>"&vbcrlf
XmlStr=XmlStr+"<result_id>"+result_Id+"</result_id>"&vbcrlf
XmlStr=XmlStr+"<result_string>"+result_string+"</result_string>"&vbcrlf
XmlStr=XmlStr+"</command_data_block>"&vbcrlf
XmlStr=XmlStr+"</misc_command>"
response.write xmlstr
End sub
'服务状态反向管理时向移动网关发送请求
Function sp_Provision( result_id, result_string)
dim XmlStr,xhttp
XmlStr=XmlStr+"<?xml version = ""1.0"" ?>"&vbcrlf
XmlStr=XmlStr+"<misc_command version=""1.3"">"&Vbcrlf
XmlStr=XmlStr+"<command_name>sp_provision</command_name>"&Vbcrlf
XmlStr=XmlStr+"<command_data_block>"&vbcrlf
XmlStr=XmlStr+"<action_Id>"+action_Id+"</action_Id>"&vbcrlf
XmlStr=XmlStr+"<service_id>"+service_id+"</service_id>"&vbcrlf
XmlStr=XmlStr+"<access_mode>"+access_mode+"</access_mode>"&vbcrlf
XmlStr=XmlStr+"<mid>"+m_id+"</mid>"&vbcrlf
XmlStr=XmlStr+"<mobile_id>"+mobile_id+"</mobile_id>"&vbcrlf
XmlStr=XmlStr+"<sp_id>"+sp_id+"</sp_id>"&vbcrlf
XmlStr=XmlStr+"<sp_password>"+sp_password+"</sp_password>"&vbcrlf
XmlStr=XmlStr+"</command_data_block>"&vbcrlf
XmlStr=XmlStr+"</misc_command>"
call writepostdata(xmlstr)
xmlString=PostXmlAndGetResponse(ProviSionWapGateWay,XmlStr)
Result_ID=GetNodevalue(xmlstring,"<result_id>")
result_string=GetNodevalue(xmlstring,"<result_string>")
' set xmlString=PostXmlAndGetResponse(ProviSionWapGateWay,XmlStr)
' Result_ID=GetXmlNodevalue(XmlString,"result_id","2")
' result_string=GetXmlNodevalue(XmlString,"result_string","2")
End Function
Function GetNodevalue(XMLStr,Node)
BeginData=instr(xmlstr,node)+Len(node)+1
EndData=instr(BeginData,xmlstr,"<")
DataLen=EndData-BeginData
if datalen>0 Then
GetNodevalue=mid(xmlstr,Begindata,DataLen)
Else
GetNodevalue="Err:Parameters Lost!"
End IF
End Function
Sub writepostdata(str) '用于调试时观察数据
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("c:\postdata.txt", forwriting,1)
f.Write str
f.Close
End Sub
'-----------------------------------------------------------------
%>
----------------------------------------------------------------------------------
const.asp
<%
const sp_id="888888
Const sp_password="FDkjfDsfdslfas32"
'Const wapgateway="网关地址"
Const ssogateway="网关地址"
Const echogateway="网关地址"
Const provisiongateway="网关地址"
%>