腾讯短信平台ASP接口范例
2024-09-08 01:29:19
疫情后一个小项目要用到腾讯短信平台,因为比较老,用ASP写的,平台没有相应的ASP接口,百度不到,无奈之下自己写了一个,也方便需要的朋友们。
主要代码如下:
<!--#include file="comm_sms.asp"-->
<%
'------------------------------------------------
' Copyright (c) 2020, shenzhen haowen
'
' SPDX-License-Identifier: Apache-2.0
'
' Change Logs:
' Date Author Notes
' 2020-12-05 812256@qq.com first version
'------------------------------------------------
'重要说明:
'1.在腾讯平台注册审核
'2.提交短信模板审核
'3.通过后再根据短信模板实际参数测试
'
'-------需要设置的部分开始----------
strMobile = "查看腾讯短信平台接口"
strAppKey = "查看腾讯短信平台接口"
sign = "查看腾讯短信平台接口"
tpl_id = 561230 '查看腾讯短信平台接口
'-------需要设置的部分结束---------- RANDOMIZE
strRand = cstr(int(rnd()*9999999999))
strTime = cstr(ToUnixTime(now()))
sig = sha256("appkey=" & strAppKey & "&random=" & strRand & "&time=" & strTime & "&mobile=" & strMobile) phone = Request.Form("p")
cartype = Request.Form("c")
otime = Request.Form("o")
addr = Request.Form("a")
if phone=0 or cartype="" or otime="" or addr="" then
%>
<html>
<head>
<style>
label {
display: block;
padding: 0.5em;
max-width: 20em;
}
input {
float: right;
}
</style>
<title>腾讯短信平台ASP接口测试</title>
</head>
<body>
<form method="post" action="">
<p><b>腾讯短信平台ASP接口测试</b></p>
<label>接收手机号:<input name="p" value="<%=strMobile%>"></label>
<label>短信模板参数1:<input name="c" value="cartype1"></label>
<label>短信模板参数2:<input name="o" value="2020-12-05"></label>
<label>短信模板参数3:<input name="a" value="预约地点"></label>
<label>短信模板参数4:<input type="submit" value="提交测试"></label>
</form>
</body>
</html>
<%
else
%>
<!-- 参考:https://cloud.tencent.com/document/product/382/5976 -->
<script src="vendor/jquery/jquery.min.js"></script>
<script>
$(function () { postdata = {
"ext": "",
"extend": "",
"params": [
//这里是你短信模板中的实际参数
"<%=phone%>",
"<%=cartype%>",
"<%=otime%>",
"<%=addr%>"
],
"sig": "<%=sig%>",
"sign": "<%=sign%>",
"tel": {
"mobile": "<%=phone%>",
"nationcode": "86"
},
"time": "<%=strTime%>",
"tpl_id": <%=tpl_id%>
};
console.log(postdata);
console.log(JSON.stringify(postdata));
$.ajax({
contentType: 'application/json',
type: 'POST',
url: "https://yun.tim.qq.com/v5/tlssmssvr/sendsms?sdkappid=1400338975&random=<%=strRand%>",
dataType: "json",
data: JSON.stringify(postdata),
success: function (message) {
if (message.result != 0) {
alert("短信发送失败:" + message.errmsg + ",错误码:" + message.result + "\n\n看到此信息说明接口调用成功,但是参数设置错误");
history.back(-1);
}
else {
alert("通知短信发送成功。");
}
},
error: function (message) {
alert("短信发送失败:", message);
}
});
});
</script>
<%end if%>
本机测试:
手机短信截图:
项目开源地址:https://github.com/Lihao2017-11-15/tencent_sms_asp
最新文章
- IE9 IE8 ajax跨域问题的解决
- Could not parse mapping document from input stream
- Linux下PHP的完全卸载
- UILable
- vi 整行 多行 复制与粘贴
- .NET平台下,关于数据持久层框架
- Oracle存储过程学习备忘
- java 集装箱 arraylist 用法
- Essential C#读书笔记
- visual studio 中将选中代码相同的代码的颜色设置,修改高亮颜色
- 如何用VS进行程序调试
- 天融信防火墙NGFW4000,无法进入web管理和community属性查看
- leetcode第三题
- PHP 使用 MongoDB
- 快速开发jQuery插件的10大技巧
- _new_()与_init_()的区别
- 微信小程序组件 自定义弹出框
- HTML5学习笔记4
- 在Unity中实现屏幕空间反射Screen Space Reflection(4)
- Mysql存储之ORM框架SQLAlchemy(一)
热门文章
- ElasticSearch7.3破解
- php ci下添加一个创建常用的模块和控制器方法
- Ubuntu 18.04.2 LTS美化方案
- Entity Fremework以及Fluentapi学习
- 性能问题,AWR High Event enq: US - contention
- 手把手教你使用rpm部署ceph集群
- BATJTMD,大厂招聘,都招什么样Java程序员?
- 6. Spark SQL和Beeline
- @requestBody 与@requestparam详解
- IDEA与Eclipse创建struts项目