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代码简介完成;

猜你喜欢

转载自blog.csdn.net/u014724048/article/details/106857912