动力思维乐信

asp调用短信接口实现用户注册

前几天做一个asp语言开发的网站需要实现用户注册短信验证功能,就研究了一下如何实现,简单给大家分享下调用过程。

首先需要找到一个第三方短信接口,当时用的是动力思维乐信的短信接口。

首先需要先注册个动力思维乐信平台账号,这个后面要用到,可以到他们官网注册(http://www.lx598.com/

这里贴出来他们的短信接口接入文档说明(http://www.lx598.com/apitext.html),和asp语言的demo(http://www.lx598.com/aspCode.html

前端用户注册页面(这个比较简单)

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>发送短信</title>
</head>
<body>
<hr />
<form name="form1" action="index4.asp" method="post"  >
  发送短信<br />
 用户名:
  <input name="AccountName" type="text" />
      
  密码:
  <input name="Password" type="password" />
  <br />
  内容:
  <input name="message" type="text" />
      
  目标号码:
  <input name="mobiles" type="text" />
  <input name="submit"type="submit"  value="提交" />
  <input name="reset"type="reset"  value="重置" />
  <input name="cd" type="hidden" value="4" />
  <input name="batchNumber" type="hidden" value="<%=now()%>" />
</form>	
</body>
</html>

 后台代码

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>发送短信</title>

</head>

          
<body>
<!--#include file="md5.asp"-->
<%
Function BytesToBstr(body,code) 
dim objstream
set objstream = Server.CreateObject("adodb.stream") 
objstream.Type = 1 
objstream.Mode =3 
objstream.Open 
objstream.Write body 
objstream.Position = 0 
objstream.Type = 2 
objstream.Charset =code
BytesToBstr = objstream.ReadText 
objstream.Close 
set objstream = nothing 
End Function
%>


<%
'response.ContentType="text/xml;charset=UTF-8"
dim cdkey1,password1,cd
dim HttpReq,str,url
dim cpname,cpadrr,cplinkman,cpphone,cpmobile,cpfax,cpmail,cppost,cpworks,manager
cd=request.Form("cd")
cmd=request.Form("cmd")
cdkey1=request.Form("AccountName")
password1=UCase(md5(request.Form("password")))


cpname=request.Form("cpname")
cpadrr=request.Form("cpadrr")
cplinkman=request.Form("cplinkman")
cpphone=request.Form("cpphone")
cpmobile=request.Form("cpmobile")
cpfax=request.Form("cpfax")
cpmail=request.Form("cpmail")
cppost=request.Form("cppost")
cpworks=request.Form("cpworks")
manager=request.Form("manager")

url="cmd="+cmd+"&AccountName="+cdkey1+"&Password="+password1



if cd="1" then
Set   HttpReq   =  Server.CreateObject("Microsoft.XMLHTTP") 
HttpReq.open "post", "http://116.255.135.146/WebClient", False,"",""
HttpReq.setRequestHeader "Content-Length",len(url)
HttpReq.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
HttpReq.send(url)
'str=HttpReq.responseXML
 if inStr(BytesToBstr(HttpReq.responseBody,"UTF-8"),"<") then
			Set XMLDOC = Server.CreateObject("Microsoft.XMLDOM")
				XMLDOC.async = false
				XMLDOC.loadxml(BytesToBstr(HttpReq.responseBody,"UTF-8"))
				set XMLDOCElement=XMLDOC.documentElement
					dimResultStr1=XMLDOCElement.SelectSingleNode("//reply/ErrorCode").text
				set objnodes=Nothing
			Set XMLDOC = Nothing
	else
			dimResultStr1=dimThisSmsState1
	end if
	if dimResultStr1=0 then
	  response.write "发送成功"	
	else
	  response.write "发送失败"     
	end if
'response.Write str
end if
%>
<br />

<%
Function UrlEncoding(DataStr) 
Dim StrReturn,Si,ThisChr,InnerCode,Hight8,Low8 
StrReturn = "" 
For Si = 1 To Len(DataStr) 
ThisChr = Mid(DataStr,Si,1) 
If Abs(Asc(ThisChr)) < &HFF Then 
StrReturn = StrReturn & ThisChr 
Else 
InnerCode = Asc(ThisChr) 
If InnerCode < 0 Then 
InnerCode = InnerCode + &H10000 
End If 
Hight8 = (InnerCode And &HFF00)\ &HFF 
Low8 = InnerCode And &HFF 
StrReturn = StrReturn & "%" & Hex(Hight8) & "%" & Hex(Low8) 
End If 
Next 
UrlEncoding = StrReturn 
End Function 

%>

<%

if cd="4" then 
mobiles=request.Form("mobiles")
content=request.Form("message")
cmd1=request.Form("cmd")
batch=replace(request.Form("batchNumber"),"-","0")
batchNumber=replace(batch,":","")
batchNumber=replace(batchNumber," ","")
batchNumber=left(batchNumber,15)
url="accName="+cdkey1+"&accPwd="+password1+"&aimcodes="+mobiles+"&content="+content+"【签名】
Set   HttpReq   =  Server.CreateObject("Microsoft.XMLHTTP") 
HttpReq.open "post", "http://www.lx198.com/sdk/send", False,"",""
HttpReq.setRequestHeader "Content-Length",len(url)
HttpReq.setRequestHeader "Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"
url=URLEncoding(url)
HttpReq.send(url)
str=HttpReq.responseText
response.Write str
end if
%>

</body>
</html>

 

posted on 2018-01-04 16:18  动力思维乐信  阅读(3024)  评论(0编辑  收藏  举报

导航