ASP版_阿里大于短信API Demo
阿里大于申请地址:http://www.alidayu.com
阿里大于短信发送Demo:
******index.asp*************
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="Alidayu_sms_send.asp" -->
<%
Dim Code,Mobile
Dim Sms,result,SMSParam
Code = MakeRandNum()
Session("code") = Code
Mobile = Request("mobile")
SMSParam = Array("number="&Code)'短信模板变量,传参规则Array{"key=value","key1=value1"},key的名字须和申请模板中的变量名一致,
If Mobile<>"" then
Set Sms = New Alidayu_sms_send
Sms.AppKey = "23631215" '阿里大鱼分配给你的AppKey
Sms.Secret = "96d77a7c4d9185feecf682d92128318b"'AppKey对应的Secret
Sms.SignName = "阿里大鱼" '在阿里大鱼管理后台中通过审批的短信签名
Sms.TplCode = "SMS_46731512" '在阿里大鱼管理后台中通过审批的短信模板IDSMS_20185053
Sms.RecNum = Mobile ' 要接收短信的手机号码
Sms.Extend = "2356" '公共回传参数
Sms.SMSParam = Sms.ToJson(SMSParam)
'Response.Write(Sms.ToJson(SMSParam))
result = Sms.SendSMS()
If result = True Then
Response.Write("发送成功!")
Else
Response.Write(result)
End If
Set Sms = Nothing
Response.End()
End If
Function MakeRandNum()
Randomize
Dim width : width = 6 '随机数长度,默认6位
width = 10 ^ (width - 1)
MakeRandNum = Int((width*10 - width) * Rnd() + width)
End Function
%>
<!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>ASP_阿里大于短信好送Demo</title>
<link href="http://bootstrap.ninghao.net/assets/css/bootstrap.css" rel="stylesheet">
<link href="http://bootstrap.ninghao.net/assets/css/bootstrap-responsive.css" rel="stylesheet">
<link href="http://bootstrap.ninghao.net/assets/css/docs.css" rel="stylesheet">
<link href="http://bootstrap.ninghao.net/assets/js/google-code-prettify/prettify.css" rel="stylesheet">
<script type="text/javascript" src="http://www.w3school.com.cn/jquery/jquery-1.11.1.min.js"></script>
<style>
ul,li{ margin:0px; padding:0px; list-style-type:none}
.controls{ display:inline}
</style>
</head>
<body>
<ul class="ulist">
<li class="group">
<label class="label" for="phone">手机号:</label>
<div class="input-append">
<input class="span2" type="text" id="phone">
</div>
</li>
<li class="group">
<label class="label" for="code">验证码:</label>
<div class="input-append">
<input class="span2" type="text" id="code">
<button class="btn" type="button" id="J_getCode" onClick="getCode(this)">获取验证码</button>
</div>
</li>
</ul>
<script>
var isPhone = 1;
function getCode(e){
checkPhone(); //验证手机号码
if(isPhone){
send();
resetCode(); //倒计时
}else{
$('#phone').focus();
}
}
//验证手机号码
function checkPhone(){
var phone = $('#phone').val();
var pattern = /^1[0-9]{10}$/;
isPhone = 1;
if(phone == '') {
alert('请输入手机号码');
isPhone = 0;
return;
}
if(!pattern.test(phone)){
alert('请输入正确的手机号码');
isPhone = 0;
return;
}
}
//倒计时
function resetCode(){
$('#J_getCode').attr('disabled','disabled');
$('#J_getCode').html("<span id='J_second'>60</span>秒后重发");
$('#J_second').html('60');
var second = 60;
var timer = null;
timer = setInterval(function(){
second -= 1;
if(second >0 ){
$('#J_second').html(second);
}else{
clearInterval(timer);
$('#J_getCode').removeAttr("disabled");
$('#J_getCode').html("获取验证码");
}
},1000);
}
function send(){
var url="";
$.get(url,
{
mobile:$('#phone').val()
},
function(data,status){
alert(data);
});
}
</script>
</body>
</html>
*************Alidayu_sms_send.asp******************
<!--#include file="MD5.asp" -->
<script language="jscript" runat="server">
function getjson(str){
try{
eval("var jsonStr = (" + str + ")");
}catch(ex){
var jsonStr = null;
}
return jsonStr;
}
</script>
<%
'==================================
'=类 名 称:Alidayu_sms_send
'=功 能:阿里大于短信发送类
'=作 者:㊣FireFox㊣
'=Q Q: 63572063
'=日 期:2016-10-20
'==================================
'转载时请保留以上内容!!
Class Alidayu_sms_send
Private s_author,s_version,a_list,b_list,s_method,s_v,s_format,s_simplify,s_secret,s_app_key,s_sign_method
Private s_sms_type,s_sms_free_sign_name,s_rec_num,s_sms_template_code,s_extend,s_sms_param
Private s_error_AppKey,s_error_Secret,s_error_SignName,s_error_RecNum,s_error_TplCode
Private Sub Class_Initialize()
s_author = "FireFox"
s_version = "1.0"
s_method = "alibaba.aliqin.fc.sms.num.send" 'API接口名称,这里是短信发送的接口
s_v = "2.0" 'API协议版本
s_format = "json" '响应格式
s_simplify = false '是否采用精简JSON返回格式,仅当format=json时有效,默认值为:false
s_sign_method = "md5" '签名的摘要算法
s_sms_type = "normal" '短信类型,传入值请填写normal
s_secret = "" 'APP的Secret,加密时用
s_app_key = "" '应用的AppKey
s_sms_free_sign_name = "" '短信签名,传入的短信签名必须是在阿里大鱼“管理中心-短信签名管理”中的可用签名
s_rec_num = "" '短信接收号码。支持单个或多个手机号码,传入号码为11位手机号码,不能加0或+86。群发短信需传入多个号码,以英文逗号分隔,一次调用最多传入200个号码。示例:18600000000,13911111111,13322222222
s_sms_template_code = "" '短信模板ID,传入的模板必须是在阿里大鱼“管理中心-短信模板管理”中的可用模板
s_extend = "" '公共回传参数,在“消息返回”中会透传回该参数;举例:用户可以传入自己下级的会员ID,在消息返回时,该会员ID会包含在内,用户可以根据该会员ID识别是哪位会员使用了你的应用
s_sms_param = "" '短信模板变量,传参规则{"key":"value"},key的名字须和申请模板中的变量名一致,多个变量之间以逗号隔开。示例:针对模板“验证码${code},您正在进行${product}身份验证,打死不要告诉别人哦!”,传参时需传入{"code":"1234","product":"alidayu"}
s_error_AppKey = "AppKey属性为空。"
s_error_Secret = "Secret属性为空。"
s_error_SignName = "SignName属性为空。"
s_error_RecNum = "RecNum属性为空。"
s_error_TplCode = "TplCode属性为空。"
End Sub
Private Sub Class_Terminate()
End Sub
'应用的AppKey属性
Public Property Let AppKey(ByVal String)
s_app_key = String
End Property
'APP的Secret,加密时用
Public Property Let Secret(ByVal String)
s_secret = String
End Property
'短信签名
Public Property Let SignName(ByVal String)
s_sms_free_sign_name = String
End Property
'短信接收号码
Public Property Let RecNum(ByVal String)
s_rec_num = String
End Property
'短信模板ID
Public Property Let TplCode(ByVal String)
s_sms_template_code = String
End Property
'公共回传参数
Public Property Let Extend(ByVal String)
s_extend = String
End Property
'短信模板变量
Public Property Let SMSParam(ByVal String)
s_sms_param = String
End Property
'发送短信,成功返回True,错误返回错误信息
Public Default Function SendSMS()
If s_app_key="" Then SendSMS=s_error_AppKey:Exit Function:End If
If s_secret="" Then SendSMS=s_error_Secret:Exit Function:End If
If s_sms_free_sign_name="" Then SendSMS=s_error_SignName:Exit Function:End If
If s_rec_num="" Then SendSMS=s_error_RecNum:Exit Function:End If
If s_sms_template_code="" Then SendSMS=s_error_AppKey:Exit Function:End If
'生成参数的键数组,原始字典对象
Dim a,b,d,k,u,l,j,Arr
Set d = Server.CreateObject("Scripting.Dictionary")
'公用参数
d.RemoveAll
d.Add "method",s_method
d.Add "app_key",s_app_key
d.Add "timestamp",GetDateTimeFormat()
d.Add "format",s_format
d.Add "v",s_v
d.Add "sms_type",s_sms_type
d.Add "simplify",s_simplify
d.Add "sign_method",s_sign_method
'接口参数
d.Add "sms_free_sign_name",s_sms_free_sign_name
d.Add "rec_num",s_rec_num
d.Add "sms_template_code",s_sms_template_code
d.Add "extend",s_extend
d.Add "sms_param",s_sms_param
Arr= SortPara(MakeArray(d))
u = CreateLinkstring(Arr)
i = CreateLinkStringUrlEncode(Arr)
i = i&Md5Sign(s_secret,u)
Set d = Nothing
Dim url : url="http://gw.api.taobao.com/router/rest?"&i
j=RequestUrl(url)
'Response.Write(j)
If Instr(j,"alibaba_aliqin_fc_sms_num_send_response")>0 Then
SendSMS = True
Else
set obj = getjson(j)
if isobject(obj) Then
ret = obj.error_response.code
msg = obj.error_response.msg
If Instr(j,"sub_msg")>0 Then
sub_code = obj.error_response.sub_code
sub_msg = obj.error_response.sub_msg
End If
End If
set obj = Nothing
If sub_code="" Then
SendSMS = msg
Else
SendSMS = sub_msg
End If
End If
End Function
'Get方法请求url,获取请求内容
Public Function RequestUrl(url)
Set XmlObj = Server.CreateObject("Microsoft.XMLHTTP")'MSXML2.XMLHTTP,Microsoft.XMLHTTP
XmlObj.open "Get",url, False
XmlObj.send
RequestUrl = XmlObj.ResponseText
Set XmlObj = nothing
End Function
''
' 对数组排序
' param sPara 排序前的数组
' return 排序后的数组
Function SortPara(sPara)
Dim nCount
nCount = ubound(sPara)
For i = nCount To 0 Step -1
minmax = sPara( 0 )
minmaxSlot = 0
For j = 1 To i
mark = (sPara( j ) > minmax)
If mark Then
minmax = sPara( j )
minmaxSlot = j
End If
Next
If minmaxSlot <> i Then
temp = sPara( minmaxSlot )
sPara( minmaxSlot ) = sPara( i )
sPara( i ) = temp
End If
Next
SortPara = sPara
end function
Private Function MakeArray(d)
Dim Str
Dim k
For Each k In d
Str = Str & k & "=" & d(k) & "&"
Next
Str = Left(Str, Len(Str)-1)
MakeArray = split(Str,"&")
End Function
' 获取当前时间
' 格式:年[4位]-月[2位]-日[2位] 小时[2位 24小时制]:分[2位]:秒[2位],如:2007-10-01 13:13:13
' return 时间格式化结果
Function GetDateTimeFormat()
sTime=now()
sResult = year(sTime)&"-"&right("0" & month(sTime),2)&"-"&right("0" & day(sTime),2)&" "&right("0" & hour(sTime),2)&":"&right("0" & minute(sTime),2)&":"&right("0" & second(sTime),2)
GetDateTimeFormat = sResult
End Function
''
' 过滤特殊字符
' param Str 要被过滤的字符串
' return 已被过滤掉的新字符串
Function DelStr(Str)
If IsNull(Str) Or IsEmpty(Str) Then
Str = ""
End If
DelStr = Replace(Str,";","")
DelStr = Replace(DelStr,"'","")
DelStr = Replace(DelStr,"&","")
DelStr = Replace(DelStr," ","")
DelStr = Replace(DelStr," ","")
DelStr = Replace(DelStr,"%20","")
DelStr = Replace(DelStr,"--","")
DelStr = Replace(DelStr,"==","")
DelStr = Replace(DelStr,"<","")
DelStr = Replace(DelStr,">","")
DelStr = Replace(DelStr,"%","")
End Function
''
' MD5签名
' param prestr 需要签名的字符串
' return 签名结果
Function Md5Sign(s_secret,str)
Dim mysign
mysign = UCase(MD5((s_secret&str&s_secret),"utf-8"))
Md5Sign = "sign="&mysign
End Function
Public Function ToJson(sPara)
Dim Json_Str,key,val,i
Json_Str = "{"
For i = 0 To Ubound(sPara)
'把sPara的数组里的元素格式:变量名=值,分割开来
pos = Instr(sPara(i),"=") '获得=字符的位置
nLen = Len(sPara(i)) '获得字符串长度
key = left(sPara(i),pos-1) '获得变量名
val = right(sPara(i),nLen-pos)'获得变量的值
If i = Ubound(sPara) then
Json_Str = Json_Str & """"&key&""":"""&val&""""
Else
Json_Str = Json_Str & """"&key&""":"""&val&""","
End If
Next
Json_Str = Json_Str &"}"
ToJson = Json_Str
End Function
''
' 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
' param sPara 需要拼接的数组
' return 拼接完成以后的字符串
Function CreateLinkstring(sPara)
nCount = ubound(sPara)
dim prestr
for i = 0 to nCount
'把sPara的数组里的元素格式:变量名=值,分割开来
pos = Instr(sPara(i),"=") '获得=字符的位置
nLen = Len(sPara(i)) '获得字符串长度
itemName = left(sPara(i),pos-1) '获得变量名
itemValue = right(sPara(i),nLen-pos)'获得变量的值
prestr = prestr & itemName & itemValue
next
CreateLinkstring = prestr
End Function
''
' 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并且做urlencode编码
' param sPara 需要拼接的数组
' return 拼接完成以后的字符串
function CreateLinkStringUrlEncode(sPara)
nCount = ubound(sPara)
dim prestr
for i = 0 to nCount
'把sPara的数组里的元素格式:变量名=值,分割开来
pos = Instr(sPara(i),"=") '获得=字符的位置
nLen = Len(sPara(i)) '获得字符串长度
itemName = left(sPara(i),pos-1) '获得变量名
itemValue = right(sPara(i),nLen-pos)'获得变量的值
prestr = prestr & itemName &"=" & server.URLEncode(itemValue) & "&"
next
CreateLinkStringUrlEncode = prestr
end function
End Class
%>
转载:http://bbs.muyunet.com/forum.php?mod=viewthread&tid=86
ASP版_阿里大于短信API Demo的更多相关文章
- PHP控制阿里云短信API接口实现短信群发功能
阿里云短信支持先使用后支付的原则,价格为4分半1条. 通过SDK可以与网站功能的绑定,实现响应的短信发送功能 现已统一合并升级为:消息服务. 消息服务 阿里云消息服务(Message Service, ...
- 2018阿里云短信发送DEMO接入简单实例
以下更新2018-04-2309:57:54 后续不再更新, 基本类: app/SignatureHelper.php <?php namespace aliyun_mns; /** * 签名助 ...
- asp实现阿里大鱼短信API接口的方法
阿里大鱼是阿里推出的产品,官方提供JAVA..NET.PHP等版本的SDK下载,不知为何,唯独不提供ASP版本的SDK. 不提供没关系,自己写就是了,参照官方提供的API写一个就是了. 本来以为无非是 ...
- asp.net mvc 接入阿里大于 短信验证码发送
项目前端页面实例 第1步:登录阿里大于控制台 https://www.alidayu.com/center/user/account?spm=0.0.0.0.P1K1jG 第2步:创建应用 第3步:配 ...
- Thinkphp5使用阿里大于短信验证
现在各种平台登录验证很多时候会使用短信验证,快捷安全,有很多平台提供短信验证服务,相比较而言阿里大于价格比较便宜,快捷,所以在在千锋日常的php教学中多以此为例来说明短信验证的使用.下面我们在tp5中 ...
- .NET Core阿里大于短信发送SDK修改以及使用
一.问题背景 继上次七牛云SDK的问题之后(参考:http://www.cnblogs.com/OMango/p/8447480.html),在发送短信的功能上又出现了问题,我们短信服务使用的是阿里大 ...
- thinkphp5阿里大于短信接口
function autumn_sendsms($tel,$stype){ $pd_go=true; if($tel==''){ $msg='手机号不能为空'; $pd_go=false; } if( ...
- pyhthon 利用爬虫结合阿里大于短信接口实现短信发送天气预报
# -*- coding: utf-8 -*- ''''' SDK for alidayu requires: python3.x, requests @author: raptor.zh@gmail ...
- 阿里大于短信服务_异常_01_InvalidTimeStamp.Expired
一.异常信息 dm.aliyuncs.com InvalidTimeStamp.Expired Specified time stamp or date value is expired. 二.异常原 ...
随机推荐
- Python基础:dict & set
一 :dict 1:Python内置了字典:dict的支持,dict全称dictionary,在其他语言中也称为map,使用键-值(key-value)存储,具有极快的查找速度. eg: dict查找 ...
- 【airtest】iOS,Android 依托 jenkins 并行跑
Airtest 只支持一台mac 连接一台iPhone, 以下方法是以“一台mac 连接一台iPhone”为基础,依托jenkins 统一管理多台iPhone. [mac] jenkins mast ...
- SyntaxError Non-ASCII character '\xe5' in file
环境: windows7 Python 2.7.16 在源码中添加注释之后报错如下: (WeChat) E:\WorkHome\Wechat>python firstBlood.py Trace ...
- 小白学习Spark系列一:Spark简介
由于最近在工作中刚接触到scala和Spark,并且作为python中毒者,爬行过程很是艰难,所以这一系列分为几个部分记录下学习<Spark快速大数据分析>的知识点以及自己在工程中遇到的小 ...
- Python笔记21-------浅复制和深复制、赋值
上面图表示浅复制和深复制,针对顶层对象来说,赋值为引用,浅复制和深复制都是复制一个新的对象. 针对子对象来说,浅复制为引用.深复制就是复制两个一样的. 1.赋值 A= [ 1,2,3, [ 'a',' ...
- WSDL实例解析
WSDL的主要文档元素 WSDL文档可以分为两部分.顶部分由抽象定义组成,而底部分则由具体描述组成.抽象部分以独立于平台和语言的方式定义SOAP消息,它们并不包含任何随 机器或语言而变的元素.这就定义 ...
- 训练1-D
把一个字符三角形掏空,就能节省材料成本,减轻重量,但关键是为了追求另一种视觉效果.在设计的过程中,需要给出各种花纹的材料和大小尺寸的三角形样板,通过电脑临时做出来,以便看看效果. Input 每行包含 ...
- win主机ping不通linux的IP
1.虚拟机的中的linux系统设置成桥接模式 2.点击虚拟机的编辑选择虚拟网络编辑器 3.点击更改设置 4点击还原默认设置即可
- 转[总结]FFMPEG视音频编解码零基础学习方法 .
http://blog.csdn.net/leixiaohua1020/article/details/15811977 在CSDN上的这一段日子,接触到了很多同行业的人,尤其是使用FFMPEG进行视 ...
- CentOS 安装 VMTools
1.点击虚拟机,选择 安装 VMware Tools 2.把 压缩包 复制到桌面 3.给当前用户管理员权限,然后解压该压缩包 4.进入到解压后的文件夹 5.执行 vmware-install.pl 6 ...