asp发送短信验证码 pst方式

 

<script language="jscript" runat="server"> 
Array.prototype.get = function(x) { return this[x]; }; 
function parseJSON(strJSON) { return eval("(" + strJSON + ")"); } 
</script>
<%if userid<>"" then
  response.write("<script>alert('已登录!');window.location.href='center.asp';</script>")
  response.end()
  end if
  if request.QueryString("action")="getsms" then
    '发送短信
 dim tel,data,smscon
 tel=request.QueryString("tel")
 if tel="" then
    response.Write("{status:0,code:0}")
    response.End()
 end if
 Dim zNum,shijian,smsurl,accountSid,smsContent,TOKEN,sig,timestamp
 smsurl="https://api.miaodiyun.com/20150822/industrySMS/sendSMS"
 accountSid="accountSid"
 TOKEN="TOKEN"
 shijian=now()
 timestamp=day_date()
 sig=lcase(md5(accountSid&TOKEN&timestamp,32))
 Randomize Timer
 zNum=Int(899999*Rnd+100000)
 
 session("smscode")=zNum
 session("time")=shijian
 smsContent="【签名】您的验证码为"&zNum&",请于20分钟内正确输入,如非本人操作,请忽略此短信。"
 
 data="accountSid="&accountSid&"&smsContent="&smsContent&"&to="&tel&"&timestamp="&timestamp&"&sig="&sig&"&respDataType=JSON"
 dim restr
    'response.Write("<br>"&timestamp)
 'response.Write(data)
 restr=getHTTPPage(smsurl,data)
 'response.Write(restr)
 Set obj = parseJSON(restr)
 if obj.respCode="00000" then
   response.Write("{status:1,code:0}")
 else
   response.Write("{status:0,code:"&obj.respCode&"}")
 end if
    response.End()
  end if
 
Function getHTTPPage(url,data)
 Dim Http
 Set Http = Server.CreateObject("MSXML2.XMLHTTP")
 Http.Open "POST", url, False
 Http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
 Http.send(data)
 If Http.readystate <> 4 Then
 Exit Function
 End If
 getHTTPPage = BytesToBstr(Http.responseBody, "GB2312")
 Set Http = Nothing
 If Err.Number <> 0 Then Err.Clear
End Function
 
Function BytesToBstr(body, Cset)
 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 = Cset
 BytesToBstr = objstream.ReadText
 objstream.Close
 Set objstream = Nothing
End Function

function dtos(num)
  dtos=cstr(num)
  dim i
  'response.Write(num&":"&len(dtos)&"<br>")
  if len(dtos)<2 then
    for i=1 to 2-len(dtos)
   'response.Write("("&i&")")
      dtos="0"&dtos
   'response.Write(dtos)
    next
  else
     dtos=dtos
  end if
  'dtos=cint(dtos)
end function

function day_date() 'response.Write(month(now)&"-"&day(now)&"-"&hour(now)&"-"&minute(now)&"-"&second(now))
  day_month=dtos(month(now))
  day_day=dtos(day(now))
  day_hour=dtos(hour(now))
  day_minute=dtos(minute(now))
  day_second=dtos(second(now))
  day_date=cstr(year(now))&cstr(day_month)&cstr(day_day)&cstr(day_hour)&cstr(day_minute)&cstr(day_second)
 
end function
%>

 

posted @ 2017-02-18 22:13  djiz  阅读(2118)  评论(0编辑  收藏  举报