700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > NODE.JS如何开发短信接口发送短信验证码/短信通知demo示例

NODE.JS如何开发短信接口发送短信验证码/短信通知demo示例

时间:2020-08-10 02:43:54

相关推荐

NODE.JS如何开发短信接口发送短信验证码/短信通知demo示例

用户将收到的短信验证码填写到网站,网站对用户填写的验证码进行校验,如果一致,说明用户填写的手机号码是正确的,否则验证失败。

在开通手机短信验证功能之前,需要将网站同接口进行对接,对接的相关说明可以访问这个链接:。下载相应接口文件及说明文档,接入网站并调试运行。

本文为您提供了NODE.JS语言版本的验证码短信接口对接DEMO示例

/* ** 接口类型:互亿无线触发短信接口,支持发送验证码短信、订单通知短信等。* 账户注册:请通过该地址开通账户/?t9nyDN* 注意事项:*(1)调试期间,请使用用系统默认的短信内容:您的验证码是:【变量】。请不要把验证码泄露给其他人。*(2)请使用 用户名 及 APIkey来调用接口,APIkey在会员中心可以获取;*(3)该代码仅供接入互亿无线短信接口参考使用,客户可根据实际需要自行编写;*//*** Created by XadillaX on 14-2-12.* /XadillaX/ihuyi106js*/String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {if (!RegExp.prototype.isPrototypeOf(reallyDo)) {return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith);} else {return this.replace(reallyDo, replaceWith);}};var dom = require('xmldom').DOMParser;var _baseUri = "/webservice/sms.php?method=Submit";var _userAgent = "node-ihuyi106-module by 死月 (admin@xcoder.in)";/*** iHuyi constructure.* @param account* @param password 查看密码请登录用户中心->验证码、通知短信->帐户及签名设置->APIKEY*/var iHuyi = function(account, password) {this.spidex = require("spidex");this.spidex.setDefaultUserAgent(_userAgent);this.account = account;this.password = password;};/*** send an SMS.* @param mobile* @param content* @param callback*/iHuyi.prototype.send = function(mobile, content, callback) {var data = {account : this.account,password : this.password,mobile : mobile,content : content};this.spidex.post(_baseUri, function(html, status) {if(status !== 200) {callback(new Error("短信发送服务器响应失败。"));return;}html = html.replaceAll("\r", "");html = html.replaceAll("\n", "");html = html.replaceAll(" xmlns=\"/\"", "");//console.log(html);var doc = new dom().parseFromString(html);var result = doc.lastChild;var json = {};for(var node = result.firstChild; node !== null; node = node.nextSibling) {json[node.tagName] = node.firstChild.data;}//console.log(json);if(json.code == "2") {callback(null, json.smsid);} else {callback(new Error(json.msg, parseInt(json.code)));}}, data, "utf8").on("err", function(e) {callback(e);});};module.exports = iHuyi;

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。