I
I
iloyd2015-09-14 22:00:33
PHP
iloyd, 2015-09-14 22:00:33

301 moved permanently when trying to log in to Qiwi using Curl. How to fix?

Hello. Yesterday, I implemented authorization in qiwi.com using Curl. But today (09/14/2015) for some reason, instead of a beautiful page with information about the balance and the status of the account, I received 301 moved permanently in response.

require 'Curl.php';
    include 'simple_html_dom.php';	
    use Curl;
    ini_set("max_execution_time", "60");
    $curl = new Curl();
 
    $curl->setOpt(CURLOPT_SSL_VERIFYPEER, 0);
    $curl->setOpt(CURLOPT_FOLLOWLOCATION, 0);
    $curl->setCookieFile('cookie.txt');
    $curl->setHeader('Content-Type', 'application/json');
    $curl->setHeader('X-Requested-With', 'XMLHttpRequest');
    
 
    $data = array(
        'login' => '',
        'password' => '',//свои логин и пароль я потёр перед написанием вопроса
    );   
 
 
    $res = $curl->post('https://auth.qiwi.com/cas/tgts', json_encode($data));
 
    $TICKET = $res->entity->ticket;
 
    $data = array(
        "ticket" => $TICKET,
        "service" => "https://visa.qiwi.com/j_spring_cas_security_check",
    );
 
    $res = $curl->post('https://auth.qiwi.com/cas/sts', json_encode($data));
    
 
    $data = array(
        "ticket" => $TICKET,
        "service" => "https://visa.qiwi.com/j_spring_cas_security_check",
    );
 
    
    $res = $curl->post('https://auth.qiwi.com/cas/sts', json_encode($data));
    
    $TICKET = $res->entity->ticket;    
    $data = array(
        "ticket" => $TICKET,
    );
   // echo $TICKET;
    $res = $curl->get('https://visa.qiwi.com/j_spring_cas_security_check?ticket='.$TICKET); 
    $res = $curl->get('https://visa.qiwi.com/report/list.action?type=3'); 	
    $res = $curl->post('https://visa.qiwi.com/person/state.action');	
    echo $res; 
    if (isset($res->data->balances->RUB)) {
        echo "Balance  =".$res->data->balances->RUB.'<br>';
       // exit(0);
    } else {
        echo 'O\F8\E8\E1\EA\E0';
    }	
    $res = $curl->post('https://visa.qiwi.com/report/list.action?type=3');	
  $html = str_get_html($res);	
  echo $html;	
  if(count($html->find('.reports')))
       foreach($html->find('.reports') as $div)
     {
         echo "found";
             //echo $div->innertext;
       $StrParsed = $div->innertext;
     }

I should add that I use php-curl-class, which I took from the link: https://github.com/php-curl-class/php-curl-class , but I think this does not play a role in my problem.
I will also add that when I change the value of the second parameter to non-zero, it treacherously returns me to the authorization page:
$curl->setOpt(CURLOPT_FOLLOWLOCATION, 0);
Username and password verification is successful. This is evidenced by the receipt of "ticket".
What is the problem and how to solve it? Has the authorization algorithm been corrected again?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
shad541, 2015-09-18
@iloyd

There is a solution!

require_once 'Curl.php'; //https://github.com/php-curl-class/php-curl-class

$curl = new \Curl\Curl();
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, 0);
$curl->setCookieFile('cookie.txt');
$curl->setHeader('Content-Type', 'application/json');
$curl->setHeader('X-Requested-With', 'XMLHttpRequest');
$curl->setUserAgent('Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:40.0) Gecko/20100101 Firefox/40.0');

// Получаем TGT-тикет по логину и паролю
$res = json_decode($curl->post('https://auth.qiwi.com/cas/tgts', json_encode(array(
    'login' => '+***',
    'password' => '***'
))));
$TgtTicket = $res->entity->ticket;

// Получаем пару ST-тикетов по TGT-тикету
// первый тикет не нужен, а вот второй понадобится
$curl->post('https://auth.qiwi.com/cas/sts', json_encode(array(
    'ticket' => $TgtTicket,
    'service' => 'https://qiwi.com/j_spring_cas_security_check',
)));

$res = json_decode($curl->post('https://auth.qiwi.com/cas/sts', json_encode(array(
    'ticket' => $TgtTicket,
    'service' => 'https://qiwi.com/j_spring_cas_security_check',
))));
$STticket = $res->entity->ticket;

// выполняем чек
$res = $curl->get('https://qiwi.com/j_spring_cas_security_check?ticket='.$STticket);
// запрос к проксе
$res = $curl->get('https://auth.qiwi.com/app/proxy?v=1');

// запрос отчета за неделю
$curl->setHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
$reports = $curl->post('https://qiwi.com/user/report/list.action', array(
    'type' => '3'
));
// возвращаем Content-Type назад
$curl->setHeader('Content-Type', 'application/json');

print_r($reports);  // обработка результатов

// запрос баланса etc
$res = $curl->post('https://qiwi.com/person/state.action');
print_r($res); // обработка результатов

$curl->close();

X
xmoonlight, 2015-09-15
@xmoonlight

$curl->setOpt(CURLOPT_FOLLOWLOCATION, true);
$curl->setOpt(CURLOPT_RETURNTRANSFER, true);
$curl->setOpt(CURLOPT_AUTOREFERER, true);
$curl->setOpt(CURLOPT_SSL_VERIFYPEER,false);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question