wifi免密码登录认证流程
用户登陆接口
[Access Authorization]
在我们的设备固件制作过程中,我们使用了与大多数电信运营商相同的 Portal认证 技术,其中系统架构上主要由 AP无线访问接入点(Wireless Access Point)、AC接入控制器(Wireless Access Point Controller)、认证页面服务器(Captive Portal Server)、认证计费服务器(Cloud Radius Server)构成,而在云端,我们完成了Portal页面的云存储,Captive Portal页面在线编辑,Portal静态文件CDN加速,以及上网用户数据的分析展示,同时radius服务器也通过Oauth2.0协议与第三方账户系统的打通。
Portal认证:

您需要做什么?
您只需要完成 Portal页面 与 AC接入控制器(路由器) 的局域网通信即可,而在路由器固件中我们配置的 Radius客户端 将代替网络接入请求者向 认证计费服务器 发送认证请求,返回认证结果。
Portal页面 与 AC接入控制器(路由器) 之间的通信是通过json Api 完成的,为了方便您的快速开发,我们提供了Javascript Library,您只需要引入制定JS文件,通过简单的编写Javascript代码即可自定义您的账户认证,而这一切都可以通过 在线编辑代码 完成。
您应该怎样去做?
一、 编辑认证页面模板,引入JS文件
<script src="http://s.anywifi.com/resources/anywifiLibrary.js"></script>
注意:请不要下载保存该文件,我们将不定期更新完善该Library.
二、 几种常用认证方式
1、匿名登陆(访客模式)
匿名登陆接口函数:anonymousLogin();
在上网用户未通过认证前,可以通过 访客模式 获取短暂的网络接入权限,或者您只需要访客 点击某链接即可上网 ,在这里即可使用匿名登陆实现(匿名登陆获取的网络接入 时常、带宽 均可在管理平台上网用户-用户组 中进行设置)。
示例
<!doctype html>
<html>
<head>
<title>{title}</title>
<script src="http://s.anywifi.com/resources/anywifiLibrary.js"></script>
</head>
<body>
<a href="anonymousLogin();">匿名登陆</a>
<p>点击上面链接,即可免费上网。</p>
</body>
</html>
当然,你也可以利用JS的定时器来显示打开页面(点击按钮)N秒后自动登陆,效果如下:

代码如下:
<!doctype html>
<html>
<head>
<title>{title}</title>
<script src="http://s.anywifi.com/resources/anywifiLibrary.js"></script>
<script type="text/javascript">
function timer(){
var i = 10;
$("#dt2").show();
$("#dt1").hide();
var ttt = window.setInterval(function(){
i--;
$("#time").html(i);
if(i==0){
clearInterval(ttt);
anonymousLogin();
}
}, 1000);
}
</script>
</head>
<body>
<dl>
<dt id="dt1">
<a href="javascript:void(0)" onclick="timer();"><span>1</span><span>点击试用免费WIFI</span></a>
</dt>
<dt id="dt2" style="display:none;">
<a href="javascript:void(0)"><span>1</span><span>上网配置中<em id="time">10</em></span></a>
</dt>
</dl>
</body>
</html>
2、微信登陆
微信登陆接口地址:http://c.anywifi.com/api/weixinlogin?uid=<平台账户UID>(“<平台账户UID>”需要 <a "http:="" c.anywifi.com="" user="" login.html"="" target="_blank">登陆平台 后显示)
上述微信登陆接口地址,适用于在上网 认证页面 提示用户 关注某微信账户,然后微信账户在用户关注后自动回复 该地址链接,用户使用微信点击此链接时,则将自动调用JS微信登陆接口函数,完成 微信一键关注上网 ,如果不是在微信中访问的此API地址,则将会出现请打开微信客户端的 提示。
微信一键关注上网:

