首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >getAuthorization的callback函数具体怎么使用的呀?

getAuthorization的callback函数具体怎么使用的呀?

提问于 2020-03-18 19:58:01
回答 1关注 1查看 1.2K

请教,这个callback函数具体是啥意思呀,脑子在这怎么也转不过来了,受累解答,感谢~~~

代码语言:javascript
复制
var COS = require('cos-js-sdk-v5');
var cos = new COS({
    // 必选参数
    getAuthorization: function (options, callback) {
        // 服务端 JS 和 PHP 例子:https://github.com/tencentyun/cos-js-sdk-v5/blob/master/server/
        // 服务端其他语言参考 COS STS SDK :https://github.com/tencentyun/qcloud-cos-sts-sdk
        // STS 详细文档指引看:https://cloud.tencent.com/document/product/436/14048
        $.get('http://example.com/server/sts.php', {
            // 可从 options 取需要的参数
        }, function (data) {
            var credentials = data && data.credentials;
            if (!data || !credentials) return console.error('credentials invalid');
            callback({
                TmpSecretId: credentials.tmpSecretId,
                TmpSecretKey: credentials.tmpSecretKey,
                XCosSecurityToken: credentials.sessionToken,
                // 建议返回服务器时间作为签名的开始时间,避免用户浏览器本地时间偏差过大导致签名错误
                StartTime: data.startTime, // 时间戳,单位秒,如:1580000000
                ExpiredTime: data.expiredTime, // 时间戳,单位秒,如:1580000900
            });
        });
    }
});
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档