您当前的位置: 首页 >  http

漏刻有时

暂无认证

  • 0浏览

    0关注

    717博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

漏刻有时API接口实战开发系列(1):萤石云HTTP接口API开发获取直播接口和流量数据查询(ajax)

漏刻有时 发布时间:2020-09-19 09:57:05 ,浏览量:0

漏刻有时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!

关注
打赏
1661217259
查看更多评论
立即登录/注册

微信扫码登录

0.0530s