На 5 странице этой ветки автор опубликовал реквизиты для помощи, я уже отметился, рекомендую всем морально и материально поддержать автораneiks писал(а):Хорошая идея, я даже готов материально немножко помочь.

Выложи код обоих функций, или мне на почту.hcube писал(а):Ага, кажется нашел багу в либе. Или в самом URFA. Но скорее в либе.
Выглядит оно следующим образом - вызываю функцию 3018, возвращается код 0. Затем вызываю функцию 3019, возвращается код 3018 - т.е. оно читает из сокета ответ на _прыдыдущий_ запрос.
Пока что пофиксил ТРЕМЯ последовательными вызовами функции - третий раз оно проходит, но вообще надо это посмотреть более внимательно.
Код: Выделить всё
function urfa_call($code)
{
global $socket;
$packet = new Packet();
$packet->clean();
$packet->code=201;
$packet->AttrSetInt($code,3);
$packet->write($socket);
if (!feof($socket))
{
// for($i=0;$i<1000000;$i++); // задержка на чтение из сокета.
$packet->clean();
$packet->read($socket);
echo "read : ".$packet->code." -> [".dechex($packet->AttrGetInt(3))."] vs [".dechex($code)."]";
switch ($packet->code)
{
case 200:
if ($packet->AttrGetInt(3)==$code)
return TRUE;
else
return FALSE;
}
}
unset($packet);
}
Код: Выделить всё
function rpcf_link_user_tariff($user_id,$account_id=0,$tariff_current,$tariff_next=tariff_current,$discount_period_id,$tariff_link_id=0) { //0x3018
$ret=array();
if (!urfa_call(0x3018)) {
print "Error calling function ". __FUNCTION__ ."\n";
return FALSE;
}
$packet = new Packet();
$packet->DataSetInt($user_id);
$packet->DataSetInt($account_id);
$packet->DataSetInt($tariff_current);
$packet->DataSetInt($tariff_next);
$packet->DataSetInt($discount_period_id);
$packet->DataSetInt($tariff_link_id);
urfa_send_param($packet);
if ($x = urfa_get_data()) {
$ret['tariff_link_id']=$x->DataGetInt();
urfa_get_data();
}
return $ret;
}
function rpcf_unlink_user_tariff($user_id,$account_id=0,$tariff_link_id=0)
{ //0x3019
$ret=array();
if (!urfa_call(0x3019)) {
print "Error calling function ". __FUNCTION__ ."\n";
return FALSE;
}
$packet = new Packet();
$packet->DataSetInt($user_id);
$packet->DataSetInt($account_id);
$packet->DataSetInt($tariff_link_id);
urfa_send_param($packet);
return $ret;
}
Код: Выделить всё
function urfa_call($code)
{
global $socket;
$packet = new Packet();
$packet->clean();
$packet->code=201;
$packet->AttrSetInt($code,3);
$packet->write($socket);
if (!feof($socket))
{
$packet->clean();
$packet->read($socket);
echo "\nread : ".$packet->code." -> [".dechex($packet->AttrGetInt(3))."] vs [".dechex($code)."]";
while($packet->AttrGetInt(3) != $code)
{
$packet->read($socket);
echo "\nread : ".$packet->code." -> [".dechex($packet->AttrGetInt(3))."] vs [".dechex($code)."]";
}
switch ($packet->code)
{
case 200:
if ($packet->AttrGetInt(3)==$code)
return TRUE;
else
return FALSE;
}
}
unset($packet);
}
Код: Выделить всё
function urfa_call($code)
{
global $socket;
$packet = new Packet();
$packet->clean();
$packet->code=201;
$packet->AttrSetInt($code,3);
$packet->write($socket);
if (!feof($socket))
{
// for($i=0;$i<1000000;$i++); // задержка на чтение из сокета.
$packet->clean();
$packet->read($socket);
$ca = $packet->AttrGetInt(3);
echo "read : ".$packet->code." -> [".dechex($ca)."] vs [".dechex($code)."]";
// echo "read : ".$packet->code." -> [".dechex($packet->AttrGetInt(3))."] vs [".dechex($code)."]";
switch ($packet->code)
{
case 200:
if ($ca==$code)
return TRUE;
else
return FALSE;
}
}
unset($packet);
}
Код: Выделить всё
function AttrGetInt($code)
{
if (isset($this->attr[$code]['data']))
{
$x = unpack("N",$this->attr[$code]['data']);
return $x[1];
}
else
return FALSE;
}
Код: Выделить всё
function rpcf_link_user_tariff($user_id,$account_id=0,$tariff_current,$tariff_next=tariff_current,$discount_period_id,$tariff_link_id=0) { //0x3018
$ret=array();
if (!urfa_call(0x3018)) {
print "Error calling function ". __FUNCTION__ ."\n";
return FALSE;
}
$packet = new Packet();
$packet->DataSetInt($user_id);
$packet->DataSetInt($account_id);
$packet->DataSetInt($tariff_current);
$packet->DataSetInt($tariff_next);
$packet->DataSetInt($discount_period_id);
$packet->DataSetInt($tariff_link_id);
urfa_send_param($packet);
if ($x = urfa_get_data()) {
$ret['tariff_link_id']=$x->DataGetInt();
}
urfa_get_data(); // Для старой версии urfa_get_data
return $ret;
}
function rpcf_unlink_user_tariff($user_id,$account_id=0,$tariff_link_id=0)
{ //0x3019
$ret=array();
if (!urfa_call(0x3019)) {
print "Error calling function ". __FUNCTION__ ."\n";
return FALSE;
}
$packet = new Packet();
$packet->DataSetInt($user_id);
$packet->DataSetInt($account_id);
$packet->DataSetInt($tariff_link_id);
urfa_send_param($packet);
urfa_get_data(); // Для старой версии urfa_get_data
return $ret;
}
Код: Выделить всё
class URFAClient_Connection
{
private $socket = null;
public $error = ''; // Для возврата ошибки
function __construct($address, $port, $login, $pass, $ssl = true)
{
if ($address && $port && $login) {
if (!$this->open($address, $port)) {
$this->error = 'connect error';
return false;
}
if (!$this->login($login, $pass, $ssl)) {
$this->error = 'login error';
}
}
}
function open($address, $port)
{
$context = stream_context_create(array('ssl' => array('ciphers'=> "ADH-RC4-MD5",)));
$address = gethostbyname($address);
$this->socket = stream_socket_client("tcp://$address:$port", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
return !empty($this->socket); // Для возврата ошибки
}
....
Код: Выделить всё
abstract class URFAClient
{
/**
* @var URFAClient_Connection
*/
protected $connection = null;
protected $address;
protected $port;
public function __construct($login, $pass, $address = "127.0.0.1", $port = "11758", $ssl = false)
{
$this->address = $address;
$this->port = $port;
$this->connection = new URFAClient_Connection($address, $port, $login, $pass, $ssl);
$this->error = $this->connection->error;
}
}
Код: Выделить всё
$urfa_user5 = new URFAClient_User5($login, $password, "127.0.0.1", "11758",false);
if ($urfa_user5->error<>'') {
exit($urfa_user5->error);
}
Код: Выделить всё
function rpcf_get_users_list($from,$to,$card_user=0) { //0x2001
$ret=array();
if (!$this->connection->urfa_call(0x2001)) {
print "Error calling function ". __FUNCTION__ ."\n";
return FALSE;
}
$packet = $this->connection->getPacket();
$packet->DataSetInt($from);
$packet->DataSetInt($to);
$packet->DataSetInt($card_user);
$this->connection->urfa_send_param($packet);
if($x = $this->connection->urfa_get_data()){
$count=$x->DataGetInt();
$ret['count']=$count;
for ($i=0;$i<$count;$i++) {
$users['user_id']=$x->DataGetInt();
$users['login']=$x->DataGetString();
$users['basic_account']=$x->DataGetInt();
$users['full_name']=$x->DataGetString();
$users['is_blocked']=$x->DataGetInt();
$users['balance']=$x->DataGetDouble();
$ip_adr_size=$x->DataGetInt();
$users['ip_adr_size']=$ip_adr_size;
$ipgroup=array();
for ($j=0;$j<$ip_adr_size;$j++) {
$group_size=$x->DataGetInt();
$ipgroup['group_size']=$group_size;
$ips=array();
for ($k=0;$k<$group_size;$k++) {
$ips['ip_address']=$x->DataGetIPAddress();
$ips['mask']=$x->DataGetIPAddress();
$ips['group_type']=$x->DataGetInt();
$ipgroup['ips'][]=$ips;
}
$users['ipgroup']=$ipgroup;
}
$users['user_int_status']=$x->DataGetInt();
$ret['users'][]=$users;
}
}
return $ret;
}