随机腾讯云 COS 视频接口

不废话,直接开始教程,去腾讯云注册账号(󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮有账号的直接跳过)开通 COS,购买标准存储容量󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮󠄮,和外网下行󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮流量,设置好防盗刷。

SDK

下载腾讯云 COS SDK 在创建一个文件夹(建议把 SDK 下载到文件夹内),然后宝塔侧边栏打开终端 cd 这个文件夹,输入下面命令。

composer require qcloud/cos-sdk-v5

代码

配置修改:

   –󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮; 替换 `yo󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮ur-b󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮ucket-name` 为你的 COS 存储桶名称

   – 替换 `a󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮p-beijing` 为你的存储桶所在区域

   – 替换 `your-secret-id` 和 `you󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮r-secret-key` 为你的腾讯云 API 密钥

   – 修改 `󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮videos/` 为你的视频文件夹路径󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮

密钥怎么获取,鼠标󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮󠅒󠅢󠄟󠄮放到头像上>访问管理>访问密钥>API 密钥管理

<?php
require 'vendor/autoload.php';

use Qcloud\Cos\Client;

class RandomVideoController {
    private $cosClient;
    private $bucket;
    private $folder;
    private $cosRegion; // 存储桶地区
    
    public function __construct() {
        $this->bucket = 'your-bucket-name';
        $this->folder = 'videos/';
        $this->cosRegion = 'ap-beijing'; // 如 ap-shanghai、ap-guangzhou
        
        $this->cosClient = new Client([
            'region' => $this->cosRegion,
            'schema' => 'https',
            'credentials' => [
                'secretId' => 'your-secret-id',
                'secretKey' => 'your-secret-key',
            ],
        ]);
    }
    
    public function getRandomVideo(): array {
        try {
            $result = $this->cosClient->listObjects([
                'Bucket' => $this->bucket,
                'Prefix' => $this->folder,
            ]);
            
            $videoFiles = $this->filterVideoFiles($result['Contents'] ?? []);
            
            if (empty($videoFiles)) {
                return [
                    'code' => 404,
                    'message' => 'No video files found',
                    'data' => null
                ];
            }
            
            $randomVideo = $videoFiles[array_rand($videoFiles)];
            
            // 直接生成公有读 URL(无需预签名)
            $videoUrl = sprintf(
                "https://%s.cos.%s.myqcloud.com/%s",
                $this->bucket,
                $this->cosRegion,
                $randomVideo['Key']
            );
            
            return [
                'code' => 200,
                'message' => 'Success',
                'data' => [
                    'video_url' => $videoUrl,
                    'video_name' => basename($randomVideo['Key']),
                    'size' => $randomVideo['Size'],
                    'last_modified' => $randomVideo['LastModified'],
                ]
            ];
            
        } catch (\Exception $e) {
            return [
                'code' => 500,
                'message' => 'Error: ' . $e->getMessage(),
                'data' => null
            ];
        }
    }
    
    private function filterVideoFiles(array $files): array {
        $videoExtensions = ['mp4', 'mov', 'avi', 'mkv', 'flv', 'wmv'];
        return array_filter($files, function($file) use ($videoExtensions) {
            if (rtrim($file['Key'], '/') === rtrim($this->folder, '/')) {
                return false;
            }
            $extension = strtolower(pathinfo($file['Key'], PATHINFO_EXTENSION));
            return in_array($extension, $videoExtensions);
        });
    }
}

// 输出 JSON
header('Content-Type: application/json');
$controller = new RandomVideoController();
echo json_encode($controller->getRandomVideo(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);

代码输出为 Json 格式

{
    "code": 200,
    "message": "Success",
    "data": {
        "video_url": "视频链接",
        "video_name": "文件名称.mp4",
        "size": "1613168",
        "last_modified": "时间"
    }
}

 

 󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠄐󠄹󠅀󠄪󠄣󠄞󠄡󠄤󠄤󠄞󠄤󠄧󠄞󠄡󠄩󠄢󠄬󠅒󠅢󠄟󠄮󠄐󠅅󠄹󠄴󠄪󠄾󠅟󠅤󠄐󠄼󠅟󠅗󠅙󠅞󠄬󠅒󠅢󠄟󠄮󠅄󠅙󠅝󠅕󠄪󠄡󠄧󠄤󠄥󠄡󠄨󠄦󠄧󠄩󠄦󠄬󠅒󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮󠅢󠄟󠄮󠇕󠅸󠆍󠇗󠆖󠆫󠇕󠅽󠆊󠇕󠆞󠆒󠄐󠇗󠅹󠅸󠇖󠆍󠅳󠇖󠅹󠅰󠇖󠆌󠅹󠄬󠅒󠅢󠄟󠄮

请登录后发表评论