@ 2015-12-14T02:15:43Z <?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;
}
}
?>
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 7.0.0 0.000 0.050 20.38 5.6.16 0.013 0.087 20.57 5.6.15 0.010 0.080 18.14 5.6.14 0.003 0.043 18.18 5.6.13 0.003 0.077 18.17 5.6.12 0.003 0.087 21.14 5.6.11 0.017 0.050 21.00 5.6.10 0.007 0.053 21.05 5.6.9 0.010 0.063 20.98 5.6.8 0.010 0.033 20.53 5.5.30 0.000 0.047 18.02 5.5.29 0.007 0.073 18.03 5.5.28 0.007 0.087 20.80 5.5.27 0.017 0.077 20.67 5.5.26 0.020 0.063 20.70 5.5.25 0.000 0.063 20.52 5.5.24 0.020 0.073 20.18
preferences:dark mode live preview
134.29 ms | 1394 KiB | 7 Q