MediaTencent.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Created by KLXQ
  4. * user: youyi
  5. * Date:2024/6/25 14:09.
  6. * Tencent VOD SDK.
  7. * 目前主要用于点播平台文件删除.
  8. */
  9. namespace App\Http\Helpers\Tencent;
  10. use App\Services\TencentRequestService;
  11. use TencentCloud\Common\Credential;
  12. use TencentCloud\Common\Exception\TencentCloudSDKException;
  13. use TencentCloud\Common\Profile\ClientProfile;
  14. use TencentCloud\Common\Profile\HttpProfile;
  15. use TencentCloud\Vod\V20180717\VodClient;
  16. class MediaTencent
  17. {
  18. public string $secretId;
  19. public string $secretKey;
  20. public string $region;
  21. public string $endpoint = 'vod.tencentcloudapi.com';
  22. public object $client;
  23. public int $sdkAppId;
  24. public array $resultArr = ['code' => 200, 'msg' => 'success', 'data' => []];
  25. public function __construct($action, $params)
  26. {
  27. $this->secretId = config('tencent.tencent_cloud_secret_id');
  28. $this->secretKey = config('tencent.tencent_cloud_secret_key');
  29. $this->region = config('tencent.trtc.region');
  30. $this->sdkAppId = (int) config('tencent.trtc.app_id');
  31. try {
  32. $cred = new Credential($this->secretId, $this->secretKey);
  33. // 实例化一个http选项,可选的,没有特殊需求可以跳过
  34. $httpProfile = new HttpProfile();
  35. $httpProfile->setEndpoint($this->endpoint);
  36. // 实例化一个client选项,可选的,没有特殊需求可以跳过
  37. $clientProfile = new ClientProfile();
  38. $clientProfile->setHttpProfile($httpProfile);
  39. // 实例化要请求产品的client对象,clientProfile是可选的
  40. $this->client = new VodClient($cred, $this->region, $clientProfile);
  41. // 实例化一个请求对象,每个接口都会对应一个request对象
  42. $respClass = 'TencentCloud\\'.ucfirst('vod').'\\V20180717\\Models\\'.ucfirst($action).'Request';
  43. $req = new $respClass();
  44. $req->fromJsonString(json_encode($params));
  45. // 返回的resp是一个RemoveUserResponse的实例,与请求对象对应
  46. $resp = $this->client->{$action}($req);
  47. $this->resultArr['data'] = json_decode($resp->toJsonString(), true);
  48. } catch (TencentCloudSDKException $e) {
  49. $this->resultArr['code'] = -1;
  50. $this->resultArr['msg'] = $e->getMessage();
  51. }
  52. // 记录日志
  53. TencentRequestService::create('vod', $action, $params, $this->resultArr);
  54. }
  55. }