写这篇文章缘由,是用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");
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));`
这就是JavaScript - Fetch方式实现短信验证功能,是不是很简单,除此之外,还应该为短信接口加上滑动验证等安全锁,防止恶意消耗企业短信条数。
每天多学习一点,总有一天小白也会变大神,祝大家都有美好的一天。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。