阿里大于申请地址: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的更多相关文章

  1. PHP控制阿里云短信API接口实现短信群发功能

    阿里云短信支持先使用后支付的原则,价格为4分半1条. 通过SDK可以与网站功能的绑定,实现响应的短信发送功能 现已统一合并升级为:消息服务. 消息服务 阿里云消息服务(Message Service, ...

  2. 2018阿里云短信发送DEMO接入简单实例

    以下更新2018-04-2309:57:54 后续不再更新, 基本类: app/SignatureHelper.php <?php namespace aliyun_mns; /** * 签名助 ...

  3. asp实现阿里大鱼短信API接口的方法

    阿里大鱼是阿里推出的产品,官方提供JAVA..NET.PHP等版本的SDK下载,不知为何,唯独不提供ASP版本的SDK. 不提供没关系,自己写就是了,参照官方提供的API写一个就是了. 本来以为无非是 ...

  4. asp.net mvc 接入阿里大于 短信验证码发送

    项目前端页面实例 第1步:登录阿里大于控制台 https://www.alidayu.com/center/user/account?spm=0.0.0.0.P1K1jG 第2步:创建应用 第3步:配 ...

  5. Thinkphp5使用阿里大于短信验证

    现在各种平台登录验证很多时候会使用短信验证,快捷安全,有很多平台提供短信验证服务,相比较而言阿里大于价格比较便宜,快捷,所以在在千锋日常的php教学中多以此为例来说明短信验证的使用.下面我们在tp5中 ...

  6. .NET Core阿里大于短信发送SDK修改以及使用

    一.问题背景 继上次七牛云SDK的问题之后(参考:http://www.cnblogs.com/OMango/p/8447480.html),在发送短信的功能上又出现了问题,我们短信服务使用的是阿里大 ...

  7. thinkphp5阿里大于短信接口

    function autumn_sendsms($tel,$stype){ $pd_go=true; if($tel==''){ $msg='手机号不能为空'; $pd_go=false; } if( ...

  8. pyhthon 利用爬虫结合阿里大于短信接口实现短信发送天气预报

    # -*- coding: utf-8 -*- ''''' SDK for alidayu requires: python3.x, requests @author: raptor.zh@gmail ...

  9. 阿里大于短信服务_异常_01_InvalidTimeStamp.Expired

    一.异常信息 dm.aliyuncs.com InvalidTimeStamp.Expired Specified time stamp or date value is expired. 二.异常原 ...

随机推荐

  1. Amaze UI的一点总结

    做一个微信公众号内的网页的时候,用到了Amaze UI,也称妹子UI. 官网上宣称,Amaze UI中国首个开源 HTML5 跨屏前端框架,用下来的感觉是比较类似于bootstrap,都是移动端优先. ...

  2. centos7常见的操作01 UTC CST

      CentOS系统将UTC时间修改为CST时间方法 2018-10-31 07:51 世界协调时间(Universal Time Coordinated,UTC): GPS 系统中有两种时间区分,一 ...

  3. 初级模拟电路:1-2 PN结与二极管

    回到目录 1.   掺杂半导体 上面我们分析了本征半导体的导电情况,但由于本征半导体的导电能力很低,没什么太大用处.所以,一般我们会对本征半导体材料进行掺杂,即使只添加了千分之一的杂质,也足以改变半导 ...

  4. VMware VCSA 6.0安装过程 (转)

    VMware VCSA 6.0安装过程(专版)  一.环境准备   VMware vCenter Server Appliance(VCSA)6.0的部署和之前的版本不同,在5.5及之前的版本可以通过 ...

  5. 网络教程(9)ARP。IP和以太网间映射

    question: how does a knows that SFO is the right place to send as Ethernet frame subnet Mask: its ju ...

  6. JavaScript 数字字符串比较大小

    JavaScript中常用数字字符串比较 1.数字与数字之间直接比较 比较方式依据数学运算,没什么好说的. 2.数字与字符串数字之间直接比较 例如 数字5 与字符串数字'123',这种比较先将数字字符 ...

  7. BZOJ 3439 Kpm的MC密码 (Trie树+线段树合并)

    题面 先把每个串反着插进$Trie$树 每个节点的子树内,可能有一些节点是某些字符串的开头 每个节点挂一棵权值线段树,记录这些节点对应的原来字符串的编号 查询的时候在线段树上二分即可 为了节省空间,使 ...

  8. [Papers] Semantic Segmentation Papers(1)

    目录 FCN Abstract Introduction Related Work FCN Adapting classifiers for dense prediction Shift-and-st ...

  9. ELK介绍及搭建 Elasticsearch 分布式集群

    上:https://blog.51cto.com/zero01/2079879 下:https://blog.51cto.com/zero01/2082794

  10. 如何让 Laravel API 永远返回 JSON 格式响应?

    当你在编写完全为 API 服务的 Laravel 应用时,你希望所有响应都是 JSON 格式的,而不是例如说授权错误会重定向到 /home 或 /login,最终重定向会变成 InvalidArgum ...