首先,安装express框架,目的,使用express框架请求,方便快捷

参考 https://www.npmjs.com/package/express

创建 index.js

const express = require('express')
const app = express()
const txSdk = require('./txsdk')

app.get('/getTxMediaInfo', function (req, res) {
    txSdk.getTxMediaInfo(req.query.videoid, function (result) {
        res.send(result)
    })
})

app.listen(81)

txsdk.js

const secretId="";
const secretKey="";
const region="ap-beijing";
const tencentcloud = require("tencentcloud-sdk-nodejs");

// 导入对应产品模块的client models。
const VodClient = tencentcloud.vod.v20180717.Client
const clientConfig = {
// 腾讯云认证信息
    credential: {
        secretId: secretId,
        secretKey: secretKey,
    },
// 产品地域
    region: region,
// 可选配置实例
    profile: {
        signMethod: "HmacSHA256", // 签名方法
        httpProfile: {
            reqMethod: "POST", // 请求方法
            reqTimeout: 30, // 请求超时时间,默认60s
        },
    },
}
// 实例化要请求产品(以cvm为例)的client对象
const client = new VodClient(clientConfig)
// 通过client对象调用想要访问的接口,需要传入请求对象以及响应回调函数

/**
 * 获取媒体详细信息
 * @param videoId
 */
const getTxMediaInfo = function (videoId,callback) {
    client.DescribeMediaInfos({
        FileIds: [videoId]
    }, function (err, response) {
        if (err) {
            // console.error("error", err)
            callback(response)
        } else {
            // console.log(response)
            callback(response)
        }
    })
}

module.exports = {
    getTxMediaInfo
}

访问域名:81/getTxMediaInfo?videoid=

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