天天看點

phalapi架構實作騰訊雲直播混流

3.0版本的騰訊雲直播混流API使用

使用此文檔之前請確定是否安裝了composer,未安裝可參考文檔:https://blog.csdn.net/u014724048/article/details/106856686

1、引用騰訊雲擴充包内的autoload.php

include API_ROOT.'/../vendor/tencentcloud/tencentcloud-sdk-php/vendor/autoload.php';

use TencentCloud\Common\Credential;
use TencentCloud\Common\Profile\ClientProfile;
use TencentCloud\Common\Profile\HttpProfile;
use TencentCloud\Common\Exception\TencentCloudSDKException;
use TencentCloud\Live\V20180801\LiveClient;
use TencentCloud\Live\V20180801\Models\CreateCommonMixStreamRequest; 
           

2、騰訊雲直播混流API代碼如下:

try {
			$cred = new Credential($txcloud_secret_id, $txcloud_secret_key);
				
			$httpProfile = new HttpProfile();
			$httpProfile->setEndpoint("live.tencentcloudapi.com");
			
			$clientProfile = new ClientProfile();
			$clientProfile->setHttpProfile($httpProfile);
			$client = new LiveClient($cred, "ap-singapore", $clientProfile);

			$req = new CreateCommonMixStreamRequest();
			//$params=$mergeparams;//用戶端傳過來的json轉字元串的參數
			/*$stream1="1592545631_stream";
			$stream2="100036_1592549535";
            //測試參數格式如下
			$params = "{\"Action\":\"CreateCommonMixStream\",\"MixStreamSessionId\":\"".$stream1."\",\"InputStreamList\":[{\"InputStreamName\":\"".$stream1."\",\"LayoutParams\":{\"ImageLayer\":1,\"InputType\":0,\"ImageWidth\":750,\"ImageHeight\":1334,\"LocationX\":0,\"LocationY\":0}},{\"InputStreamName\":\"".$stream2."\",\"LayoutParams\":{\"ImageLayer\":2,\"ImageWidth\":100,\"ImageHeight\":200,\"LocationX\":0,\"LocationY\":0}}],\"OutputParams\":{\"OutputStreamName\":\"".$stream1."\"}}";
			*/
			$req->fromJsonString($params);
			
			$resp = $client->CreateCommonMixStream($req);
			if(!$resp){
				$rs['code']=1002;
				$rs['msg']="混流失敗,請重新開播";
				return $rs;
			}
			$result=$resp->toJsonString();
			if(!$result){
				$rs['code']=1002;
				$rs['msg']="混流失敗,請重新開播";
				return $rs;
			}
		}catch(TencentCloudSDKException $e){
			$rs['code']=1002;
			$rs['msg']="混流失敗,請重新開播";
			return $rs;
		}
           

以上騰訊雲混流API3.0代碼簡介完成;