mr_therabbit

Untitled

Dec 1st, 2014
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 22.00 KB | None | 0 0
  1. <?
  2.  
  3. /**
  4.  * TB
  5.  * Класс по работе TWO
  6.  *
  7.  * @package
  8.  * @author TheRabbit
  9.  * @copyright 2013
  10.  * @version $Id$
  11.  * @access public
  12.  */
  13. class TB {
  14.     // Параметры подключения к сервису
  15.     private $serviceHost;
  16.     private $servicePort;
  17.     private $masterKey;
  18.     public $dataNamespace;
  19.     public $soapNamespace;
  20.  
  21.    // Объекты сеанса
  22.     protected $debug = 0;
  23.  
  24.     // Параметры сеанса
  25.     private $PAN;
  26.     private $keyId;
  27.     private $STAN;
  28.     private $PIN;
  29.     private $dynamicPassword;
  30.     private $prevTranId;
  31.     private $personId;
  32.     private $personName;
  33.     private $textLogin;
  34.     private $extraAuthLevel;
  35.     private $lastLogon;
  36.     private $birthDay;
  37.     private $WorkKey;
  38.     private $responseCode;
  39.  
  40.    
  41.     /**
  42.      * TB::__construct()
  43.      * Конструктор сессии телебанка.
  44.      *
  45.      * @return void
  46.      */
  47.     public function __construct() {
  48.         $arrT = Config::get('vtbi');
  49.         $this->serviceHost = Config::get('vtbi.host');
  50.         $this->servicePort = Config::get('vtbi.port');
  51.         $this->masterKey = $arrT['masterKey'];
  52.         $this->dataNamespace = Config::get('vtbi.xmlns');
  53.         $this->soapNamespace = Config::get('vtbi.wsdl');
  54.    
  55.         // Начальное значени параметров сеанса
  56.         /*$this->PAN = null;
  57.         $this->keyId = 0;
  58.         $this->STAN = 0;
  59.         $this->PIN = null;
  60.         $this->dynamicPassword = null;
  61.         $this->prevTranId = null;
  62.         $this->personId = null;
  63.         $this->textLogin = null;
  64.         $this->personName = null;
  65.         $this->lastLogon = null;
  66.         $this->birthDay = null;
  67.         $this->extraAuthLevel = 0;
  68.         $this->responseCode = 0;*/
  69.        
  70.         // Получим данные из сессии и установим начальные значения
  71.         $this->getKey2Session('PAN', null);
  72.         $this->getKey2Session('keyId', 0);
  73.         $this->getKey2Session('STAN', 0);
  74.         $this->getKey2Session('PIN', null);
  75.         $this->getKey2Session('dynamicPassword', null);
  76.         $this->getKey2Session('prevTranId', null);
  77.         $this->getKey2Session('personId', null);
  78.         $this->getKey2Session('textLogin', null);
  79.         $this->getKey2Session('personName', null);
  80.         $this->getKey2Session('lastLogon', null);
  81.         $this->getKey2Session('birthDay', null);
  82.         $this->getKey2Session('extraAuthLevel', 0);
  83.         $this->getKey2Session('responseCode', 0);
  84.     }//\\ __construct
  85.  
  86.     /**
  87.      * Запрос имени клиента
  88.      * @return имя клиента
  89.      */
  90.     public function getPersonName() {
  91.         return $this->personName;
  92.     }//\\ getPersonName
  93.  
  94.     /**
  95.      * Запрос карты телебанк-пользователя
  96.      * @return
  97.      */
  98.     public function getPAN() {
  99.         return $this->PAN;
  100.     }//\\ getPAN
  101.    
  102.     /**
  103.      * Запрос динамического пароля
  104.      * @return
  105.      */
  106.     public function getDynamicPassword() {
  107.         return $this->dynamicPassword;
  108.     }//\\ getDynamicPassword
  109.    
  110.     /**
  111.      * Установка динамического пароля
  112.      * @param value
  113.      */
  114.     public function setDynamicPassword($value) {
  115.         $this->dynamicPassword = $value;
  116.     }//\\ setDynamicPassword
  117.    
  118.     /**
  119.      * Запрос пердыдущей транзакции по динамаческому паролю
  120.      * @return
  121.      */
  122.     public function getPrevTranId() {
  123.         return $this->prevTranId;
  124.     }//\\ getPrevTranId
  125.    
  126.     /**
  127.      * Установка динамического пароля
  128.      * @param value
  129.      */
  130.     public function setPrevTranId($value) {
  131.         $this->prevTranId = $value;
  132.     }//\\ setPrevTranId
  133.    
  134.     /**
  135.      * Запрос идентификатора клиента
  136.      * @return идентификатор клиента
  137.      */
  138.     public function getPersonId() {
  139.         return $this->personId;
  140.     }//\\ getPersonId
  141.    
  142.     /**
  143.      * Вернуть последний вход в систему
  144.      * @return
  145.      */
  146.     public function getLastLogon() {
  147.         return $this->lastLogon;
  148.     }//\\ getLastLogon
  149.    
  150.     /**
  151.      * Вернуть день рождения
  152.      * @return
  153.      */
  154.     public function getBirthDay() {
  155.         return $this->birthDay;
  156.     }//\\ getBirthDay
  157.    
  158.     /**
  159.      * Запрос текстового логина
  160.      * @return текстовый логин
  161.      */
  162.     public function getTextLogin() {
  163.         return $this->textLogin;
  164.     }//\\ getTextLogin
  165.    
  166.     /**
  167.      * Получить уровень дополнительной авторизации
  168.      * @return
  169.      */
  170.     public function getExtraAuthLevel() {
  171.         return $this->extraAuthLevel;
  172.     }//\\ getExtraAuthLevel
  173.  
  174.  
  175.  
  176.  
  177.  
  178.     /**
  179.      * TB::exec()
  180.      * Вызов метода интерфейса VTBI.
  181.      *
  182.      * @return string
  183.      */
  184.     public function exec($strName, $strXML = '', $booUseCache = false) {
  185.         //var_dump($this->PAN);
  186.         //var_dump($this->masterKey);
  187.         $objResult = false;
  188.        
  189.         // Инициализируем переменные ошибок
  190.         $this->intError = 0;
  191.         $this->strErrorTech = '';
  192.        
  193.         //echo 'PAN-'.$this->PAN."\r\n";
  194.        
  195.         // Вычислим хеш динамического пароля
  196.         $strDynamicPassword = null;
  197.         if ($this->dynamicPassword != null) {
  198.             $strDynamicPassword = $this->calcDynamicPassword();
  199.             $this->dynamicPassword = null;
  200.             //$this->setKey2Session('STAN', $this->STAN);
  201.         }//\\ if
  202.  
  203.         // Формируем XML для SOAP запроса
  204.         if (strlen($strXML))
  205.             $strData = '<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><'.$strName.'Rq xmlns="http://schemas.compassplus.ru/telebank/1.0/telebank.wsdl"><Request'.($strDynamicPassword != null ? ' DynamicPassword="'.$strDynamicPassword.'"' : '').(intval($this->keyId) ? ' KeyId="'.$this->keyId.'"' : '').($this->PAN != null ? ' PAN="'.$this->PAN.'"' : '').($this->PIN != null ? ' PIN="'.$this->PIN.'"' : '').($this->prevTranId != null ? ' PrevTranId="'.$this->prevTranId.'"' : '').' Product="TB"'.(intval($this->STAN) ? ' STAN="'.$this->STAN.'"' : '').' Ver="5.0" xmlns="">'.$strXML.'</Request></'.$strName.'Rq></SOAP-ENV:Body></SOAP-ENV:Envelope>';
  206.         else
  207.             $strData = '<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><'.$strName.'Rq xmlns="http://schemas.compassplus.ru/telebank/1.0/telebank.wsdl"><Request'.($strDynamicPassword != null ? ' DynamicPassword="'.$strDynamicPassword.'"' : '').(intval($this->keyId) ? ' KeyId="'.$this->keyId.'"' : '').($this->PAN != null ? ' PAN="'.$this->PAN.'"' : '').($this->PIN != null ? ' PIN="'.$this->PIN.'"' : '').($this->prevTranId != null ? ' PrevTranId="'.$this->prevTranId.'"' : '').' Product="TB"'.(intval($this->STAN) ? ' STAN="'.$this->STAN.'"' : '').' Ver="5.0" xmlns=""/></'.$strName.'Rq></SOAP-ENV:Body></SOAP-ENV:Envelope>';
  208.        
  209.         //var_dump($strData);
  210.        
  211.  
  212.         /*if ($objRequest = fsockopen('192.168.190.6', 8080, $errno, $errstr)) {
  213.             socket_set_timeout($objRequest, 60);
  214.             // Отошлем запрос
  215.             $strPost  = "POST /proxy.jsp HTTP/1.1\r\n";
  216.             $strPost .= "Host: 192.168.190.6:8080\r\n";
  217.             $strPost .= "Content-Type: text/xml\r\n";
  218.             $strPost .= "Accept-Language: en-us, en;q=0.50\r\n";
  219.             $strPost .= "Accept-Encoding: gzip, deflate, compress;q=0.9\r\n";
  220.             $strPost .= "Keep-Alive: 300\r\n";
  221.             $strPost .= "Connection: keep-alive\r\n";
  222.             $strPost .= "Cache-Control: max-age=0\r\n";
  223.             $strPost .= "Content-Type: application/x-www-form-urlencoded\r\n";
  224.             $strPost .= "Content-Length: ".strlen($strData)."\r\n";
  225.             $strPost .= "\r\n";
  226.             $strPost .= 'xml='.urlencode($strData);    
  227.             fwrite($objRequest, $strPost);*/
  228.  
  229.         // Получим ключ для кеша
  230.         if ($this->PAN != null) $strCacheKey = md5($this->PAN.'_'.$strName.'_'.$strXML);
  231.         else $strCacheKey = md5('0000000000000000_'.$strName.'_'.$strXML);
  232.        
  233.         if ($booUseCache && Cache::has($strCacheKey)) {
  234.             $strOutData = Cache::get($strCacheKey);
  235.         }//\\ if
  236.        
  237.         if (!$booUseCache || ($booUseCache && !Cache::has($strCacheKey))) {
  238.             // Делаем запрос в TWO
  239.             if ($objRequest = fsockopen($this->serviceHost, $this->servicePort, $errno, $errstr, Config::get('vtbi.timeout'))) {
  240.                 stream_set_blocking ($objRequest, 0);
  241.                
  242.                 //$cryptPassword = CryptUtils::CryptBlock($strWorkKey, $strPasswordHash, true);
  243.                
  244.                 socket_set_timeout($objRequest, Config::get('vtbi.timeout'));
  245.                 // Отошлем запрос
  246.                 $strPost  = "POST / HTTP/1.1\r\n";
  247.                 $strPost .= "Host: ".$this->serviceHost.':'.$this->servicePort."\r\n";
  248.                 $strPost .= "Connection: keep-alive\r\n";
  249.                 $strPost .= "User-Agent: Java/1.6.0_06\r\n";
  250.                 $strPost .= "Content-Type: text/xml; charset=utf-8\r\n";
  251.                 //$strPost .= "Accept-Language: en-us, en;q=0.50\r\n";
  252.                 $strPost .= "Accept-Encoding: gzip, deflate, compress;q=0.9\r\n";
  253.                 //$strPost .= "Keep-Alive: 300\r\n";
  254.                 //$strPost .= "Cache-Control: max-age=0\r\n";
  255.                 //$strPost .= "MIME-Version: 1.0\r\n";
  256.                 $strPost .= "SOAPAction: \"\"\r\n";
  257.                 $strPost .= "Content-Length: ".strlen($strData)."\r\n";
  258.                 //$strPost .= "Ver: 9.1\r\n";
  259.                 //$strPost .= "Product: FIMI\r\n";
  260.                 //$strPost .= "Clerk: anushka\r\n";
  261.                 //$strPost .= "Password: ".$cryptPassword."\r\n";
  262.  
  263.                 $strPost .= "\r\n";
  264.                 $strPost .= $strData;      
  265.                 fwrite($objRequest, $strPost);
  266.                 //fputs($objRequest, $strPost);
  267.                
  268.                 // Логируем запрос
  269.                 Log::Request($strData);
  270.                 if (Request::cli()) var_dump($strData);
  271.                
  272.                 // Получим заголовок ответа
  273.                 $strHeader = '';
  274.                 do $strHeader .= fread($objRequest, 1);
  275.                 while (!preg_match('/\\r\\n\\r\\n$/',$strHeader));
  276.                 //var_dump($strHeader);
  277.                
  278.                 $strOutData = '';
  279.                 if (preg_match('/Content\\-Length:\\s+([0-9]*)\\r\\n/',$strHeader,$matches)) {
  280.                     //echo '$matches[1]-'.$matches[1]."\n\r";
  281.                     $strOutData = fread($objRequest, $matches[1]);
  282.                     if (strlen($strOutData) != $matches[1]) {
  283.                         while (!feof($objRequest)) {
  284.                             $strOutData .= fread($objRequest, 512);
  285.                             //var_dump($strOutData);
  286.                             if (strlen($strOutData) >= $matches[1]) break;
  287.                         }//\\ while
  288.                        
  289.                     }//\\ if
  290.                 } else {
  291.                     // not a nice way to do it (may also result in extra CRLF which trails the real content???)
  292.                     while (!feof($objRequest)) {
  293.                         $strOutData .= fread($objRequest, 512);
  294.                         //var_dump($strOutData);
  295.                     }
  296.                 }
  297.                
  298.                 //echo 'strlen-'.strlen($strOutData)."\n\r";
  299.                 // Логируем ответ
  300.                 Log::Response($strOutData);
  301.                
  302.                 fclose($objRequest);
  303.             } else {
  304.                 $this->responseCode = 54;
  305.                 throw new Exception(MessagesVtbi::getResponseMessage($this->responseCode), $this->responseCode);
  306.             }//\\ if
  307.            
  308.             // Сохраним в кеше
  309.             if ($booUseCache) Cache::put($strCacheKey, $strOutData, 60);
  310.         }//\\ if
  311.        
  312.         // Ошибок нет, поэтому парсим ответ
  313.         if (!$this->intError) {
  314.            
  315.             if ($this->STAN >= 1) {
  316.                 $this->STAN++;
  317.                 $this->setKey2Session('STAN', $this->STAN);
  318.             }//\\ if
  319.            
  320.             if (Request::cli()) var_dump($strOutData); 
  321.  
  322.             try {
  323.                 if (!strlen($strOutData)) {
  324.                     $this->responseCode = 54;
  325.                     throw new Exception(MessagesVtbi::getResponseMessage($this->responseCode), $this->responseCode);
  326.                 }
  327.                
  328.                 $strOutData = str_replace('<m0:', '<', $strOutData);
  329.                 $strOutData = str_replace('</m0:', '</', $strOutData);
  330.                 $strOutData = str_replace('<m:', '<', $strOutData);
  331.                 $strOutData = str_replace('</m:', '</', $strOutData);
  332.  
  333.                 // Проверим наличие сообщения об ошибке
  334.                 $objXml = simplexml_load_string($strOutData);
  335.                 $objResult = $objXml->xpath('//SOAP-ENV:Envelope/SOAP-ENV:Body/SOAP-ENV:Fault/SOAP-ENV:Code/SOAP-ENV:Value');
  336.                 if (count($objResult)) {
  337.                    
  338.                     // Проверим существование номера транзакции
  339.                     $objResultTranId = $objXml->xpath('//SOAP-ENV:Envelope/SOAP-ENV:Body/SOAP-ENV:Fault/SOAP-ENV:Detail/TranId');
  340.                     if (count($objResultTranId)) {
  341.                         $this->setKey2Session('prevTranId', (integer)$objResultTranId[0]);
  342.                     }//\\ if
  343.                    
  344.                     $this->responseCode = (integer)$objResult[0];
  345.                     throw new Exception(MessagesVtbi::getResponseMessage($this->responseCode), $this->responseCode);
  346.                 }
  347.                
  348.    
  349.                
  350.                 // Парсим ответ
  351.                 $objXml = simplexml_load_string($strOutData);
  352.                 $objResult = $objXml->xpath('//SOAP-ENV:Body/'.$strName.'Rp/Response');
  353.                 if (count($objResult)) {
  354.                     $this->responseCode = (integer)$objResult[0]->attributes()->Response;
  355.                     if ($this->responseCode == 1) $objResult = $objResult[0];
  356.                     else {
  357.                         throw new Exception(MessagesVtbi::getResponseMessage($this->responseCode), $this->responseCode);
  358.                     }
  359.                 } else {
  360.                     $this->responseCode = 54;
  361.                     throw new Exception(MessagesVtbi::getResponseMessage($this->responseCode), $this->responseCode);
  362.                 }
  363.             } catch (Exception $e) {
  364.                 throw $e;
  365.             }//\\ try
  366.         }//\\ if
  367.        
  368.         //var_dump($objResult);
  369.         //exit;
  370.         return $objResult;
  371.     }//\\ exec
  372.  
  373.  
  374.  
  375.  
  376.     /**
  377.      * Получение PAN кода по текстовому логину
  378.      * @param $strTextLogin логин телебанка
  379.      * @return
  380.      */
  381.     public function getTextLoginPAN($strTextLogin) {
  382.         try {
  383.             $objGetPAN = $this->exec('GetPAN', '<TextLogin>'.$strTextLogin.'</TextLogin>', true);
  384. //          $objGetPAN = $this->exec('GetPAN', '<TextLogin>'.$strTextLogin.'</TextLogin>');
  385.             $strNewPAN = '';
  386.             if (isset($objGetPAN->PAN) && strlen((string)$objGetPAN->PAN) == 12 && strpos((string)$objGetPAN->PAN, '7788') === 0) {
  387.                 $strNewPAN = (string)$objGetPAN->PAN;
  388.             }
  389.             //$this->extraAuthLevel = (integer)$objGetPAN->ExtraAuthLevel;
  390.             $this->setKey2Session('extraAuthLevel', (integer)$objGetPAN->ExtraAuthLevel);
  391.             return $strNewPAN;
  392.         } catch (Exception $e) {
  393.             throw $e;
  394.         }//\\ try
  395.     }//\\ getTextLoginPAN
  396.  
  397.  
  398.     /**
  399.      * TB::setKey2Session()
  400.      * Сохраняет в свойствах класса и в сессии данные.
  401.      *
  402.      * @param mixed $strKey
  403.      * @param mixed $strValue
  404.      * @return
  405.      */
  406.     public function setKey2Session($strKey, $strValue) {
  407.         $this->{$strKey} = $strValue;
  408.         if (!Request::cli()) Session::put($strKey, $strValue);
  409.         return $this->{$strKey};
  410.     }//\\ getPAN
  411.    
  412.     /**
  413.      * TB::getKey2Session()
  414.      * Возвращает значение из сессии.
  415.      *
  416.      * @param mixed $strKey
  417.      * @param mixed $strValue
  418.      * @return
  419.      */
  420.     public function getKey2Session($strKey, $strValue = null) {
  421.         if (!Request::cli() && Session::has($strKey)) {
  422.             $this->{$strKey} = Session::get($strKey);
  423.         } else $this->{$strKey} = $strValue;
  424.         return $this->{$strKey};
  425.     }//\\ getPAN
  426.    
  427.    
  428.     /**
  429.      * TB::execLogoff()
  430.      * Осуществляет выход из сессии TWO.
  431.      *
  432.      * @return
  433.      */
  434.     public function execLogoff() {
  435.         if ($this->PAN == null) {
  436.             return false;
  437.         }//\\ if
  438.        
  439.         try {
  440.             $objLogoff = $this->exec('Logoff');
  441.         } catch (Exception $e) {
  442.                 throw $e;
  443.         }//\\ try
  444.        
  445.         $this->setKey2Session('personId', null);
  446.         $this->setKey2Session('textLogin', null);
  447.         $this->setKey2Session('personName', null);
  448.         $this->setKey2Session('lastLogon', null);
  449.         $this->setKey2Session('birthDay', null);
  450.  
  451.         $this->setKey2Session('PIN', null);
  452.         $this->setKey2Session('keyId', 0);
  453.         $this->setKey2Session('PAN', null);
  454.         $this->setKey2Session('dynamicPassword', null);
  455.         $this->setKey2Session('prevTranId', null);
  456.         $this->setKey2Session('extraAuthLevel', 0);
  457.         $this->setKey2Session('STAN', 0);
  458.     }//\\ execLogoff
  459.    
  460.     /**
  461.      * Telebank logon by PAN
  462.      * @param Login      user name
  463.      * @param Password   password
  464.      */
  465.     public function logonByPAN($strPAN, $strPassword) {
  466.         try {
  467.             if (!strlen($strPassword))
  468.                 throw new Exception(MessagesVtbi::getError(5003), 5003);
  469.    
  470.             if (!strlen($strPAN))
  471.                 throw new Exception(MessagesVtbi::getError(5004), 5004);
  472.             else {
  473.                 // Если пользователь авторизован, то сбросим сессию
  474.                 if (!Request::cli() && Auth::check()) {
  475.                     $this->execLogoff();
  476.                     Auth::logout();
  477.                     Session::flush();
  478.                 }//\\ if
  479.    
  480.                 $this->setKey2Session('PAN', $strPAN);
  481.                
  482.                 // Получим ключ
  483.                 //$objGetKey = $this->exec('CreateSession');
  484.                 $objGetKey = $this->exec('GetKey');
  485.                 $strSessionKey = (string)$objGetKey->Key;
  486.                 //$this->keyId = intval((integer)$objGetKey->KeyId);
  487.                 $this->setKey2Session('keyId', (string)$objGetKey->KeyId);
  488.  
  489.                 /*$this->setKey2Session('keyId', 373859);
  490.                 $strSessionKey = '74697C17B9FFC062';
  491.                 var_dump($this->masterKey);*/
  492.  
  493.                 $strWorkKey = CryptUtils::CryptBlock($this->masterKey, $strSessionKey, false);
  494.                 //var_dump($strWorkKey);
  495.                 $strPasswordHash = CryptUtils::MakePinBlock($this->PAN, $strPassword);
  496.                 //var_dump($strPasswordHash);
  497.                 $strPIN = CryptUtils::CryptBlock($strWorkKey, $strPasswordHash, true);
  498.                 $this->setKey2Session('PIN', $strPIN);
  499.                 //var_dump($this->PIN);
  500.                
  501.                 //$this->STAN = 1;
  502.                 $this->setKey2Session('STAN', 1);
  503.                
  504.                 // Регистрация пользователя
  505.                 $objLogon = $this->exec('Logon');
  506.                
  507.                 /*$this->personId = (integer)$objLogon->PersonId;
  508.                 $this->personName = (string)$objLogon->Name;
  509.                 $this->lastLogon = (string)$objLogon->LastLogonTime;
  510.                 $this->birthDay = (string)$objLogon->BirthDay;*/
  511.                
  512.                 $this->setKey2Session('personId', (integer)$objLogon->PersonId);
  513.                 $this->setKey2Session('personName', (string)$objLogon->Name);
  514.                 $this->setKey2Session('lastLogon', (string)$objLogon->LastLogonTime);
  515.                 $this->setKey2Session('birthDay', (string)$objLogon->BirthDay);
  516.                 //$this->setKey2Session('BirthPlace', (string)$objLogon->BirthPlace);
  517.                 //$this->setKey2Session('ExpDate', (string)$objLogon->ExpDate);
  518.                
  519.                 /*var_dump($this->personId);
  520.                 var_dump($this->personName);
  521.                 var_dump($this->lastLogon);
  522.                 var_dump($this->birthDay);*/
  523.                
  524.                 return $this->personId;
  525.             }//\\ if
  526.  
  527.         } catch (Exception $e) {
  528.             throw $e;
  529.         }//\\ try
  530.  
  531.         return false;
  532.     }//\\ logonByPAN
  533.  
  534.     /**
  535.      * Вход в телебанк по текстовому логину
  536.      * @param $strTextLogin логин телебанка
  537.      * @param $strPassword   пароль
  538.      */
  539.     public function logonByTextLogin($strTextLogin, $strPassword) {
  540.         try {
  541.             if (!strlen($strTextLogin))
  542.                 throw new Exception(MessagesVtbi::getError(5002), 5002);
  543.             else {
  544.                 // Запомнить имя регисрации
  545.                 //$this->textLogin = $strTextLogin;
  546.                 $this->setKey2Session('textLogin', $strTextLogin);
  547.                 // Регистрация по PAN
  548.                 $this->logonByPAN($this->getTextLoginPAN($strTextLogin), $strPassword);
  549.             }//\\ if
  550.         } catch (Exception $e) {
  551.             throw $e;
  552.         }//\\ try
  553.     }//\\ logonByTextLogin
  554.    
  555.     /**
  556.      * TB::calcDynamicPassword()
  557.      * Вычисляет динамический пароль.
  558.      *
  559.      * @return void
  560.      */
  561.     public function calcDynamicPassword() {
  562.         $strDynamicPassword = $this->dynamicPassword;
  563.         $strPassword = Str::upper($strDynamicPassword);
  564.        
  565.         if (strlen($strPassword) >= 8) $strPassword8 = substr($strPassword, 0, 8);
  566.         else  $strPassword8 = $strPassword.substr('        ', 0, 8-strlen($strPassword));
  567.        
  568.         if (strlen($strPassword) >= 16) $strPassword16 = substr($strPassword, 0, 16);
  569.         else  $strPassword16 = $strPassword.substr('                ', 0, 16-strlen($strPassword));
  570.        
  571.         $strPasswordHash = CryptUtils::CryptBlock(bin2hex($strPassword16), bin2hex($strPassword8), true);
  572.         return $strPasswordHash;   
  573.     }//\\ calcDynamicPassword
  574.    
  575.     /**
  576.      * TB::getBackOfficeInfo()
  577.      * Делает запрос в Back office.
  578.      *
  579.      * @param mixed $strInfoType
  580.      * @param mixed $strIdentType
  581.      * @param mixed $strIdent
  582.      * @param mixed $strFormat
  583.      * @param mixed $strAddParams
  584.      * @return
  585.      */
  586.     public function getBackOfficeInfo($strInfoType, $strIdentType, $strIdent, $strFormat, $strAddParams = null){
  587.         $strXML = '<InfoType>'.$strInfoType.'</InfoType><IdentType>'.$strIdentType.'</IdentType><Ident>'.$strIdent.'</Ident><Format>'.$strFormat.'</Format>';
  588.         if ($strAddParams != null) $strXML = '<AddParams>'.$strAddParams.'</AddParams>';
  589.        
  590.         $objXml = $this->exec('GetBackOfficeInfo', $strXML);
  591.         $objResult = $objXml->xpath('//Value');
  592.         if (count($objResult)) {
  593.             $strValue = (string)$objResult[0];
  594.             $strValue = base64_decode($strValue);
  595.             /*if (strpos($strValue, 'encoding="windows-1251"') !== false)
  596.                 $strValue = iconv('windows-1251', 'UTF-8', $strValue);*/
  597.         }//\\ if
  598.         return $strValue;
  599.     }//\\ getBackOfficeInfo
  600.    
  601.     /**
  602.      * TB::getDynAuthAddressList()
  603.      * Возвращает список получателей динамической аунтификации.
  604.      *
  605.      * @return
  606.      */
  607.     public function getDynAuthAddressList(){
  608.         $arrAddressList = array();
  609.         $objXml = $this->exec('DynAuthAddressList');
  610.         $objResult = $objXml->xpath('//List/Row');
  611.         if (count($objResult)) {
  612.             foreach($objResult as $objT) {
  613.                 if ((integer)$objT->Lock == 0)
  614.                     $arrAddressList[] = array(
  615.                         'Channel' => (string)$objT->Channel,
  616.                         'Provider' => (string)$objT->Provider,
  617.                         'Address' => (string)$objT->Address,
  618.                         'FullAddress' => (string)$objT->FullAddress,
  619.                         'Title' => (string)$objT->Title,
  620.                         'Default' => ((integer)$objT->Default == 1),
  621.                     );
  622.             }//\\ foreach
  623.         }//\\ if
  624.         return $arrAddressList;
  625.     }//\\ getDynAuthAddressList
  626.    
  627.     public function getCardLimits($strPAN, $strMBR) {
  628.         $arrLimits = array();
  629.         $objXml = $this->exec('CardLimits', '<PAN>'.$strPAN.'</PAN><MBR>'.$strMBR.'</MBR>');
  630.         $objResult = $objXml->xpath('//Limits/Row');
  631.         if (count($objResult)) {
  632.             foreach($objResult as $objT) {
  633.                 $arrLimits[] = array(
  634.                     'Id' => (integer)$objT->Id,
  635.                     'Title' => (string)$objT->Title,
  636.                     'Max' => (string)$objT->Max,
  637.                     'Current' => (integer)$objT->Current,
  638.                     'AtMomentCurrent' => (integer)$objT->AtMomentCurrent,
  639.                     'IsCounter' => (integer)$objT->IsCounter,
  640.                     'PeriodType' => (string)$objT->PeriodType,
  641.                     'Period' => (string)$objT->Period,
  642.                     'PermanentMax' => (string)$objT->PermanentMax,
  643.                 );
  644.             }//\\ foreach
  645.         }//\\ if
  646.         return $arrLimits;
  647.     }//\\ getCardLimits
  648.    
  649.    
  650. }//\\ TB
Add Comment
Please, Sign In to add comment