コード例 #1
1
ファイル: odoo.php プロジェクト: funbaker/odoozpush
 public function Logon($username, $domain, $password)
 {
     $common = ripcord::client(ODOO_SERVER . '/xmlrpc/2/common');
     $this->uid = $common->authenticate(ODOO_DB, $username, $password, []);
     $this->username = $username;
     $this->domain = $domain;
     $this->password = $password;
     if ($this->uid) {
         $this->models = ripcord::client(ODOO_SERVER . '/xmlrpc/2/object');
         $this->models->_throwExceptions = true;
         $partners = $this->models->execute_kw(ODOO_DB, $this->uid, $password, 'res.users', 'search_read', [[['id', '=', $this->uid]]], ['fields' => ['partner_id']]);
         if (count($partners) == 0) {
             return false;
         }
         ZLog::Write(LOGLEVEL_DEBUG, 'Odoo::Logon: $partners = (' . print_r($partners, true)) . ')';
         $this->partnerID = $partners[0]['partner_id'][0];
         ZLOG::Write(LOGLEVEL_INFO, 'Odoo:Logon: Logged in with partner/user id ' . $this->partnerID . '/' . $this->uid);
         # timezone
         $users = $this->models->execute_kw(ODOO_DB, $this->uid, $password, 'res.users', 'search_read', [[['id', '=', $this->uid]]], ['fields' => ['tz']]);
         $user = $users[0];
         $this->utz = $user['tz'];
         return true;
     }
     return false;
 }
コード例 #2
0
 /**
  *调用方法
  */
 function calling_methods($post_param, $model = "eshop.to.odoo")
 {
     $uid = $this->logging_in();
     $models = ripcord::client("{$this->url}/xmlrpc/2/object");
     file_put_contents('api_juzhen.log', date("Y-m-d H:i:s", time()) . ' $post_param:' . print_r($post_param, 1) . "\r\n", FILE_APPEND);
     $re = $models->execute_kw($this->db, $uid, $this->password, $model, 'synchronous_method', array(json_encode($post_param), array()));
     file_put_contents('api_juzhen.log', date("Y-m-d H:i:s", time()) . ' $re:' . print_r($re, 1) . "\r\n", FILE_APPEND);
     return $re;
 }
コード例 #3
0
ファイル: OdooHandler.php プロジェクト: erpmesh/odoo-connect
 public function CreatePO($docHeader, $docDetailAr)
 {
     $models = ripcord::client("{$this->url}/xmlrpc/2/object");
     $id = $models->execute_kw($this->db, $this->uid, $this->password, 'res.partner', 'create', [['name' => "New Partner"]]);
     return $id;
     //        $search_id = $models->execute_kw($db, $uid, $password,
     //            'product.product', 'search', array(
     //                array(array('default_code', '=', '7wonder'))));
     //        var_dump($search_id);
     //        return;
     //
     //        $result = $models->execute_kw($db, $uid, $password,
     //            'product.template', 'search_read',
     //            array(array(array('active', '=', true))),
     //            array('fields'=>array('name', 'list_price'), 'limit'=>5));
     //        var_dump($result);
     //
     //
     //        $name = "New Product2";
     //        $product_template_id = $models->execute_kw($db, $uid, $password,
     //            'product.template', 'create',
     //            array(array('name'=>$name)));
 }
