doutun1875 2016-03-09 19:33
浏览 114
已采纳

在php中返回实例化的类... BigBluebutton

I am new to PHP and trying to a third party code namely Big blue button api https://github.com/bigbluebutton/bigbluebutton/tree/master/labs/bbb-api-php

I try to call BigBlueButton->createMeeting() function which looks like this :

public function createMeeting($createMeetingParams, $xml = '')
{
    $xml = $this->processXmlResponse($this
        ->getCreateMeetingURL($createMeetingParams), $xml);
    //$xml is fine
    return new CreateMeetingResponse($xml);
}

CreateMeetingResponse class

  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();
    }
}

BaseResponse class

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();
}

Now when I do call the BigBlueButton->createMeeting() function, I am expecting an object which I can encode to json ,But what I get is this (I have used print_r() here..):

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.
        )

)

I am not sure what is happening but I think the prefixed namespace 'BigBlueButton\Responses\CreateMeetingResponse Object' is the problem. I want to parse the response I get to an json object in php but cannot

Here is where I try to parse it

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

}
  • 写回答

1条回答 默认 最新

  • doumen5895 2016-03-09 19:47
    关注

    The return part looks right. The error you are getting is coming from BigBlueButton->createMeeting()

    You already have created a meeting with the ID you used. Are you generating a new Meeting ID to pass in with the XML when you create a new meeting?

    Edit:

    To be able to json_encode the response you will need to use the getRawXml() function since $rawXml is a protected property of the base class and the rest of the class is just methods. So:

    public function createMeeting($createMeetingParams, $xml = '')
    {
        $xml = $this->processXmlResponse($this
            ->getCreateMeetingURL($createMeetingParams), $xml);
        //$xml is fine
        $resp = new CreateMeetingResponse($xml);
        return $resp->getRawXml();
    }
    

    Should return just the SimpleXMLElement which you can then json_encode.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序