写这篇文章原因,是用JavaScript对接短信验证码接口老是失败,而后去找网上师傅解决,最后用Fetch方式实现短信验证功能,今天就把代码发出来和你们分享一下。
`var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");安全
var urlencoded = new URLSearchParams();
urlencoded.append("appId", "41KYR0EB**");
urlencoded.append("appKey", "IIWCKKSR7NOQ**");
urlencoded.append("phone", "1561894**");
urlencoded.append("templateId", "1043");
urlencoded.append("variables", "1234");app
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: urlencoded,
redirect: 'follow'
};学习
fetch("https://vip.veesing.com/smsApi/verifyCode", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));`fetch
这就是JavaScript - Fetch方式实现短信验证功能,是否是很简单,除此以外,还应该为短信接口加上滑动验证等安全锁,防止恶意消耗企业短信条数。url
天天多学习一点,总有一天小白也会变大神,祝你们都有美好的一天。.net