Advertisement
Guest User

StartExam

a guest
Sep 8th, 2015
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.60 KB | None | 0 0
  1.     function start_exam_auth($verb = 'GET', $canonical_path = '', $content_length = 0) {
  2.         $result = $this->start_exam_id . ":";
  3.         $StringToSign = strtoupper($verb) . ' ' . strtolower($canonical_path) . ' ' . str_replace('+0000','GMT',gmdate(DATE_RFC1123)) .' '. $content_length;
  4.         $hash = hash_hmac('sha256',  utf8_encode($StringToSign), $this->start_exam_secret_key, true);
  5.         $Signature = $result . base64_encode($hash);
  6.         return $Signature;
  7.     }
  8.  
  9.     function start_exam_register() {
  10.         $method = "POST";
  11.         $xml = '<?xml version="1.0" encoding="utf-16"?>
  12.                     <RegisterParticipantsQuery xmlns="https://api.startexam.com/v1/xml">
  13.                         <Center>at19629</Center>
  14.                         <ValidFrom>2015-01-16T00:00:00Z</ValidFrom>
  15.                         <ValidTill>2016-01-31T23:59:59Z</ValidTill>
  16.                         <Test>2eca1305-a99f-4f43-bdb9-ba93e5ca86af</Test>
  17.                         <Participant>
  18.                             <Data key="FirstName" value="John" />
  19.                             <Data key="LastName" value="Lennon" />
  20.                             <Data key="Email" value="lennon@gmail.com" />
  21.                             <Data key="f1094d46-fe61-49fc-89a7-d534e9a2c013" value="000000000" />
  22.                         </Participant>
  23.                         <Participant>
  24.                             <Data key="FirstName" value="Paul" />
  25.                             <Data key="LastName" value="McCartney" />
  26.                             <Data key="Email" value="paulmccartney@hotmail.com" />
  27.                             <Data key="f1094d46-fe61-49fc-89a7-d534e9a2c013" value="999999999" />
  28.                         </Participant>
  29.                     </RegisterParticipantsQuery>';
  30.         //----------------------
  31.         $opts = array(
  32.             'http' => array(
  33.                 'Method' => $method,
  34.                 'Header' => 'Authorization: SharedKey '.$this->start_exam_auth($method, '/v1/participants', strlen($xml)). "\r\n".
  35.                             'Accept: application/json; charset=utf-8'. "\r\n".
  36.                             'Content-Length: '.strlen($xml). "\r\n".
  37.                             'Date: '.str_replace('+0000','GMT',gmdate(DATE_RFC1123)). "\r\n".
  38.                             'Host: api.startexam.com',
  39.                 'Content' => $xml
  40.             )
  41.         );
  42.        
  43.         //print_r($opts);
  44.         //exit();
  45.         $context = stream_context_create($opts);
  46.         $result = file_get_contents("https://api.startexam.com/v1/participants", false, $context);
  47.         return $result;
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement