3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php if( ($aResponse = @json_decode( $this->curl( 'person/state.action' ), true )) !== false && is_array( $aResponse['data'] ) && isset( $aResponse['data']['person'] ) && isset( $aResponse['data']['balances'] ) && $aResponse['data']['person'] == $iQiwiAccount ) { $this->iQiwiAccount = $aResponse['data']['person']; foreach( $aResponse['data']['balances'] as $sEquivalent => $dBalance ) $this->aBalances[$sEquivalent] = $dBalance; return; } # Запрос к серверу : $this->curl( 'https://auth.qiwi.com/cas/tgts', json_encode( array( 'login' => '+'.$iQiwiAccount, 'password' => $sPassword ) ) ); # Если в ответе есть ошибка : if( isset( $this->aResponse['entity'] ) && isset( $this->aResponse['entity']['error'] ) && isset( $this->aResponse['entity']['error']['message'] ) ) throw new Exception( $this->aResponse['entity']['error']['message'] ); # Если в ответе нет токена : if( !isset( $this->aResponse['entity'] ) || !isset( $this->aResponse['entity']['ticket'] ) ) throw new Exception( 'ticket not found - '.$this->sResponse ); # Тут у нас TGT токен $sTGTToken = $this->aResponse['entity']['ticket']; # Запрос к серверу : $this->curl( 'https://auth.qiwi.com/cas/sts', json_encode( array( 'service' => 'https://qiwi.com/j_spring_cas_security_check', 'ticket' => $sTGTToken ) ) ); # Если в ответе есть ошибка : if( isset( $this->aResponse['entity'] ) && isset( $this->aResponse['entity']['error'] ) && isset( $this->aResponse['entity']['error']['message'] ) ) throw new Exception( $this->aResponse['entity']['error']['message'] ); # Если в ответе нет токена : if( !isset( $this->aResponse['entity'] ) || !isset( $this->aResponse['entity']['ticket'] ) ) throw new Exception( 'ticket not found - '.$this->sResponse ); # Запрос к серверу : $this->curl( 'https://qiwi.com/j_spring_cas_security_check?ticket='.$this->aResponse['entity']['ticket'] ); # Если в ответе есть ошибка : if( isset( $this->aResponse['message'] ) && $this->aResponse['message'] != '' ) throw new Exception( $this->aResponse['message'] ); # Если авторизация не успешная : if( !isset( $this->aResponse['code'] ) || !isset( $this->aResponse['code']['_name'] ) || $this->aResponse['code']['_name'] != 'NORMAL' ) throw new Exception( 'error authorize - '.$this->sResponse ); # Получение информации об qiwi.кошельке : $this->curl( 'person/state.action' ); # Если возникла ошибка: if( !isset( $this->aResponse['data'] ) || !is_array( $this->aResponse['data'] ) || !isset( $this->aResponse['data']['person'] ) || !isset( $this->aResponse['data']['balances'] ) ) throw new Exception( var_export( $this->aResponse, true ) ); # Инициализация переменных класса : $this->iQiwiAccount = $this->aResponse['data']['person']; # Перебираем информацию о балансах : foreach( $this->aResponse['data']['balances'] as $sEquivalent => $dBalance ) { # Инициализация переменных класса : $this->aBalances[$sEquivalent] = $dBalance; } } public function SendMoney( $iQiwiAccount, $dAmount, $sCurrency, $sComment ) { return $this->payment( null, array( 'account' => '+'.$iQiwiAccount, 'comment' => $sComment ), $dAmount, $sCurrency ); } public function GetHistory( $sStartDate, $sFinishDate ) { $sResult = $this->curl( 'user/report/list.action?daterange=true&start='.$sStartDate.'&finish='.$sFinishDate ); $aTransactions = array(); foreach( explode( '</div><div class="reportsLine ', str_replace( '> <', '><', preg_replace( '!\s+!u', ' ', $sResult ) ) ) as $iKey => $sValue ) { if( $iKey == 0 ) continue; $aData = array(); $aData['iID'] = explode( '<span class="value">', $sValue ); if( count( $aData['iID'] ) < 2 ) continue; $aData['iID'] = explode( '</', $aData['iID'][1] ); $aData['iID'] = trim( $aData['iID'][0] ); $aData['sDate'] = explode( 'class="date">', $sValue ); $aData['sDate'] = explode( '</', $aData['sDate'][1] ); $aData['sDate'] = trim( $aData['sDate'][0] ); $aData['sTime'] = explode( 'class="time">', $sValue ); $aData['sTime'] = explode( '</', $aData['sTime'][1] ); $aData['sTime'] = trim( $aData['sTime'][0] ); $aData['sAmount'] = explode( 'class="originalExpense"><span>', $sValue ); $aData['sAmount'] = explode( '</', $aData['sAmount'][1] ); $aData['sAmount'] = trim( $aData['sAmount'][0] ); $aData['dAmount'] = preg_replace( '/[^0-9\.]+/', '', str_replace( ',', '.', $aData['sAmount'] ) ) - 0; $aData['sCurrency'] = mb_strpos( $aData['sAmount'], 'руб.' ) !== false ? 'RUB' : (mb_strpos( $aData['sAmount'], 'долл.' ) !== false ? 'USD' : (mb_strpos( $aData['sAmount'], 'тенге.' ) !== false ? 'KZT' : 'NAN')); $aData['sWithExpend'] = explode( 'WithExpend', $sValue ); $aData['sWithExpend'] = explode( '</div>', $aData['sWithExpend'][1] ); $aData['sWithExpend'] = explode( '<div class="cash">', $aData['sWithExpend'][0] ); $aData['sWithExpend'] = trim( $aData['sWithExpend'][1] ); $aData['dWithExpend'] = preg_replace( '/[^0-9\.]+/', '', str_replace( ',', '.', $aData['sWithExpend'] ) ) - 0; $aData['iOpponentPhone'] = explode( 'class="opNumber">', $sValue ); $aData['iOpponentPhone'] = explode( '</', $aData['iOpponentPhone'][1] ); $aData['iOpponentPhone'] = trim( str_replace( '+', '', $aData['iOpponentPhone'][0] ) ); $aData['sComment'] = explode( 'class="comment">', $sValue ); $aData['sComment'] = explode( '</', $aData['sComment'][1] ); $aData['sComment'] = html_entity_decode( trim( $aData['sComment'][0] ), ENT_QUOTES, 'UTF-8' ); $aData['sProvider'] = explode( '<div class="provider"><span>', $sValue ); $aData['sProvider'] = explode( '</span>', $aData['sProvider'][1] ); $aData['sProvider'] = trim( $aData['sProvider'][0] ); $aData['sType'] = mb_strpos( $sValue, 'IncomeWithExpend expenditure' ) !== false ? 'EXPENDITURE' : (mb_strpos( $sValue, 'IncomeWithExpend income' ) !== false ? 'INCOME' : 'NAN'); $aData['sStatus'] = explode( '"', $sValue ); $aData['sStatus'] = trim( $aData['sStatus'][0] ); if( $aData['sStatus'] == 'ERROR' ) { $aData['sError'] = explode( '{"message":"', $sValue ); $aData['sError'] = explode( '"', $aData['sError'][1] ); $aData['sError'] = trim( $aData['sError'][0] ); } if( $aData['iID'] == false ) { $aData['iID'] = explode( '{"txn":', $sValue ); $aData['iID'] = explode( '}', $aData['iID'][1] ); $aData['iID'] = $aData['iID'][0]; } $aTransactions['ID-'.$aData['iID']] = $aData; } return $aTransactions; } public function payment( $iProvider, array $aExtra, $dAmount, $sCurrency = 'RUB', $sPayCurrency = 'RUB' ) { $dAmount = intval( str_replace( ',', '.', $dAmount ) * 100 ) / 100; $aAmount = explode( '.', $dAmount ); if( !isset( $aAmount[1] ) ) $aAmount[1] = '00'; else if( strlen( $aAmount[1] ) != 2 ) $aAmount[1] .= '0'; foreach( $aExtra as $sKey => $sValue ) { $aExtra["extra['".$sKey."']"] = $sValue; unset( $aExtra[$sKey] ); } $this->curl( is_null( $iProvider ) ? 'payment/transfer/form.action' : 'payment/form.action?provider='.$iProvider ); if( ($aResponse = @json_decode( $this->curl( 'user/payment/form/state.action?'.http_build_query( array_merge( array( 'amountInteger' => $aAmount[0], 'amountFraction' => $aAmount[1], 'arg_num' => '', 'currency' => $sCurrency, 'protected' => 'true', 'source' => 'qiwi_'.$sPayCurrency, 'state' => 'CONFIRM' ), $aExtra ) ) ), true )) === false ) throw new Exception( 'internal error, step 1' ); if( !isset( $aResponse['data'] ) || !isset( $aResponse['data']['token'] ) ) throw new Exception( isset( $aResponse['message'] ) ? $aResponse['message'] : 'internal error, step 2' ); $sResponse = $this->curl( 'user/payment/form/state.action?'.http_build_query( array_merge( array( 'amountInteger' => $aAmount[0], 'amountFraction' => $aAmount[1], 'arg_num' => '', 'currency' => $sCurrency, 'protected' => 'true', 'source' => 'qiwi_'.$sPayCurrency, 'state' => 'CONFIRM', 'token' => $aResponse['data']['token'], ), $aExtra ) ) ); if( ($aResponse = @json_decode( $this->curl( 'payment/form/state.action?state=PAY' ), true )) === false ) throw new Exception( 'internal error, step 3' ); if( !isset( $aResponse['data'] ) || !isset( $aResponse['data']['token'] ) ) throw new Exception( isset( $aResponse['message'] ) ? $aResponse['message'] : 'internal error, step 4' ); $sResponse = $this->curl( 'payment/form/state.action', array( 'token' => $aResponse['data']['token'], 'state' => 'PAY' ) ); if( mb_strpos( $sResponse, 'transaction":"' ) === false ) { if( mb_strpos( $sResponse, 'class="errorElement"' ) !== false ) { $aExplode = explode( 'class="errorElement">', $sResponse ); $aExplode = explode( '</', $aExplode[1] ); throw new Exception( trim( $aExplode[0] ) ); } else { if( count( $sMessage = explode( '<p>', $sResponse ) ) < 2 ) throw new Exception( 'unknown error' ); $sMessage = explode( '</p>', $sMessage[1] ); throw new Exception( $sMessage[0] ); } } if( $iProvider == 22496 ) { if( count( $aExplode = explode( 'Код ваучера:', $sResponse ) ) < 2 ) throw new Exception( 'error parse egg' ); $aExplode = explode( '</', $aExplode[1] ); return trim( $aExplode[0] ); } $aHistory = $this->GetHistory( date( 'd.m.Y', strtotime( '-1 day' ) ), date( 'd.m.Y', strtotime( '+1 day' ) ) ); $aTransfer = array_shift( $aHistory ); if( $aTransfer === false || $aTransfer['dAmount'] != $dAmount || $aTransfer['sCurrency'] != $sCurrency ) throw new Exception( 'transfer not found in history' ); return $aTransfer['iID']; } private function curl( $sPath, $mPOST = null, array $aOptions = null ) { # Инициализация статических переменных : static $sReferer = null; # Инициализация переменных : $oCurl = curl_init( mb_substr( $sPath, 0, 4 ) == 'http' ? $sPath : 'https://qiwi.com/'.$sPath ); # Настройки cURL : curl_setopt_array( $oCurl, array( CURLOPT_RETURNTRANSFER => true, CURLOPT_COOKIEJAR => $this->sCookieFile, CURLOPT_COOKIEFILE => $this->sCookieFile, CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0', CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_HTTPHEADER => mb_substr( $sPath, 0, 4 ) == 'http' ? (is_null( $mPOST ) ? array( 'Accept: application/json, text/javascript, */*; q=0.01', 'X-Requested-With: XMLHttpRequest' ) : array( 'Content-Type: application/json; charset=UTF-8' )) : array( 'Accept: application/json, text/javascript, */*; q=0.01', 'X-Requested-With: XMLHttpRequest' ), ) ); # Если требуется отправить POST - запрос : if( is_array( $mPOST ) || $mPOST != '' || mb_substr( $sPath, 0, 4 ) != 'http' ) { # Настройки Curl подключения : curl_setopt_array( $oCurl, array( CURLOPT_POST => true, CURLOPT_POSTFIELDS => is_array( $mPOST ) ? http_build_query( $mPOST ) : $mPOST, ) ); } # Если существует реферер : if( !is_null( $sReferer ) ) curl_setopt( $oCurl, CURLOPT_REFERER, $sReferer ); # Если требуется указать дополнительные настройки : if( is_array( $aOptions ) && count( $aOptions ) ) curl_setopt_array( $oCurl, $aOptions ); # Получение ответа : $this->sResponse = curl_exec( $oCurl ); # Если произошла ошибка : if( curl_errno( $oCurl ) ) throw new Exception( curl_errno( $oCurl ).' - '.curl_error( $oCurl ) ); # Закрываем соединение : curl_close( $oCurl ); # Сохраняем страницу referer : $sReferer = mb_substr( $sPath, 0, 4 ) == 'http' ? $sPath : 'https://qiwi.com/'.$sPath; # Преобразование ответа в массив : $this->aResponse = json_decode( $this->sResponse, true ); if( json_last_error() != JSON_ERROR_NONE ) $this->aResponse = array(); return $this->sResponse; } } ?>
based on OOE7Q
Output for 7.0.0
Parse error: syntax error, unexpected '}', expecting end of file in /in/rRUB2 on line 61
Process exited with code 255.
Output for 5.3.20 - 5.6.16
Parse error: syntax error, unexpected '}' in /in/rRUB2 on line 61
Process exited with code 255.