文档中心

新手指南 / 服务介绍 / 接口说明 / 代码示例 / 注意事项

ASP

感谢 liuchao 提供ASP版代码示例。: P

示例中验证部分username固定为api,password格式为key-32位KEY,各位的KEY可在后台短信或语音->触发发送下查看、更改

 

发送短信
发送语音
短信发送&余额获取
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="base64.asp"-->
<%
response.contenttype = "text/html;charset=utf-8"

'短信接口的 Authorization 认证
function request_auth(method,url,auth,data,cset)
dim xml
set xml = server.createobject("Msxml2.ServerXMLHTTP.3.0")
    xml.open method,url,false
    xml.setrequestheader "Authorization",auth
    if method = "POST" then
        xml.setrequestheader "content-length",len(data)
        xml.setrequestheader "content-type","application/x-www-form-urlencoded"
        xml.send(data)
    else
        xml.send()
    end if
    on error resume next
    request_auth = xml.responseText
    if err then
        err.clear
        request_auth = bytetostr(xml.responseBody,cset)
    end if
set xml = nothing
end function

'ByteToStr
function bytetostr(vin,cset)
dim bs,sr
set bs = server.createObject("adodb.stream")
    bs.type = 2
    bs.open
    bs.writetext vin
    bs.position = 0
    bs.charset = cset
    bs.position = 2
    sr = bs.readtext
    bs.close
set bs = nothing
bytetostr = sr
end function

'API & KEY
api_username = "api"
api_password = "key-XXXXXXXXXXXXXXXXXXXXXXXX"
api_auth = "Basic " & encode64(api_username & ":" & api_password)

'短信发送
sms_mobile = "13936628410"
sms_message = "测试验证码是654321【luosimao】"
api_urlsend = "http://sms-api.luosimao.com/v1/send.json"
api_data = "mobile=" & sms_mobile & "&message=" + sms_message
api_method = "POST"
response.write "发送短信:" & request_auth(api_method,api_urlsend,api_auth,api_data,api_charset)
response.write "<hr>"

'余额状态
api_urlstatus = "http://sms-api.luosimao.com/v1/status.json"
api_method = "GET"
api_charset = "utf-8"
api_data = ""
response.write "短信余额:" & request_auth(api_method,api_urlstatus,api_auth,api_data,api_charset)
response.write "<hr>"
%>
短信语音&余额获取
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="base64.asp"-->
<%
response.contenttype = "text/html;charset=utf-8"

'短信接口的 Authorization 认证
function request_auth(method,url,auth,data,cset)
dim xml
set xml = server.createobject("Msxml2.ServerXMLHTTP.3.0")
    xml.open method,url,false
    xml.setrequestheader "Authorization",auth
    if method = "POST" then
        xml.setrequestheader "content-length",len(data)
        xml.setrequestheader "content-type","application/x-www-form-urlencoded"
        xml.send(data)
    else
        xml.send()
    end if
    on error resume next
    request_auth = xml.responseText
    if err then
        err.clear
        request_auth = bytetostr(xml.responseBody,cset)
    end if
set xml = nothing
end function

'ByteToStr
function bytetostr(vin,cset)
dim bs,sr
set bs = server.createObject("adodb.stream")
    bs.type = 2
    bs.open
    bs.writetext vin
    bs.position = 0
    bs.charset = cset
    bs.position = 2
    sr = bs.readtext
    bs.close
set bs = nothing
bytetostr = sr
end function

'API & KEY
api_username = "api"
api_password = "key-XXXXXXXXXXXXXXXXXXXXXXXX"
api_auth = "Basic " & encode64(api_username & ":" & api_password)

'语音发送
sms_mobile = "13936628411"
sms_code = "123456"
api_urlsend = "http://voice-api.luosimao.com/v1/verify.json"
api_data = "mobile=" & sms_mobile & "&code=" + sms_code
api_method = "POST"
response.write "发送短信:" & request_auth(api_method,api_urlsend,api_auth,api_data,api_charset)
response.write "<hr>"

'余额状态
api_urlstatus = "http://voice-api.luosimao.com/v1/status.json"
api_method = "GET"
api_charset = "utf-8"
api_data = ""
response.write "短信余额:" & request_auth(api_method,api_urlstatus,api_auth,api_data,api_charset)
response.write "<hr>"
%>
微信客服
立即咨询
客服热线:
021-60193106
服务时间:
9:00-18:00
(周日除外)