PHP Sample Code
Integrate WizIQ Virtual Classroom API with your website and make it a complete ‘online teaching website’
WizIQ’s Virtual Classroom is 100% browser-based. You can make your website an online tutoring/teaching website and anyone can access the Virtual Classroom instantly, and without having to download software or host server. Let your teachers focus on delivering classes and helping students, with the help of WizIQ’s wide range of tools.
I edited the below codes using WizIQ’s source code. It is compatible with WizIQ NextGen / WizIQxt.
This example only includes the “create” method. You can create other methods using these files.
authbase.php
<?php
#This file is part of Wiziq - http://www.wiziq.com/
#Edited by Şevket Polan
set_time_limit(0);
class wiziq_authbase {
# This function defines the secret access key and access key.
# @param string $wiziq_secretaccesskey
# @param string $wiziq_access_key
public function __construct($wiziq_secretaccesskey, $wiziq_access_key) {
$this->wiziq_secretaccesskey=$wiziq_secretaccesskey;
$this->wiziq_access_key=$wiziq_access_key;
}
/**
* This function generates the timestamp.
*
* @return integer time.
*/
public function wiziq_generatetimestamp() {
return time();
}
/**
* This function generates the signature in order to send a http request.
*
* @param string $methodname name of the method.
* @param string $requestparameters parameters that are required for http request.
*
* @return string
*/
public function wiziq_generatesignature($methodname, &$requestparameters) {
$signaturebase="";
$wiziq_secretaccesskey = urlencode($this->wiziq_secretaccesskey);
$requestparameters["access_key"] = $this->wiziq_access_key;
$requestparameters["timestamp"] =$this->wiziq_generatetimestamp();
$requestparameters["method"] = $methodname;
foreach ($requestparameters as $key => $value) {
$signaturebaselenght = strlen($signaturebase);
if ($signaturebaselenght > 0) {
$signaturebase.="&";
}
$signaturebase.="$key=$value";
}
return base64_encode($this->wiziq_hmacsha1($wiziq_secretaccesskey, $signaturebase));
}
/**
* This function generates the hash based message authentication code(hmac)
* using cryptographic hash function sha1.
*
* @param string $key cryptographic key.
* @param string $data the data which will be appended.
*
* @return string $hmac
*/
public function wiziq_hmacsha1($key, $data) {
$blocksize=64;
$hashfunc='sha1';
$keylenght = strlen($key);
if ($keylenght > $blocksize) {
$key=pack('H*', $hashfunc($key));
}
$key=str_pad($key, $blocksize, chr(0x00));
$ipad=str_repeat(chr(0x36), $blocksize);
$opad=str_repeat(chr(0x5c), $blocksize);
$hmac = pack(
'H*', $hashfunc(
($key^$opad).pack(
'H*', $hashfunc(
($key^$ipad).$data
)
)
)
);
return $hmac;
}
}//end class wiziq_authbase
class wiziq_httprequest {
/**
* This function generates a http request using curl.
*
* @param string $url this is wiziq url to which request is to be send.
* @param array $data which contains the request paramters.
* @param string $optional_headers
*
* @return string $response.
*/
public function wiziq_do_post_request($url, $data, $optional_headers = null) {
try {
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch,CURLOPT_POSTFIELDS, $data);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
return $result;
} catch (Exception $e) {
$errorexecption = $e->getMessage();
$errormsg = get_string('errorinservice', 'wiziq'). " " . $errorexecption;
print_error($errormsg);
}
}
}//end class wiziq_httprequest
create.php
<?php
class ScheduleClass
{
public function __construct($secretAccessKey,$access_key,$webServiceUrl)
{
require_once("authbase.php");
$authBase = new wiziq_authbase($secretAccessKey,$access_key);
$method = "create";
$requestParameters["signature"]=$authBase->wiziq_generatesignature($method,$requestParameters);
#for teacher account pass parameter 'presenter_email'
//This is the unique email of the presenter that will identify the presenter in WizIQ. Make sure to add
//this presenter email to your organization's teacher account.For more information visit at: (http://developer.wiziq.com/faqs)
$requestParameters["presenter_email"]="[email protected]";
#for room based account pass parameters 'presenter_id', 'presenter_name'
//$requestParameters["presenter_id"] = "40";
//$requestParameters["presenter_name"] = "sevketpolan";
$requestParameters["start_time"] = "12/08/2019 16:00";
$requestParameters["title"]="my php-class 2"; //Required
$requestParameters["duration"]="30"; //optional
$requestParameters["time_zone"]="Europe/Istanbul"; //optional
$requestParameters["attendee_limit"]=""; //optional
$requestParameters["control_category_id"]=""; //optional
$requestParameters["create_recording"]=""; //optional
$requestParameters["return_url"]=""; //optional
$requestParameters["status_ping_url"]=""; //optional
$requestParameters["language_culture_name"]="tr-TR";
$httpRequest=new wiziq_httprequest();
try
{
$XMLReturn=$httpRequest->wiziq_do_post_request($webServiceUrl.'?method=create',http_build_query($requestParameters, '', '&'));
}
catch(Exception $e)
{
echo $e->getMessage();
}
if(!empty($XMLReturn))
{
try
{
$objDOM = new DOMDocument();
$objDOM->loadXML($XMLReturn);
}
catch(Exception $e)
{
echo $e->getMessage();
}
$status=$objDOM->getElementsByTagName("rsp")->item(0);
$attribNode = $status->getAttribute("status");
if($attribNode=="ok")
{
$methodTag=$objDOM->getElementsByTagName("method");
echo "method=".$method=$methodTag->item(0)->nodeValue;
$class_idTag=$objDOM->getElementsByTagName("class_id");
echo "<br>Class ID=".$class_id=$class_idTag->item(0)->nodeValue;
$recording_urlTag=$objDOM->getElementsByTagName("recording_url");
echo "<br>recording_url=".$recording_url=$recording_urlTag->item(0)->nodeValue;
$presenter_emailTag=$objDOM->getElementsByTagName("presenter_email");
echo "<br>presenter_email=".$presenter_email=$presenter_emailTag->item(0)->nodeValue;
$presenter_urlTag=$objDOM->getElementsByTagName("presenter_url");
echo "<br>presenter_url=".$presenter_url=$presenter_urlTag->item(0)->nodeValue;
}
else if($attribNode=="fail")
{
$error=$objDOM->getElementsByTagName("error")->item(0);
echo "<br>errorcode=".$errorcode = $error->getAttribute("code");
echo "<br>errormsg=".$errormsg = $error->getAttribute("msg");
}
}//end if
}//end function
}
?>
wiziqservice.php
Add your Access Key and Secret Access Key
<?php
$access_key="<<YOUR ACCESS KEY>>";
$secretAccessKey="<<YOUR SECRET ACCESS KEY>>";
$webServiceUrl="http://classapi.wiziqxt.com/apimanager.ashx";
require_once("create.php");
$obj=new ScheduleClass($secretAccessKey,$access_key,$webServiceUrl);
//require_once("ModifyClass.php");
//$obj=new ModifyClass($secretAccessKey,$access_key,$webServiceUrl);
//require_once("AddAttendee.php");
//$obj=new AddAttendee($secretAccessKey,$access_key,$webServiceUrl);
//require_once("CancelClass.php");
//$obj=new CancelClass($secretAccessKey,$access_key,$webServiceUrl);
//require_once("DownloadRecording.php");
/*$obj = new DownloadRecording($secretAccessKey, $access_key, $webServiceUrl);
In the above download recording output xml there is a <status_xml_path> i.e. http://wiziq.com/download/1234.xml
this xml would contain all the necessary status for the recording download
e.g -:
<rsp status='ok'>
<method>download_recording</method>
<download_recording status='true'>
<download_status>false</download_status>
<message>Download Recording has been started..</message>
<recording_download_path>http://wiziq.com/download/recording_9195.exe</recording_download_path>
</download_recording>
</rsp>
Actual recording file path will be the value of node <recording_download_path> obtained by requesting above xml
*/
?>
To download files;
https://github.com/sevketpolan/wiziq-php-api