예제 #1
0
function GetCardhRefValueSber($n, $outer = false)
{
    $CardhRefValueSber = nodeContent($n);
    $CardhRefValue = substr($CardhRefValueSber, 0, strpos($CardhRefValueSber, '"'));
    return $CardhRefValue;
}
예제 #2
0
 /**
  * @param string $LoginName
  * @param string $Password
  * @return string $XML
  */
 function SDMRestAccount($LoginName, $Password)
 {
     // Create the logger
     $logger = new Logger('logger_service');
     // Now add some handlers
     $logger->pushHandler(new StreamHandler(__DIR__ . '/Log/service.log', Logger::DEBUG));
     $logger->pushHandler(new FirePHPHandler());
     // You can now use your logger
     $logger->addInfo('Start running SDMRestAccount class');
     $sLogin = $LoginName;
     $sPassword = $Password;
     $postData = 'password='******'&username='******'https://retail.sdm.ru/logon?ReturnUrl=%2f', true, $postData, false, '', 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)', 60);
     if (!$data) {
         return 'нет ответа от сервера';
     }
     //echo($data);
     $cookie = substr($data, strpos($data, 'cookie=') + 7, strlen($data));
     if (!$cookie) {
         return 'не смогли залогиниться - нет кукисов';
     }
     //echo($cookie);
     $data = http_request('https://retail.sdm.ru/', false, '', false, $cookie, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)', 60);
     if (!$data) {
         return 'не можем получить информацию по счетам';
     }
     $body = substr($data, strpos($data, 'body=') + 5, strlen($body) - 8);
     //echo($body);
     $doc = new DOMDocument();
     libxml_use_internal_errors(true);
     $doc->loadHTML($body);
     libxml_clear_errors();
     $xpath = new DOMXPath($doc);
     $xml = new DOMDocument('1.0', 'UTF-8');
     // $xml = new DOMDocument('1.0','CP1251');
     $xmlRoot = $xml->createElement('GetAccountRestAndStmSDM');
     $xml->appendChild($xmlRoot);
     $TableTrAccount = $xpath->query('//div[@class="Content-Center"]/div[1]//table/tr/td');
     $TableTrCard = $xpath->query('//div[@class="Content-Center"]/div[2]//table/tr/td');
     $CountAccount = $TableTrAccount->length / 4;
     $CountCard = $TableTrCard->length / 6;
     //По счетам
     $xmlAccountList = $xml->createElement("AccountsList");
     $xmlAccountListAttribute = $xml->createAttribute("count");
     $xmlAccountListAttribute->value = $CountAccount;
     $xmlAccountList->appendChild($xmlAccountListAttribute);
     $xmlRoot->appendChild($xmlAccountList);
     for ($i = 0; $i < $CountAccount; $i++) {
         $xmlAccount = $xml->createElement("Account");
         $xmlAccountList->appendChild($xmlAccount);
         for ($j = 0; $j < 4; $j++) {
             //  printf('i='.$i.';j='.$j.';'.nodeContent($TableTrAccount->item($i*4+$j)).'<br>');
             switch ($j) {
                 case 0:
                     $xmlCurrCode = $xml->createElement("CurrCode");
                     $xmlAccount->appendChild($xmlCurrCode);
                     $xmlCurrCode->nodeValue = str_replace('"/', '', str_replace(' ', '', str_replace(' "ico-l" ', '', str_replace('img src="/img/ico_usd.gif" width="16" height="19" alt="', '', str_replace('img src="/img/ico_rur.gif" width="16" height="19" alt="', '', str_replace('img src="/img/ico_eur.gif" width="16" height="19" alt="', '', nodeContent($TableTrAccount->item($i * 4 + j))))))));
                     break;
                 case 1:
                     $xmlAccountName = $xml->createElement("AccountName");
                     $xmlAccount->appendChild($xmlAccountName);
                     $xmlAccountName->nodeValue = nodeContent($TableTrAccount->item($i * 4 + j + 1));
                     break;
                 case 2:
                     $xmlRest = $xml->createElement("Rest");
                     $xmlAccount->appendChild($xmlRest);
                     $xmlRest->nodeValue = nodeContent($TableTrAccount->item($i * 4 + $j));
                     break;
                 case 3:
                     $xmlAcountID = $xml->createElement("AcountID");
                     $xmlAccount->appendChild($xmlAcountID);
                     $xmlAcountID->nodeValue = str_replace('" "ajax-window"История платежей/a', '', str_replace('a href="/finances/account/', '', nodeContent($TableTrAccount->item($i * 4 + $j))));
                     break;
                 default:
                     //   Xml_.WriteStartElement("Param" + (j + 1).ToString());
                     break;
             }
         }
     }
     //По картам
     $xmlCardList = $xml->createElement("CardList");
     $xmlCardListAttribute = $xml->createAttribute("count");
     $xmlCardListAttribute->value = $CountCard;
     $xmlCardList->appendChild($xmlCardListAttribute);
     $xmlRoot->appendChild($xmlCardList);
     for ($i = 0; $i < $CountCard; $i++) {
         $xmlCard = $xml->createElement("Cards");
         $xmlCardList->appendChild($xmlCard);
         for ($j = 0; $j < 6; $j++) {
             //  printf('i='.$i.';j='.$j.';'.nodeContent($TableTrCard->item($i*6+$j)).'<br>');
             switch ($j) {
                 case 0:
                     $xmlCurrCodeCard = $xml->createElement("CurrCode");
                     $xmlCard->appendChild($xmlCurrCodeCard);
                     $xmlCurrCodeCard->nodeValue = str_replace('"/', '', str_replace(' ', '', str_replace(' "ico-l" ', '', str_replace('img src="/img/ico_usd.gif" width="16" height="19" alt="', '', str_replace('img src="/img/ico_rur.gif" width="16" height="19" alt="', '', str_replace('img src="/img/ico_eur.gif" width="16" height="19" alt="', '', nodeContent($TableTrCard->item($i * 6 + $j))))))));
                     break;
                 case 1:
                     $xmlCardType = $xml->createElement("CardType");
                     $xmlCard->appendChild($xmlCardType);
                     $xmlCardType->nodeValue = str_replace(' ', '', str_replace('img src=img/ico_mastercard.gif" width="32" height="20" alt="', '', str_replace('"/', '', str_replace(' "ico-r"', '', str_replace('img src="/img/ico_visa.gif" width="32" height="20" alt="', '', nodeContent($TableTrCard->item($i * 6 + $j)))))));
                     break;
                 case 2:
                     $xmlCardID = $xml->createElement("CardID");
                     $xmlCard->appendChild($xmlCardID);
                     $xmlCardID->nodeValue = str_replace('"MASTERCARD GOLD', '', str_replace('"VISA PLATINUM', '', str_replace('"VISA GOLD', '', str_replace('"VISA CLASSIC', '', str_replace('"MASTERCARD ELECTRONIC', '', str_replace('"VISA ELECTRON', '', str_replace('/a', '', str_replace('a "ajax-window" href="/finances/card/', '', nodeContent($TableTrCard->item($i * 6 + $j))))))))));
                     break;
                 case 4:
                     $xmlRestCard = $xml->createElement("Rest");
                     $xmlCard->appendChild($xmlRestCard);
                     $xmlRestCard->nodeValue = nodeContent($TableTrCard->item($i * 6 + $j));
                     break;
                 case 5:
                     $xmlCardClose = $xml->createElement("CloseCard");
                     $xmlCard->appendChild($xmlCardClose);
                     $xmlCardClose->nodeValue = str_replace('срок действия: ', '', nodeContent($TableTrCard->item($i * 6 + $j)));
                     break;
                 default:
                     break;
             }
         }
     }
     /*
         foreach ($TableTrAccount as $tag) {
              echo $tag->C14N();
             echo nodeContent($tag);
            }
     
         foreach ($TableTrAccount as $tag)
         {
             echo ($tag->nodeValue.'<br>');
         }
         
             foreach ($TableTrCard as $tag)
         {
             echo ($tag->nodeValue.'<br>');
         }
     */
     //return cp1251_to_utf8($xml->saveXML());
     $logger->addInfo('Good result: ' . $xml->saveXML());
     $logger->addInfo('End SDMRestAccount class');
     return $xml->saveXML();
 }
