寫這篇文章原因,是用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