漏刻有时API接口实战开发系列,主要针对现有互联网和物联网接口的技术开发,使用js技术,采用ajax直接对接相关接口。(安全隐患:appKey和secret会直接暴露在前端HTML代码中,实际生产环境,使用后台语言如php获取即可)。
获取accessToken
$.ajax({ type: 'post', url: 'https://open.ys7.com/api/lapp/token/get', async: true, dataType: 'json', data: { appKey: 'bcb**', appSecret: 'a74**' }, success: function (res) { //console.log(res); $("#token").html(res.data.accessToken); //获取直播地址; getList(res.data.accessToken); //账号下流量消耗汇总; getTraffic(res.data.accessToken); }, error: function (err) { console.log("API call Failed: ", err); } });
获取直播接口
//直播地址相关接口 function getList(token) { $.ajax({ type: 'post', url: 'https://open.ys7.com/api/lapp/live/video/list', async: true, dataType: 'json', data: { accessToken: token, }, success: function (res) { //console.log(res.data[0]); $("#list").html(res.data[0].hdAddress); }, error: function (err) { console.log("API call Failed: ", err); } }); }
获取流量数据查询
//账号下流量消耗汇总 function getTraffic(token) { $.ajax({ type: 'post', url: 'https://open.ys7.com/api/lapp/traffic/user/total', async: true, dataType: 'json', data: { accessToken: token, }, success: function (res) { console.log(res); $("#traffic").html(res.data.usedFlow); }, error: function (err) { console.log("API call Failed: ", err); } }); }
Done!