由于瀏覽器的安全限制的成都越來越高,尤其是設計到跨域的資料呼叫問題,限制要求也是越來越嚴格,而EasyNVR作為能力層,需要進行介面的呼叫,因此在呼叫介面進行token驗證往往也是存在很多不方便的地方,

針對這些問題,EasyNVR在新的4.1.0版之后(包含4.1.0版本)也同步兼容了get進行token驗證的方法,就是將登錄獲取到的token值在后續需要用到的介面可以通過get傳值的方式進行介面傳遞從而達到介面的呼叫,
前端代碼實作:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>EasyNVR</title>
</head>
<body>
<h5>DEMO</h5>
<input type="button" value="登錄" id="login" />
<input type="button" value="退出" id="loginout" />
<input type="button" value="獲取通道" id="modify" />
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.js"></script>
<h6>回傳資料展示<h6>
<input type="text" name="userName" style="height: 400px;width: 1000px;" id="text">
</body>
<script type="text/javascript">
var token
$(function () {
$("#login").click(function () { //登錄
$.ajax({
type: "GET",
Url:"http://127.0.0.1:10800/api/v1/login?username=easynvr&&password=ec6206d95f5772323792621ad25ffedf",
success: function(data) {
token=data.EasyDarwin.Body.Token
console.log(data.EasyDarwin.Body.Token);
}
});
});
$("#loginout").click(function () { //退出
$.ajax({
type:"Get",
url:"http://127.0.0.1:10800/api/v1/logout",
success: function (data) {
console.log(data);
}
})
});
$("#modify").click(function () {
$.ajax({
type:"Get",
url:"http://127.0.0.1:10800/api/v1/getchannelsconfig?token="+token,
success: function (data) {
console.log(data);
}
})
});
})
</script>
</html>
示例:
DEMO

轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/215945.html
標籤:其他
上一篇:時序約束(二)
