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.

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

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?