scripting / xml-rpc

XML-RPC client and server in JavaScript.
MIT License
61 stars 28 forks source link

Перестало работать) #16

Open Evgeny321991 opened 2 years ago

Evgeny321991 commented 2 years ago

Добрый день. Меня зовут Евгений. У нас работала синхронизация на сайте с продуктам 1с. Два месяца назад она перестала работать. Выяснили что подключение есть, но сайт информацию не отдает. Изучали код и предположили следующую ошибку. В коде написаны не рабочие ссылки на ресурсы. Вот часть кода:

function setCapabilities() { // Initialises capabilities array $this->capabilities = array( 'xmlrpc' => array( 'specUrl' => 'http://www.xmlrpc.com/spec', 'specVersion' => 1 ), 'faults_interop' => array( 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php', 'specVersion' => 20010516 ), 'system.multicall' => array( 'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208', 'specVersion' => 1 ), ); }

Мы очень слабо разбираемся в программировании, но предполагаем, что при рабочих ссылках всё заново будет работать.

Это весь код:

<?php /**

class IXR_Value { var $data; var $type;

function IXR_Value($data, $type = false)
{
    $this->data = $data;
    if (!$type) {
        $type = $this->calculateType();
    }
    $this->type = $type;
    if ($type == 'struct') {
        // Turn all the values in the array in to new IXR_Value objects
        foreach ($this->data as $key => $value) {
            $this->data[$key] = new IXR_Value($value);
        }
    }
    if ($type == 'array') {
        for ($i = 0, $j = count($this->data); $i < $j; $i++) {
            $this->data[$i] = new IXR_Value($this->data[$i]);
        }
    }
}

function calculateType()
{
    if ($this->data === true || $this->data === false) {
        return 'boolean';
    }
    if (is_integer($this->data)) {
        return 'int';
    }
    if (is_double($this->data)) {
        return 'double';
    }

    // Deal with IXR object types base64 and date
    if (is_object($this->data) && is_a($this->data, 'IXR_Date')) {
        return 'date';
    }
    if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) {
        return 'base64';
    }

    // If it is a normal PHP object convert it in to a struct
    if (is_object($this->data)) {
        $this->data = get_object_vars($this->data);
        return 'struct';
    }
    if (!is_array($this->data)) {
        return 'string';
    }

    // We have an array - is it an array or a struct?
    if ($this->isStruct($this->data)) {
        return 'struct';
    } else {
        return 'array';
    }
}

function getXml()
{
    // Return XML for this value
    switch ($this->type) {
        case 'boolean':
            return '<boolean>'.(($this->data) ? '1' : '0').'</boolean>';
            break;
        case 'int':
            return '<int>'.$this->data.'</int>';
            break;
        case 'double':
            return '<double>'.$this->data.'</double>';
            break;
        case 'string':
            return '<string>'.htmlspecialchars($this->data).'</string>';
            break;
        case 'array':
            $return = '<array><data>'."\n";
            foreach ($this->data as $item) {
                $return .= '  <value>'.$item->getXml()."</value>\n";
            }
            $return .= '</data></array>';
            return $return;
            break;
        case 'struct':
            $return = '<struct>'."\n";
            foreach ($this->data as $name => $value) {
                $return .= "  <member><name>$name</name><value>";
                $return .= $value->getXml()."</value></member>\n";
            }
            $return .= '</struct>';
            return $return;
            break;
        case 'date':
        case 'base64':
            return $this->data->getXml();
            break;
    }
    return false;
}

/**
 * Checks whether or not the supplied array is a struct or not
 *
 * @param unknown_type $array
 * @return boolean
 */
function isStruct($array)
{
    $expected = 0;
    foreach ($array as $key => $value) {
        if ((string)$key != (string)$expected) {
            return true;
        }
        $expected++;
    }
    return false;
}

}

/**

/**

EOD; // Send it $this->output($xml); }

function call($methodname, $args)
{
    if (!$this->hasMethod($methodname)) {
        return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.');
    }
    $method = $this->callbacks[$methodname];

    // Perform the callback and send the response
    if (count($args) == 1) {
        // If only one paramater just send that instead of the whole array
        $args = $args[0];
    }

    // Are we dealing with a function or a method?
    if (is_string($method) && substr($method, 0, 5) == 'this:') {
        // It's a class method - check it exists
        $method = substr($method, 5);
        if (!method_exists($this, $method)) {
            return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.');
        }

        //Call the method
        $result = $this->$method($args);
    } else {
        // It's a function - does it exist?
        if (is_array($method)) {
            if (!method_exists($method[0], $method[1])) {
                return new IXR_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.');
            }
        } else if (!function_exists($method)) {
            return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.');
        }

        // Call the function
        $result = call_user_func($method, $args);
    }
    return $result;
}

function error($error, $message = false)
{
    // Accepts either an error object or an error code and message
    if ($message && !is_object($error)) {
        $error = new IXR_Error($error, $message);
    }
    $this->output($error->getXml());
}

function output($xml)
{
    $xml = '<?xml version="1.0"?>'."\n".$xml;
    $length = strlen($xml);
    header('Connection: close');
    header('Content-Length: '.$length);
    header('Content-Type: text/xml');
    header('Date: '.date('r'));
    echo $xml;
    exit;
}

function hasMethod($method)
{
    return in_array($method, array_keys($this->callbacks));
}

function setCapabilities()
{
    // Initialises capabilities array
    $this->capabilities = array(
        'xmlrpc' => array(
            'specUrl' => 'http://www.xmlrpc.com/spec.md',
            'specVersion' => 1
    ),
        'faults_interop' => array(
            'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php',
            'specVersion' => 20010516
    ),
        'system.multicall' => array(
            'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208',
            'specVersion' => 1
    ),
    );
}

function getCapabilities($args)
{
    return $this->capabilities;
}

function setCallbacks()
{
    $this->callbacks['system.getCapabilities'] = 'this:getCapabilities';
    $this->callbacks['system.listMethods'] = 'this:listMethods';
    $this->callbacks['system.multicall'] = 'this:multiCall';
}

function listMethods($args)
{
    // Returns a list of methods - uses array_reverse to ensure user defined
    // methods are listed before server defined methods
    return array_reverse(array_keys($this->callbacks));
}

function multiCall($methodcalls)
{
    // See http://www.xmlrpc.com/discuss/msgReader$1208
    $return = array();
    foreach ($methodcalls as $call) {
        $method = $call['methodName'];
        $params = $call['params'];
        if ($method == 'system.multicall') {
            $result = new IXR_Error(-32600, 'Recursive calls to system.multicall are forbidden');
        } else {
            $result = $this->call($method, $params);
        }
        if (is_a($result, 'IXR_Error')) {
            $return[] = array(
                'faultCode' => $result->code,
                'faultString' => $result->message
            );
        } else {
            $return[] = array($result);
        }
    }
    return $return;
}

}

/**

EOD; foreach ($this->args as $arg) { $this->xml .= ''; $v = new IXR_Value($arg); $this->xml .= $v->getXml(); $this->xml .= "\n"; } $this->xml .= ''; }

function getLength()
{
    return strlen($this->xml);
}

function getXml()
{
    return $this->xml;
}

}

/**

/**

EOD; return $xml; } }

/**

/**

/**

/**

/**

/**

Evgeny321991 commented 2 years ago

Многие ссылки от вашего домена перестали работать в марте