这是我获取 api 的代码
$apiurl = "https://class.cvcngr.in/bigbluebutton/api/create?allowStartStopRecording=true&attendeePW=ap&autoStartRecording=false&meetingID=random-1495797&moderatorPW=mp&name=random-1495797&record=false&voiceBridge=74999&welcome=%3Cbr%3EWelcome+to+%3Cb%3E%25%25CONFNAME%25%25%3C%2Fb%3E%21&checksum=ad1f82091f78ee18673f9c5be36df9eef7860187";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $apiurl);
$response = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($response);
echo $xml;
在上面,我使用了一个存储API网址的apiurl。 这是我的自定义 API,服务提供商提供了一个测试 API
$apiurl2 "http://test-install.blindsidenetworks.com/bigbluebutton/api/create?allowStartStopRecording=true&attendeePW=ap&autoStartRecording=false&meetingID=random-9370670&moderatorPW=mp&name=random-9370670&record=false&voiceBridge=79891&welcome=%3Cbr%3EWelcome+to+%3Cb%3E%25%25CONFNAME%25%25%3C%2Fb%3E%21&checksum=0aae50d2d079fd67138a7b266837f6b0112166b5";
Bothe URL 给出了相同的响应,但我只能在使用 apiurl2 时获取数据。 当我使用第一个时,没有响应。 但是当我直接在浏览器中使用时,没有问题
它工作得很好,$xml
变量是一个 SimpleXMLElement 实例。echo
尝试打印字符串。您可以使用var_dump($xml)
打印其所有内容,并使用对象运算符直接访问其元素:echo $xml->dialNumber
甚至循环遍历它们:
<?php
$apiurl = "https://class.cvcngr.in/bigbluebutton/api/create?allowStartStopRecording=true&attendeePW=ap&autoStartRecording=false&meetingID=random-1495797&moderatorPW=mp&name=random-1495797&record=false&voiceBridge=74999&welcome=%3Cbr%3EWelcome+to+%3Cb%3E%25%25CONFNAME%25%25%3C%2Fb%3E%21&checksum=ad1f82091f78ee18673f9c5be36df9eef7860187";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $apiurl);
$response = curl_exec($ch);
$xml = simplexml_load_string($response);
// var_dump($xml);
// echo 'Dial number: ' . $xml->dialNumber;
foreach ($xml as $key => $value) {
echo "{$key}: {$value}n";
}
curl_close($ch);