微信登陆接口函数:webchatLogin();
获取页面推广微信账户:http://c.anywifi.com/api/weixinname?nasid=[NASID](NASID 参数可以从URL的GET查询字符串中获取)
微信登陆接口函数 是区别于 匿名登陆接口的,主要是因为管理平台可以对两种用户组分别设置不同的 时常、带宽组别属性,微信登陆接口,我们通常利用微信浏览器的UA( 微信浏览器User-Agent )的特殊性,来判断是否是在微信浏览器中点击此链接,查看此页面,决定是否予以网络接入,上面提到的 微信关注一键上网接口 就是采用该思路实现的。
示例
<!doctype html>
<html>
<head>
<title>{title}</title>
<script src="http://s.anywifi.com/resources/anywifiLibrary.js"></script>
<script type="text/javascript">
//通过查询字符串中的NASID判断查询该设备认证页面需要推广的微信账号
var nasId = getQueryString('nasid');
ajaxLoad("GET","http://c.anywifi.com/api/weixinname?nasid="+nasId+"&t="+Math.random(),function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
getel('wx_name').innerHTML = xmlhttp.responseText;
}
});
});
</script>
</head>
<body>
<div class="gridContainer clearfix" id="forpc" style="display:none;">
<div id="div1" class="fluid wrapper test transition">
<h1 id="logo" class="test"><img class="lo_ico" src="http://s.anywifi.com/resources/template/1/webchatonekeylogin/warnico.png"></h1>
<div class="notecont transition">
<h2>WebChat Only</h2>
<a class="golink" href="weixin://qr/gEx_Zm-EdTlKrSsF9xmS">关注微信<span id="wx_name"></span>认证上网</a>
</div>
</div>
</div>
<div class="gridContainer clearfix" id="forweixin" style="display:none;">
<div id="div1" class="fluid wrapper test transition">
<h1 id="logo" class="test"><img class="lo_ico" src="http://s.anywifi.com/resources/template/1/webchatonekeylogin/successico.png"></h1>
<div class="notecont transition">
<h2>登陆成功</h2>
</div>
</div>
</div>
<script type="text/javascript">
//根据UA判断
var ua = navigator.userAgent.toLowerCase();
var url = window.location.href;
if(ua.indexOf("android")!=-1 || ua.indexOf("iphone")!=-1 || ua.indexOf("ipad")!=-1 || ua.indexOf("phone")!=-1){ //mobile end
//micromessenger
if(ua.indexOf("micromessenger")!=-1){
getel('forweixin').style.display='block';
setTimeout("webchatLogin()",2000);
}else {
getel('forpc').style.display='block';
}
}else{
getel('forpc').style.display='block';
}
</script>
</body>
</html>
3、手机号码登陆
手机号登陆接口函数:userLogin(mobilephone,password);
获取登陆验证码:http://c.anywifi.com/api/mobilephone?nasid=[NASID]&mobilephone=[MOBILEPHONE]&mac=[MAC]&ap=[AP]
(其中NASID、MOBILEPHONE、MAC、AP参数均可从表单或者查询字符串中获取)
使用手机号码作为账号登陆,上网用户需要填写 手机号码,通过请求获取手机号码验证密码,然后填入 验证密码 即可登陆(获取验证密码需要下行短信,注册账户默认赠送50条,可以通过平台账户购买短信,上网用户手机号码信息可以从后台浏览查看)
手机号码登陆:

示例代码:
<!doctype html>
<html>
<head>
<title>{title}</title>
<script src="http://s.anywifi.com/resources/anywifiLibrary.js"></script>
<script type="text/javascript">
//登陆按钮
function doLogin(){
userLogin(getel("phone").value,getel("code").value);
};
//获取短信验证密码
function getPhoneCode(){
var nasId = getQueryString('nasid');
var mac = getQueryString('mac');
var ap = getQueryString('called');
var mobilePhone = getel("phone").value;
if(/^1\d{10}$/g.test(mobilePhone)){
ajaxLoad("GET","http://"+adminDomain+"/api/mobilephone?nasid="+nasId+"&mobilephone="+mobilePhone+"&mac="+mac+"&ap="+ap+"&t="+Math.random(),function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
if(xmlhttp.responseText=="SUCCESS"){
alert('短信验证码已发送');
}else if(xmlhttp.responseText=="OVERLOAD"){
alert('短信发送中,请稍等...');
}else{
alert(xmlhttp.responseText);
}
}
});
}else{
alert('手机号码格式不正确');
getel("phone").value = '';
}
}
</script>
</head>
<body>
<div >
<input type="text" id="phone" placeholder="输入手机号" />
<button id="codeButton" onclick="getPhoneCode();" >获取验证码</button>
</div>
<div >
<input type="text" id="code" placeholder="输入验证码" />
<button id="accordion-longinBtn2" onclick="doLogin();" >登 录</button>
</div>
</body>
</html>


浙公网安备 33010602011771号