コード例 #4
0
ファイル: ripcord_client.php プロジェクト: odom/ripcord
 /**
  * This method catches any native method called on the client and calls it on the rpc server instead. It automatically
  * parses the resulting xml and returns native php type results.
  * @throws Ripcord_InvalidArgumentException (ripcord::notRipcordCall) when handling a multiCall and the 
  * arguments passed do not have the correct method call information
  * @throws Ripcord_RemoteException when _throwExceptions is true and the server returns an XML-RPC Fault.
  */
 public function __call($name, $args)
 {
     if (isset($this->_namespace)) {
         $name = $this->_namespace . '.' . $name;
     }
     if ($name === 'system.multiCall' || $name == 'system.multicall') {
         if (!$args || is_array($args) && count($args) == 0) {
             // multiCall is called without arguments, so return the fetch interface object
             return new Ripcord_Client_MultiCall($this->_rootClient, $name);
         } else {
             if (is_array($args) && count($args) == 1 && is_array($args[0]) && !isset($args[0]['methodName'])) {
                 // multicall is called with a simple array of calls.
                 $args = $args[0];
             }
         }
         $this->_rootClient->_multiCall = false;
         $params = array();
         $bound = array();
         foreach ($args as $key => $arg) {
             if (!is_a($arg, 'Ripcord_Client_Call') && (!is_array($arg) || !isset($arg['methodName']))) {
                 throw new Ripcord_InvalidArgumentException('Argument ' . $key . ' is not a valid Ripcord call', ripcord::notRipcordCall);
             }
             if (is_a($arg, 'Ripcord_Client_Call')) {
                 $arg->index = count($params);
                 $params[] = $arg->encode();
             } else {
                 $arg['index'] = count($params);
                 $params[] = array('methodName' => $arg['methodName'], 'params' => isset($arg['params']) ? (array) $arg['params'] : array());
             }
             $bound[$key] = $arg;
         }
         $args = array($params);
         $this->_rootClient->_multiCallArgs = array();
     }
     if ($this->_rootClient->_multiCall) {
         $call = new Ripcord_Client_Call($name, $args);
         $this->_rootClient->_multiCallArgs[] = $call;
         return $call;
     }
     if ($this->_rootClient->_cloneObjects) {
         //workaround for php bug 50282
         foreach ($args as $key => $arg) {
             if (is_object($arg)) {
                 $args[$key] = clone $arg;
             }
         }
     }
     $request = xmlrpc_encode_request($name, $args, $this->_outputOptions);
     $response = $this->_transport->post($this->_url, $request);
     $result = xmlrpc_decode($response);
     $this->_rootClient->_request = $request;
     $this->_rootClient->_response = $response;
     if (ripcord::isFault($result) && $this->_throwExceptions) {
         throw new Ripcord_RemoteException($result['faultString'], $result['faultCode']);
     }
     if (isset($bound) && is_array($bound)) {
         foreach ($bound as $key => $callObject) {
             if (is_a($callObject, 'Ripcord_Client_Call')) {
                 $returnValue = $result[$callObject->index];
             } else {
                 $returnValue = $result[$callObject['index']];
             }
             if (is_array($returnValue) && count($returnValue) == 1) {
                 // XML-RPC specification says that non-fault results must be in a single item array
                 $returnValue = current($returnValue);
             }
             if ($this->_autoDecode) {
                 $type = xmlrpc_get_type($returnValue);
                 switch ($type) {
                     case 'base64':
                         $returnValue = ripcord::binary($returnValue);
                         break;
                     case 'datetime':
                         $returnValue = ripcord::timestamp($returnValue);
                         break;
                 }
             }
             if (is_a($callObject, 'Ripcord_Client_Call')) {
                 $callObject->bound = $returnValue;
             }
             $bound[$key] = $returnValue;
         }
         $result = $bound;
     }
     return $result;
 }
コード例 #5
0
ファイル: ripcord_server.php プロジェクト: funbaker/ripcord
 /**
  * Handles the given request xml
  * @param string $request_xml The incoming request.
  * @return string
  */
 public function handle($request_xml)
 {
     $result = $this->parseRequest($request_xml);
     if (!$result || ripcord::isFault($result)) {
         return $result;
     } else {
         $method = $result['methodName'];
         $params = $result['params'];
     }
     if ($method == 'system.multiCall' || $method == 'system.multicall') {
         // php's xml-rpc server (xmlrpc-epi) crashes on multicall, so handle it ourselves... fixed in php 5.3.2
         $result = $this->multiCall($params);
     } else {
         try {
             $result = xmlrpc_server_call_method($this->xmlrpc, $request_xml, null, $this->outputOptions);
         } catch (Exception $e) {
             $result = xmlrpc_encode_request(null, ripcord::fault($e->getCode(), $e->getMessage()), $this->outputOptions);
         }
     }
     return $result;
 }
コード例 #6
0
ファイル: xmlrpc.php プロジェクト: poef/ariadne
 public static function getType($arg)
 {
     return ripcord::getType($arg);
 }
コード例 #7
0
ファイル: Server.php プロジェクト: darkaonline/ripcord
 /**
  * Runs the rpc server. Automatically handles an incoming request.
  */
 public function run()
 {
     if ($this->documentor) {
         $this->documentor->setMethodData($this->methods);
     }
     $request_xml = file_get_contents('php://input');
     if (!$request_xml) {
         if (($query = $_SERVER['QUERY_STRING']) && isset($this->wsdl[$query]) && $this->wsdl[$query]) {
             header('Content-type: text/xml');
             header('Access-Control-Allow-Origin: *');
             echo $this->wsdl[$query];
         } elseif ($this->documentor) {
             header('Content-type: text/html; charset=' . $this->outputOptions['encoding']);
             $this->documentor->handle($this, $this->methods);
         } else {
             // FIXME: add check for json-rpc protocol, if set and none of the xml protocols are set, use that
             header('Content-type: text/xml');
             header('Access-Control-Allow-Origin: *');
             echo xmlrpc_encode_request(null, ripcord::fault(-1, 'No request xml found.'), $this->outputOptions);
         }
     } else {
         // FIXME: add check for the protocol of the request, could be json-rpc, then check if it is supported.
         header('Content-type: text/xml');
         header('Access-Control-Allow-Origin: *');
         echo $this->handle($request_xml);
     }
 }
コード例 #8
0
 public function __construct()
 {
     $this->odoo_url = C('odoo_config.basic.odoo_url');
     $this->odoo_db = C('odoo_config.basic.odoo_db');
     $this->odoo_username = C('odoo_config.basic.odoo_username');
     $this->odoo_password = C('odoo_config.basic.odoo_password');
     require_once APPPATH . 'third_party/ripcord-1.1/ripcord.php';
     $this->common = ripcord::client("{$this->odoo_url}/xmlrpc/2/common");
     $this->uid = $this->common->authenticate($this->odoo_db, $this->odoo_username, $this->odoo_password, array());
     $this->models = ripcord::client("{$this->odoo_url}/xmlrpc/2/object");
 }