예제 #3
0
 /**
  * @param string $LoginName
  * @param string $Password
  * @return string $XML
  */
 public function SBERRestAccount($LoginName, $Password)
 {
     $Dir_path = str_replace('\\', '/', __DIR__);
     $logger = new Logger('logger_service');
     $logger->pushHandler(new StreamHandler($Dir_path . '/../logs/sber_json_debbug-' . $LoginName . '.log', Logger::DEBUG, false));
     $logger->pushHandler(new StreamHandler($Dir_path . '/../logs/sber_json_error-' . $LoginName . '.log', Logger::WARNING, false));
     $logger->pushHandler(new StreamHandler($Dir_path . '/../logs/sber_json_info-' . $LoginName . '.log', Logger::INFO, false));
     $logger->pushHandler(new FirePHPHandler());
     $logger->addInfo('------------------------------------------------------------------------------------------');
     $logger->addInfo('Start running SBERRestAccount class');
     $deviceprint = "deviceprintversion=3.4.0.0_2&pm_fpua=mozilla/5.0 (windows nt 6.3) applewebkit/537.36 (khtml, like gecko) chrome/36.0.1985.143 safari/537.36|5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36|Win32&pm_fpsc=24|1280|1024|984&pm_fpsw=&pm_fptz=4&pm_fpln=lang=ru|syslang=|userlang=&pm_fpjv=1&pm_fpco=1&pm_fpasw=widevinecdmadapter|pepflashplayer|internal-remoting-viewer|ppgooglenaclpluginchrome|pdf|npspwrap|npbssplugin|npgoogleupdate3|npdeployjava1|npjp2|npmeetingjoinpluginoc|npvlc|npitunes|npctrl&pm_fpan=Netscape&pm_fpacn=Mozilla&pm_fpol=true&pm_fposp=&pm_fpup=&pm_fpsaw=1280&pm_fpspd=24&pm_fpsbd=&pm_fpsdx=&pm_fpsdy=&pm_fpslx=&pm_fpsly=&pm_fpsfse=&pm_fpsui=&pm_os=Windows&pm_brmjv=36&pm_br=Chrome&pm_inpt=&pm_expt=";
     $htmlinjection = 'htmlinjection={"functions":{"names":[],"excluded":{"size":0,"count":0},"truncated":false},"inputs":[],"iframes":[],"scripts":[],"collection_status":3}';
     $manvsmachinedetection = 'manvsmachinedetection=1,1,INPUT:text,6;2,2,INPUT:text,22@1,3,0;1,1,0;1,1,0;1,1,0;1,1,0;1,1,0;1,1,0;1,1,0;1,4,0@0,1409563058988,0';
     $postData = urldecode('field(login)=' . $LoginName . '&field(password)=' . $Password . '&operation=button.begin&' . $deviceprint . '&' . $htmlinjection . '&' . $manvsmachinedetection);
     //$postData=  urldecode('field(login)='.$LoginName.'&field(password)='.$Password).'&operation=button.begin';
     //$logger->addInfo('>>>>>'.$postData);
     $data = http_requestSDM('https://online.sberbank.ru/CSAFront/index.do', false, '', false, '', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537', 30);
     if (!$data) {
         $logger->addError('не можем получить информацию по счетам URL 1');
         return 'не можем получить информацию по счетам';
     }
     $logger->addDebug('DATA1:' . $data . 'END DATA1');
     $cookie = substr($data, strpos($data, 'cookie=') + 7, strlen($data));
     $logger->addInfo('COOKIE1:' . $cookie . 'END DATA 1');
     $data = http_requestSDM('https://online.sberbank.ru/CSAFront/login.do', true, $postData, false, $cookie, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537', 30);
     if (!$data) {
         $logger->addError('не можем получить информацию по счетам URL 2');
         return 'не можем получить информацию по счетам';
     }
     $logger->addDebug('DATA2:' . $data . 'END DATA2');
     $URL_WITH_TOKEN = str_replace(';cookie=', '', str_replace('">', '', strstr($data, 'https')));
     if (!$URL_WITH_TOKEN) {
         $logger->addError('нет кукисов - возможно введен неверный пароль URL_WITH_TOKEN!');
         return 'нет кукисов - возможно введен неверный пароль!';
     }
     $logger->addInfo($URL_WITH_TOKEN);
     $data = http_requestSDM($URL_WITH_TOKEN, true, '', false, $cookie, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537', 30);
     if (!$data) {
         return 'не можем получить информацию по счетам URL 3';
     }
     $cookie = substr($data, strpos($data, 'cookie=') + 7, strlen($data));
     $logger->addInfo('COOKIE3:' . $cookie);
     $logger->addDebug('DATA3:' . $data . 'END DATA 3');
     //$data=  http_request('https://online.sberbank.ru/PhizIC/private/accounts.do',true, '' ,false,$cookie,'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36',60);
     //$data=  http_requestSDM('https://online.sberbank.ru/PhizIC/private/cards/list.do',true, '' ,false,$cookie,'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537',30);
     $data = http_requestSDM('https://node2.online.sberbank.ru/PhizIC/private/cards/list.do', true, '', false, $cookie, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537', 30);
     if (!$data) {
         return 'не можем получить информацию по счетам';
     }
     $logger->addDebug('DATA4:' . $data . 'END DATA 4');
     $body = substr($data, strpos($data, 'body=') + 5, -8);
     //  echo($body);
     if (!$body) {
         return 'не можем получить информацию по счетам';
     }
     $doc = new DOMDocument();
     libxml_use_internal_errors(true);
     $doc->loadHTML($body);
     libxml_clear_errors();
     $xpath = new DOMXPath($doc);
     $CardProductName = $xpath->query('//div[@class="productCover activeProduct"]//span[@class="mainProductTitle mainProductTitleLight"]');
     //$CardProductName = $xpath->query('//span[@class="mainProductTitle mainProductTitleLight"]');
     $CardNumber = $xpath->query('//div[@class="accountNumber decoration-none"]');
     $CardAmount = $xpath->query('//span[@class="overallAmount nowrap"] | //span[@class="overallAmount nowrap negativeAmount"]');
     $CardhRef = $xpath->query('//div[@class="productName"]//a[contains(@href,"/PhizIC/private/cards/info.do?id=")]');
     $CardsArray = '';
     $ArrayAccountID = '';
     $logger->addInfo('Count CardProductName=' . count($CardProductName));
     $logger->addInfo('Count CardNumber=' . count($CardNumber));
     $logger->addInfo('Count CardAmount=' . count($CardAmount));
     $logger->addInfo('Count CardhRef=' . count($CardhRef));
     $i = 0;
     foreach ($CardProductName as $CardProductName_) {
         $logger->addInfo('for I=' . $i);
         $logger->addInfo('CardProductName:' . GetCardProductNameSber($CardProductName_));
         $logger->addInfo('CardNumber:' . GetCardNumberSber($CardNumber->item($i)));
         $logger->addInfo('CardAmount:' . nodeContent($CardAmount->item($i)));
         $logger->addInfo('CardhRef:' . GetCardhRefValueSber($CardhRef->item($i)));
         $CardsArray[] = GetCardProductNameSber($CardProductName->item($i));
         $CardsArray[] = GetCardNumberSber($CardNumber->item($i));
         $CardsArray[] = nodeContent($CardAmount->item($i));
         $CardsArray[] = GetCardhRefValueSber($CardhRef->item($i));
         $ArrayAccountID[] = GetCardhRefValueSber($CardhRef->item($i));
         //Попробуем с кодами валют
         $logger->addInfo('CurrCode:' . CurrCodeSber($CardAmount->item($i)));
         $CardsArray[] = CurrCodeSber($CardAmount->item($i));
         $i++;
     }
     $json = array("AccountsList" => array(), "CardList" => array(), "AcountStatements" => array());
     $logger->addInfo('>>>>>RealResult starting');
     $logger->addInfo('Count Array=' . count($CardsArray));
     for ($i = 0; $i < count($CardsArray) / 5; $i++) {
         for ($j = 0; $j < 5; $j++) {
             //echo ('i='.$i.';j='.$j.'<br>');
             switch ($j) {
                 case 0:
                     $logger->addInfo('CardProductName:' . $CardsArray[$i * 5 + $j]);
                     $CardType = $CardsArray[$i * 5 + $j];
                     break;
                 case 1:
                     $logger->addInfo('CardNumber:' . $CardsArray[$i * 5 + $j]);
                     $CardNumber = $CardsArray[$i * 5 + $j];
                     break;
                 case 2:
                     $logger->addInfo('CardAmount:' . $CardsArray[$i * 5 + $j]);
                     $Rest = str_replace(",", ".", str_replace(' ', '', $CardsArray[$i * 5 + $j]));
                     break;
                 case 3:
                     $logger->addInfo('CardhRef:' . $CardsArray[$i * 5 + $j]);
                     $CardID = $CardsArray[$i * 5 + $j];
                     break;
                 case 4:
                     $logger->addInfo('CurrCode:' . $CardsArray[$i * 5 + $j]);
                     $CurrCode = $CardsArray[$i * 5 + $j];
                     break;
                 default:
                     break;
             }
         }
         if ($CardType != '') {
             $json["CardList"][] = array("CardType" => $CardType, "CardNumber" => $CardNumber, "Rest" => $Rest, "CardID" => $CardID, "CurrCode" => $CurrCode);
         }
     }
     //https://online.sberbank.ru/PhizIC/private/cards/print.do?id=9045783&printAbstract=true
     /*
     foreach ($ArrayAccountID as $ArrayAccountID_)
         {
       //  sel:c:9045783
     //fromDateString:01/01/2014
     //toDateString:03/03/2014
       //  $postData= 'fromDateString=01/01/2014&toDateString=03/0132014&sel:c:9045783';
         $data=  http_request('https://online.sberbank.ru/PhizIC/private/accounts/print.do?sel=c:'.$ArrayAccountID_.'&fromDateString=01/01/2014&toDateString=03/03/2014',true, '' ,false,$cookie,'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537',30);
         if (!$data) {
                $logger->addError('не можем получить информацию по выписке');
                //return 'не можем получить информацию по выписке';
            }
         $logger->addDebug('DATA5_STATEMENT1:'.$data.'END DATA5_STATEMENT1');
     
     
          $body=substr($data,strpos($data, 'body=')+5,-8);
          $logger->addDebug('DATA5:'.$body.'END DATA 5');
        
          $doc->loadHTML($body);
          libxml_clear_errors();
          $xpath = new DOMXPath($doc);
     
     $logger->addInfo('STATEMENT7:');
           //Выписка                      
          $TableTrStatement = $xpath->query('//table');
                    foreach ($TableTrStatement as $tag1) {
                       $logger->addInfo('NodeContent1:'.($tag1->nodeValue));
               }  
              
         
         }*/
     $logger->addInfo('Good result: ' . Json::json_encode($json));
     $logger->addInfo('End SBERRestAccount class');
     return Json::json_encode($json);
 }