Advertisement
geirby

tochka_api_example

Oct 15th, 2021
990
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.60 KB | None | 0 0
  1.     /**
  2.      * @param houses $accountId
  3.      * @param $access_token
  4.      * @return mixed
  5.      */
  6.     protected function getTochkaAccountId($access_token, $accountId, $dateArr = [])
  7.     {
  8.         if(count($dateArr) == 0) {
  9.             $dateArr['start_date'] = '2014-01-01T00:00:00+03:00';
  10.             $dateArr['end_date'] = '2020-12-01T00:00:00+03:00';
  11.         }
  12.         $ch = curl_init();
  13.  
  14.         curl_setopt($ch, CURLOPT_URL, "https://api.tochka.com/ws/do/R0100");
  15.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  16.         curl_setopt($ch, CURLOPT_HEADER, FALSE);
  17.  
  18.         curl_setopt($ch, CURLOPT_POST, TRUE);
  19.  
  20.         curl_setopt($ch, CURLOPT_POSTFIELDS, "<message_v1 xmlns=\"http://www.anr.ru/types\" type=\"request\">
  21.        <data trn_code=\"R0100\">
  22.        <statement_request_v1 xmlns=\"http://www.anr.ru/types\"
  23.            account_id=\"" . $accountId . "\"
  24.            account_bic=\"000000000\"
  25.            start_date=\"" . $dateArr['start_date'] . "\"
  26.            end_date=\"" . $dateArr['end_date'] . "\"></statement_request_v1>
  27.        </data>
  28.        </message_v1>");
  29.  
  30.         curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  31.             "Content-Type: application/xml",
  32.             "Authorization: Bearer " . $access_token,
  33.             "Accept: application/xml;"
  34.         ));
  35.  
  36.         $response = curl_exec($ch);
  37.         curl_close($ch);
  38.         $xmlTochkaId = new \SimpleXMLElement($response);
  39.         foreach ($xmlTochkaId->attributes() as $nameAttr => $valAttr) {
  40.             if ((string) $nameAttr == 'int_id') {
  41.                 $int_id = (string) $valAttr;
  42.             }
  43.         }
  44.         return $int_id;
  45.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement