voip_json2sql_phoneConfigs.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. $unit_code = $argv[1];
  3. $api_key = $argv[2];
  4. processUnit($unit_code);
  5. function processUnit($unit_code) {
  6. global $api_key;
  7. static $unitId = 1;
  8. static $appointmentId = 1;
  9. if (empty($unit_code)) {
  10. return;
  11. }
  12. $unit = json_decode(file_get_contents('https://voip.mephi.ru/units/'.$unit_code.'.json?renderFilter=unit_selected&apiKey='.$api_key.'&effectiveSecurityLevel=1024'), 1)['unit_selected'];
  13. $phones = json_decode(file_get_contents('https://voip.mephi.ru/phones.json?phone.PinnedToUnitKey='.$unit_code.'&renderFilter=phones&apiKey='.$api_key.'&effectiveSecurityLevel=1024'), 1)['phones'];
  14. foreach ($phones as $phone) {
  15. if (empty($phone['Lines'])) {
  16. continue;
  17. }
  18. foreach ($phone['Lines'] as $line) {
  19. print "INSERT INTO `phone_configs` SET `phone_mac`='".$phone['Mac']."', `extension`='".$line['Extension']."', created_at=NOW(), updated_at=NOW();\n";
  20. }
  21. }
  22. if (isset($unit['Children'])) {
  23. foreach ($unit['Children'] as $child) {
  24. processUnit(str_replace($child['CodeStr'], " ", ""));
  25. }
  26. }
  27. }
  28. ?>