PHP 创建腾讯视频会议

php创建视频会议,方便后台操作,发送通知和保存相关人员,比如发送到相关人员手机上

curl 有问题 会提示错误{"error_info":{"error_code":400,"message":"Missing required http header 'AppId'"}}

 

 true,
		"allow_unmute_self" => false,
		"mute_all" => false,
		"host_video" => true,
		"participant_video" => false,
		"enable_record" => false,
		"play_ivr_on_leave" => false,
		"play_ivr_on_join" => false,
		"live_url" => false
	];
	$param = [
		'userid' => 'aaxxxxxx',
		'instanceid' => 1,
		'subject' => "testermeeting",
        'type' => 0,
		'hosts'=>array(array('userid'=>'aaxxxxxx','is_anonymous'=>false,'nick_name'=>"Master")),
		'start_time' => (string) ($time + 60),
		'end_time' =>(string)(strtotime($expires)),
		'password'=>"111111",
		'settings' => $settines,
	];
	$signature = $this->qcloud_eip_sign($url,$time, $nonce, $param);
	// 公共参数
	$header = [
		"X-TC-Key:{$this->SecretId}",
		"X-TC-Timestamp:{$time}",
		"X-TC-Nonce:{$nonce}",
        "X-TC-Signature:{$signature}",
		"AppId:{$this->APPID}", 
		"SdkId:{$this->SdkId}",
		"Content-Type:application/json"
	];
	echo $this->socket_post($url,$param,$header);

}
//使用fsockopen模拟 不用curl
public function socket_post($url, $post,$header=array()) {
	$urls = parse_url($url);
	if (!isset($urls['port'])) {
		$urls['port'] = 80;
	}

	$fp = fsockopen("ssl://".$urls['host'],443, $errno, $errstr);
	if (!$fp) {
		echo "$errno, $errstr";
		exit();
	}

	$post =json_encode($post);
	$length = strlen($post);

	$headerstr="";
	//把header信息组装起来
	foreach($header as $k=>$v){
		$headerstr.=$v."\r\n";
	}	
	$header = "POST ".$urls['path']." HTTP/1.1\r\nHOST: ".$urls['host']."\r\n".$headerstr."Content-Length: ".$length."\r\nConnection: close\r\n\r\n".$post;
	fwrite($fp, $header);
	$result = '';
	while (!feof($fp)) {
		$result .= fread($fp, 512);
	}
	$result = explode("\r\n\r\n", $result, 2);//取内容部分
	return $result[1];
}
// SecretKey sha256签名
public function qcloud_eip_sign( $url = 'https://api.meeting.qq.com/v1/meetings',$time = '', $nonce = '', $param = array()){
	$urls = parse_url($url);
	$headerString = "X-TC-Key=".$this->SecretId."&X-TC-Nonce=".$nonce."&X-TC-Timestamp=".$time;
	$httpString = "POST\n".$headerString."\n".$urls['path']."\n".json_encode($param);
	$signature = base64_encode(hash_hmac("sha256", $httpString, $this->SecretKey));
	return $signature;
}


}

$http=new huiyi();
$http->create_meeting();

 

你可能感兴趣的:(php)