我是PHP的新手,正在尝试第三方代码,即蓝色大按钮api。https://github.com/bigbluebutton/bigbluebutton/tree/master/labs/bbb-api-php
我尝试调用BigBlueButton->createMeeting()
看起来像这样的函数:
public function createMeeting($createMeetingParams, $xml = '')
{
$xml = $this->processXmlResponse($this
->getCreateMeetingURL($createMeetingParams), $xml);
//$xml is fine
return new CreateMeetingResponse($xml);
}
创建会议响应类
namespace BigBlueButton'Responses;
/**
* Class CreateMeetingResponse
* @package BigBlueButton'Responses
*/
class CreateMeetingResponse extends BaseResponse
{
/**
* @return string
*/
public function getMeetingId()
{
return $this->rawXml->meetingID->__toString();
}
/**
* @return string
*/
public function getAttendeePassword()
{
return $this->rawXml->attendeePW->__toString();
}
/**
* @return string
*/
public function getModeratorPassword()
{
return $this->rawXml->moderatorPW->__toString();
}
/**
* Creation timestamp.
*
* @return double
*/
public function getCreationTime()
{
return doubleval($this->rawXml->createTime);
}
/**
* @return int
*/
public function getVoiceBridge()
{
return intval($this->rawXml->voiceBridge);
}
/**
* @return string
*/
public function getDialNumber()
{
return $this->rawXml->dialNumber->__toString();
}
/**
* Creation date at the format "Sun Jan 17 18:20:07 EST 2016".
*
* @return string
*/
public function getCreationDate()
{
return $this->rawXml->createDate->__toString();
}
/**
* @return true
*/
public function hasUserJoined()
{
return $this->rawXml->hasUserJoined->__toString() == 'true';
}
/**
* @return int
*/
public function getDuration()
{
return intval($this->rawXml->duration);
}
/**
* @return bool
*/
public function hasBeenForciblyEnded()
{
return $this->rawXml->hasBeenForciblyEnded->__toString() == 'true';
}
/**
* @return string
*/
public function getMessageKey()
{
return $this->rawXml->messageKey->__toString();
}
/**
* @return string
*/
public function getMessage()
{
$this->rawXml->message->__toString();
}
}
基本响应类
namespace BigBlueButton'Parameters;
/**
* Class BaseParameters.
*/
abstract class BaseParameters
{
/**
* @param $array
*
* @return string
*/
protected function buildHTTPQuery($array)
{
return http_build_query(array_filter($array));
}
/**
* @return string
*/
abstract public function getHTTPQuery();
}
现在当我调用 BigBlueButton->createMeeting()
函数时,我期待一个可以编码为 json 的对象,但我得到的是这个(我在这里使用了print_r()
..):
BigBlueButton'Responses'CreateMeetingResponse Object
(
[rawXml:protected] => SimpleXMLElement Object
(
[returncode] => FAILED
[messageKey] => idNotUnique
[message] => A meeting already exists with that meeting ID. Please use a different meeting ID.
)
)
我不确定发生了什么,但我认为前缀命名空间' BigBlueButton'Responses'CreateMeetingResponse Object
'是问题所在。我想解析我在 php 中得到的对 json 对象的响应,但不能
这是我尝试解析它的地方
function easymeet_create_meeting($id) {
// Create BBB object
$bbb = new BigBlueButton'BigBlueButton();
//creating meeting parameter
$meetingParas=new BigBlueButton'Parameters'CreateMeetingParameters('123456','sned');
//Creatign meeting
return json_encode($bbb->createMeeting($meetingParas));
///print_r($bbb->createMeeting($meetingParas)) give the xml response shown above
}
返回部分看起来正确。您收到的错误来自BigBlueButton->createMeeting()
您已经使用您使用的 ID 创建了会议。创建新会议时,是否生成新的会议 ID 以与 XML 一起传入?
编辑:
为了能够json_encode响应,您需要使用 getRawXml()
函数,因为$rawXml
是基类的受保护属性,类的其余部分只是方法。所以:
public function createMeeting($createMeetingParams, $xml = '')
{
$xml = $this->processXmlResponse($this
->getCreateMeetingURL($createMeetingParams), $xml);
//$xml is fine
$resp = new CreateMeetingResponse($xml);
return $resp->getRawXml();
}
应该只返回您可以json_encode的SimpleXMLElement
。