Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.28 KB | None | 0 0
  1. <?php
  2.  
  3. function wf_createAbonent($accountname, $parentId, $cf_918)
  4. {
  5.     $billingAPIAddr = 'http://185.108.208.71:8082/rest_api/v2';
  6.     $billingMethod = 'Abonents/';
  7.  
  8.     $arg1 = array(
  9.         'name' => $accountname,
  10.         'parent_id' => $parentId,
  11.         'contract_number' => $cf_918
  12.     );
  13.     $postData = array('method1' => 'objects.create', 'arg1' => json_encode($arg1));
  14.  
  15.     $curl = curl_init();
  16.  
  17.     curl_setopt($curl, CURLOPT_URL, $billingAPIAddr.'/'.$billingMethod);
  18.     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  19.     curl_setopt($curl, CURLOPT_POST, true);
  20.     curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($postData));
  21.  
  22.     $preRes = curl_exec($curl);
  23.     $res = json_decode($preRes, true);
  24.  
  25.     curl_close($curl);
  26.  
  27.     if (!empty($res['error']) && empty($res['result']['pk'])) {
  28.         return false;
  29.     }
  30.  
  31.     return $res;
  32. }
  33.  
  34. function wf_createUser($pk, $cf_918)
  35. {
  36.     $billingAPIAddr = 'http://185.108.208.71:8082/rest_api/v2';
  37.     $billingMethod = 'Users/';
  38.  
  39.     $arg1 = array(
  40.         'abonent_id' => $pk,
  41.         'login' => (int)$cf_918
  42.     );
  43.     $postData = array('method1' => 'objects.create', 'arg1' => json_encode($arg1));
  44.  
  45.     $curl = curl_init();
  46.  
  47.     curl_setopt($curl, CURLOPT_URL, $billingAPIAddr.'/'.$billingMethod);
  48.     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  49.     curl_setopt($curl, CURLOPT_POST, true);
  50.     curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($postData));
  51.  
  52.     $preRes = curl_exec($curl);
  53.     $res = json_decode($preRes, true);
  54.  
  55.     curl_close($curl);
  56.  
  57.     if (!empty($res['error'])) {
  58.         return false;
  59.     }
  60.  
  61.     return $res;
  62. }
  63.  
  64. function wf_getAbonentPK($contract_number)
  65. {
  66.     $billingAPIAddr = 'http://185.108.208.71:8082/rest_api/v2';
  67.     $billingMethod = 'Abonents/';
  68.  
  69.     $arg1 = array(
  70.         'contract_number' => $contract_number
  71.     );
  72.     $fields = array('pk');
  73.     $postData = array('method1' => 'objects.get', 'arg1' => json_encode($arg1), 'fields' => json_encode($fields));
  74.  
  75.     $curl = curl_init();
  76.  
  77.     curl_setopt($curl, CURLOPT_URL, $billingAPIAddr.'/'.$billingMethod);
  78.     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  79.     curl_setopt($curl, CURLOPT_POST, true);
  80.     curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($postData));
  81.  
  82.     $preRes = curl_exec($curl);
  83.     $res = json_decode($preRes, true);
  84.  
  85.     curl_close($curl);
  86.  
  87.     if (!empty($res['error'])) {
  88.         return false;
  89.     }
  90.  
  91.     return $res['result']['pk'];
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement