api_addwork.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. //$key = '6a7bdbaa-6bc1-4159-a2f4-07a13c8907d1';
  3. //$url = '62.141.88.61:8085/Thingworx/Things/connSmoppLibrary/Services/get_employee_status';
  4. $url = $_SERVER['SERVER_NAME'].'/api/service/addwork';
  5. $key = '07a13c8907d1-6a7bdba1-a2fz-aatgu4j';
  6. //$jsonEncoded = json_encode('dateTime='.milliseconds().'&kind=3&diagnosticCard=true&subnumber=23456787&number=34&series=2');
  7. $jsonEncoded = json_encode(['dateTime' => milliseconds(), 'kind'=> 3, 'diagnosticCard' => '123e4567-e89b-12d3-a456-426655440000', 'subnumber' => '23456787', 'number'=> '34', 'series'=> '2']);
  8. $curl = curl_init();
  9. curl_setopt($curl, CURLOPT_URL, $url);
  10. curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Accept: application/json","appKey: " . $key));
  11. curl_setopt($curl, CURLOPT_TIMEOUT, 20);
  12. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  13. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  14. curl_setopt($curl, CURLOPT_POST, 1);
  15. curl_setopt($curl, CURLOPT_POSTFIELDS, $jsonEncoded);
  16. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  17. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  18. $result = curl_exec($curl);
  19. //$info = curl_getinfo($curl, CURLINFO_HEADER_OUT);
  20. //$result = json_decode($result,true);
  21. echo $result;
  22. curl_close($curl);
  23. function milliseconds()
  24. {
  25. $mt = explode(' ', microtime());
  26. return ((int)$mt[1]) * 1000 + ((int)round($mt[0] * 1000));
  27. }
  28. //echo "<pre>";var_dump($result); echo "</pre>";
  29. ?>