1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- /**
- * Created by KLXQ
- * user: youyi
- * Date:2024/6/25 14:09.
- * Tencent VOD SDK.
- * 目前主要用于点播平台文件删除.
- */
- namespace App\Http\Helpers\Tencent;
- use App\Services\TencentRequestService;
- use TencentCloud\Common\Credential;
- use TencentCloud\Common\Exception\TencentCloudSDKException;
- use TencentCloud\Common\Profile\ClientProfile;
- use TencentCloud\Common\Profile\HttpProfile;
- use TencentCloud\Vod\V20180717\VodClient;
- class MediaTencent
- {
- public string $secretId;
- public string $secretKey;
- public string $region;
- public string $endpoint = 'vod.tencentcloudapi.com';
- public object $client;
- public int $sdkAppId;
- public array $resultArr = ['code' => 200, 'msg' => 'success', 'data' => []];
- public function __construct($action, $params)
- {
- $this->secretId = config('tencent.tencent_cloud_secret_id');
- $this->secretKey = config('tencent.tencent_cloud_secret_key');
- $this->region = config('tencent.trtc.region');
- $this->sdkAppId = (int) config('tencent.trtc.app_id');
- try {
- $cred = new Credential($this->secretId, $this->secretKey);
- // 实例化一个http选项,可选的,没有特殊需求可以跳过
- $httpProfile = new HttpProfile();
- $httpProfile->setEndpoint($this->endpoint);
- // 实例化一个client选项,可选的,没有特殊需求可以跳过
- $clientProfile = new ClientProfile();
- $clientProfile->setHttpProfile($httpProfile);
- // 实例化要请求产品的client对象,clientProfile是可选的
- $this->client = new VodClient($cred, $this->region, $clientProfile);
- // 实例化一个请求对象,每个接口都会对应一个request对象
- $respClass = 'TencentCloud\\'.ucfirst('vod').'\\V20180717\\Models\\'.ucfirst($action).'Request';
- $req = new $respClass();
- $req->fromJsonString(json_encode($params));
- // 返回的resp是一个RemoveUserResponse的实例,与请求对象对应
- $resp = $this->client->{$action}($req);
- $this->resultArr['data'] = json_decode($resp->toJsonString(), true);
- } catch (TencentCloudSDKException $e) {
- $this->resultArr['code'] = -1;
- $this->resultArr['msg'] = $e->getMessage();
- }
- // 记录日志
- TencentRequestService::create('vod', $action, $params, $this->resultArr);
- }
- }
|