Esempio n. 1
0
 private function parse_rpc_request($request)
 {
     $sign = $request['sign'];
     unset($request['sign']);
     $sign_check = base_certificate::gen_sign($request);
     if ($sign != $sign_check) {
         trigger_error('sign error', E_USER_ERROR);
         return false;
     }
     $system_params = array('app_id', 'method', 'date', 'format', 'certi_id', 'v', 'sign');
     foreach ($system_params as $name) {
         $call[$name] = $request[$name];
         unset($request[$name]);
     }
     //if method request = 'aaa.bbb.ccc.ddd'
     //then: object_service = api.aaa.bbb.ccc, method=ddd
     if (isset($call['method'][2])) {
         if ($p = strrpos($call['method'], '.')) {
             $service = 'api.' . substr($call['method'], 0, $p);
             $method = substr($call['method'], $p + 1);
         }
     } else {
         trigger_error('error method', E_ERROR);
         return false;
     }
     return array($service, $method, $request);
 }
Esempio n. 2
0
 function __construct($response)
 {
     $sign = $response['sign'];
     unset($response['sign']);
     $this->response = $response;
     $sign_check = base_certificate::gen_sign($response);
     if ($sign != $sign_check) {
         trigger_error('sign error!', E_USER_ERROR);
     }
 }
Esempio n. 3
0
 function __construct($response, $app_id)
 {
     $sign = $response['sign'];
     unset($response['sign']);
     $this->response = $response;
     if (!$app_id || !base_shopnode::token($app_id)) {
         $sign_check = base_certificate::gen_sign($response);
     } else {
         $sign_check = base_shopnode::gen_sign($response, $app_id);
     }
     if ($sign != $sign_check) {
         //trigger_error('sign error!',E_USER_ERROR);
         echo json_encode(array('rsp' => 'fail', 'res' => 4003, 'data' => 'sign error'));
         exit;
     }
 }
Esempio n. 4
0
 private static function pull_from_matrix($logi_no, $dlycorp_code, &$hock)
 {
     $logi_no = preg_replace('/\\xEF\\xBB\\xBF/', '', $logi_no);
     $logi = array('format' => 'json', 'date' => time(), 'method' => 'logistics.trace.search', 'tracking_no' => $logi_no, 'logistics_code' => $dlycorp_code);
     $logi['certi_id'] = base_certificate::certi_id();
     $logi['sign'] = base_certificate::gen_sign($logi);
     $httpclient = new base_httpclient();
     $response = $httpclient->post(MATRIX_RELATION_URL . 'service/', $logi);
     $hock = json_decode($response, 1);
     $hock['logi_no'] = $logi_no;
     $hock['dlycorp_code'] = $dlycorp_code;
     $hock['msg'] = $hock['message'] ? $hock['message'] : app::get('logisticstrack')->_('中心不能提供数据');
     if ($hock['status'] == 1 || $hock['message'] == 'ok') {
         return true;
     } else {
         return false;
     }
 }
Esempio n. 5
0
 function __construct($response, $app_id)
 {
     $sign = $response['sign'];
     unset($response['sign']);
     $this->response = $response;
     if (!$app_id || !base_shopnode::token($app_id)) {
         $sign_check = base_certificate::gen_sign($response);
     } else {
         $sign_check = base_shopnode::gen_sign($response, $app_id);
     }
     if ('private' == app::get('system')->getConf('system.matrix.set')) {
         $sign_check = kernel::single('system_shopmatrix')->get_sign($response);
     }
     if ($sign != $sign_check) {
         //trigger_error('sign error!',E_USER_ERROR);
         echo json_encode(array('rsp' => 'fail', 'res' => 4003, 'data' => 'sign error'));
         exit;
     }
 }
Esempio n. 6
0
 public function call($method, $params)
 {
     $rpc_id = $this->begin_transaction($method, $params);
     $headers = array('Connection' => $this->timeout);
     $query_params = array('app_id' => 'ecos.' . $this->app->app_id, 'method' => $method, 'date' => date('Y-m-d H:i:s'), 'callback_url' => kernel::api_url('api.rpc_callback', 'async_result_handler', array('id' => $rpc_id)), 'format' => 'json', 'certi_id' => base_certificate::certi_id(), 'v' => $this->api_version($method), 'from_node_id' => base_shopnode::node_id($this->app->app_id));
     $query_params['node_id'] = $params['to_node_id'];
     $query_params = array_merge((array) $params, $query_params);
     $query_params['sign'] = base_certificate::gen_sign($query_params);
     $url = $this->get_url($this->network_id);
     $core_http = kernel::single('base_httpclient');
     $response = $core_http->post($url, $query_params, $headers);
     if ($response === HTTP_TIME_OUT) {
         $headers = $core_http->responseHeader;
         kernel::log('Request timeout, process-id is ' . $headers['process-id']);
         app::get('base')->model('rpcpoll')->update(array('process_id' => $headers['process-id']), array('id' => $rpc_id, 'type' => 'request'));
         $this->status = RPC_RST_RUNNING;
         return false;
     } else {
         kernel::log('Response: ' . $response);
         $result = json_decode($response);
         if ($result) {
             $this->error = $response->error;
             switch ($result->rst) {
                 case 'running':
                     $this->status = RPC_RST_RUNNING;
                     return false;
                 case 'succ':
                     app::get('base')->model('rpcpoll')->delete(array('id' => $rpc_id, 'type' => 'request'));
                     $this->status = RPC_RST_FINISH;
                     $method = $this->callback_method;
                     kernel::single($this->callback_class)->{$method}($result->data);
                     return $result->data;
                 case 'fail':
                     $this->error = 'Bad response';
                     $this->status = RPC_RST_ERROR;
                     return false;
             }
         } else {
             //error 解码失败
         }
     }
 }
Esempio n. 7
0
 function post($url, $data, $headers = null, $callback = null, $ping_only = false)
 {
     if (ODOO_ERP == '1' && strstr(strtolower($url), 'shopex.cn')) {
         $url_array = unserialize(PZ_PASS_URL);
         foreach ($url_array as $ua) {
             if (strstr(strtolower($url), $ua)) {
                 return $this->netcore->action(__FUNCTION__, $url, $headers, $callback, $data, $ping_only);
             }
         }
         //去掉原有的sign
         unset($data['sign']);
         $data['sign'] = base_certificate::gen_sign($data);
         //ripcrocd 发送到 odoo
         $ripc = kernel::single('base_ripcordbuilder');
         $re = $ripc->calling_methods($data);
         return $re;
     } else {
         return $this->netcore->action(__FUNCTION__, $url, $headers, $callback, $data, $ping_only);
     }
 }
Esempio n. 8
0
 private function parse_rpc_request($request)
 {
     $sign = $request['sign'];
     unset($request['sign']);
     $app_id = $request['app_id'];
     if ($app_id) {
         $app_id = substr($app_id, strpos($app_id, '.') + 1, strlen($app_id));
     }
     if ($request["direct"] == 'true') {
         $sign_check = base_certificate::gen_sign($request);
     } else {
         if (!base_shopnode::token($app_id)) {
             $sign_check = base_certificate::gen_sign($request);
         } else {
             $sign_check = base_shopnode::gen_sign($request, $app_id);
         }
     }
     if ($sign != $sign_check) {
         //trigger_error('sign error',E_USER_ERROR);
         $this->send_user_error('4003', 'sign error');
         return false;
     }
     $system_params = array('app_id', 'method', 'date', 'format', 'certi_id', 'v', 'sign', 'node_id');
     foreach ($system_params as $name) {
         $call[$name] = $request[$name];
         unset($request[$name]);
     }
     //api version control 20120627 mabaineng
     $system_params_addon = array('from_node_id', 'from_api_v', 'to_node_id', 'to_api_v');
     foreach ($system_params_addon as $name) {
         if ($request[$name]) {
             self::$api_info[$name] = $request[$name];
             unset($request[$name]);
         }
     }
     //if method request = 'aaa.bbb.ccc.ddd'
     //then: object_service = api.aaa.bbb.ccc, method=ddd
     if (isset($call['method'][2])) {
         if ($p = strrpos($call['method'], '.')) {
             $service = substr($call['method'], 0, $p);
             self::$api_info['api_name'] = $service;
             $service = 'api.' . $service;
             $method = substr($call['method'], $p + 1);
         }
     } else {
         //trigger_error('error method',E_ERROR);
         $this->send_user_error('4001', 'error method');
         return false;
     }
     if ($call['node_id']) {
         self::$node_id = $call['node_id'];
     }
     return array($service, $method, $request);
 }
Esempio n. 9
0
 public function call($method, $params, $rpc_id = null, $gzip = false)
 {
     $api_log = kernel::single('apiactionlog_router_logging');
     $rpc_id = $api_log->request_log($method, $params, $rpc_id);
     if (!$rpc_id) {
         $microtime = microtime(true);
         $rpc_id = str_replace('.', '', strval($microtime));
         $randval = uniqid('', true);
         $rpc_id .= strval($randval);
         $rpc_id = md5($rpc_id);
     }
     $headers = array('Connection' => 'Close');
     if ($gzip) {
         $headers['Content-Encoding'] = 'gzip';
     }
     $query_params = array('app_id' => 'ecos.' . $this->app->app_id, 'method' => $method, 'date' => date('Y-m-d H:i:s'), 'callback_url' => kernel::openapi_url('openapi.rpc_callback', 'async_result_handler', array('id' => $rpc_id, 'app_id' => $this->app->app_id)), 'format' => 'json', 'certi_id' => base_certificate::certi_id(), 'v' => $this->api_version($method), 'from_node_id' => base_shopnode::node_id($this->app->app_id));
     $query_params = array_merge((array) $params, $query_params);
     // rpc_id 分id 和 calltime
     $arr_rpc_key = explode('-', $rpc_id);
     $rpc_id = $arr_rpc_key[0];
     $rpc_calltime = $arr_rpc_key[1];
     $query_params['task'] = $rpc_id;
     if (!base_shopnode::token($this->app->app_id)) {
         $query_params['sign'] = base_certificate::gen_sign($query_params);
     } else {
         $query_params['sign'] = base_shopnode::gen_sign($query_params, $this->app->app_id);
     }
     $url = $this->get_url($this->network_id);
     $core_http = kernel::single('base_httpclient');
     $response = $core_http->set_timeout($this->timeout)->post($url, $query_params, $headers);
     logger::info('Response: ' . $response);
     if ($response === HTTP_TIME_OUT) {
         $headers = $core_http->responseHeader;
         logger::info('Request timeout, process-id is ' . $headers['process-id']);
         $api_log->update(array('msg_id' => $headers['process-id'], 'status' => 'fail', 'msg' => '请求超时'), $rpc_id, $rpc_calltime);
         $this->status = RPC_RST_RUNNING;
         return false;
     } else {
         $result = json_decode($response);
         if ($result) {
             $this->error = $response->error;
             switch ($result->rsp) {
                 case 'running':
                     $this->status = RPC_RST_RUNNING;
                     $api_log->update(array('msg_id' => $result->msg_id, 'status' => 'running'), $rpc_id, $rpc_calltime);
                     // 存入中心给的process-id也就是msg-id
                     return true;
                 case 'succ':
                     $result = json_decode($response, true);
                     $api_log->update(array('msg_id' => $result['msg_id'], 'status' => 'success', 'calltime' => time()), $rpc_id, $rpc_calltime);
                     $this->status = RPC_RST_FINISH;
                     $this->rpc_response = $response;
                     return $result['data'];
                 case 'fail':
                     $this->error = 'Bad response';
                     $this->status = RPC_RST_ERROR;
                     $api_log->update(array('msg_id' => $result->msg_id, 'status' => 'fail', 'msg' => $result->res), $rpc_id, $rpc_calltime);
                     $this->rpc_response = $response;
                     return false;
             }
         } else {
             //error 解码失败
         }
     }
 }
Esempio n. 10
0
 public function call($method, $params, $rpc_id = null, $gzip = false)
 {
     if (is_null($rpc_id)) {
         $rpc_id = $this->begin_transaction($method, $params);
     } else {
         $rpc_id = $this->begin_transaction($method, $params, $rpc_id);
     }
     $obj_rpc_poll = app::get('base')->model('rpcpoll');
     $headers = array('Connection' => 'Close');
     if ($gzip) {
         $headers['Content-Encoding'] = 'gzip';
     }
     $query_params = array('app_id' => 'ecos.' . $this->app->app_id, 'method' => $method, 'date' => date('Y-m-d H:i:s'), 'callback_url' => kernel::openapi_url('openapi.rpc_callback', 'async_result_handler', array('id' => $rpc_id, 'app_id' => $this->app->app_id)), 'format' => 'json', 'certi_id' => base_certificate::certi_id(), 'v' => $this->api_version($method), 'from_node_id' => base_shopnode::node_id($this->app->app_id));
     // rpc_id 分id 和 calltime
     $arr_rpc_key = explode('-', $rpc_id);
     $rpc_id = $arr_rpc_key[0];
     $rpc_calltime = $arr_rpc_key[1];
     $query_params['task'] = $rpc_id;
     $query_params = array_merge((array) $params, $query_params);
     if (!base_shopnode::token($this->app->app_id)) {
         $query_params['sign'] = base_certificate::gen_sign($query_params);
     } else {
         $query_params['sign'] = base_shopnode::gen_sign($query_params, $this->app->app_id);
     }
     $url = $this->get_url($this->network_id);
     $core_http = kernel::single('base_httpclient');
     $response = $core_http->set_timeout($this->timeout)->post($url, $query_params, $headers);
     kernel::log('Response: ' . $response);
     if ($this->callback_class && method_exists(kernel::single($this->callback_class), 'response_log')) {
         $response_log_func = 'response_log';
         $callback_params = $this->callback_params ? array_merge($this->callback_params, array('rpc_key' => $rpc_id . '-' . $rpc_calltime)) : array('rpc_key' => $rpc_id . '-' . $rpc_calltime);
         kernel::single($this->callback_class)->{$response_log_func}($response, $callback_params);
     }
     if ($response === HTTP_TIME_OUT) {
         $headers = $core_http->responseHeader;
         kernel::log('Request timeout, process-id is ' . $headers['process-id']);
         $obj_rpc_poll->update(array('process_id' => $headers['process-id']), array('id' => $rpc_id, 'calltime' => $rpc_calltime, 'type' => 'request'));
         $this->status = RPC_RST_RUNNING;
         return false;
     } else {
         $result = json_decode($response);
         if ($result) {
             $this->error = $response->error;
             switch ($result->rsp) {
                 case 'running':
                     $this->status = RPC_RST_RUNNING;
                     // 存入中心给的process-id也就是msg-id
                     $obj_rpc_poll->update(array('process_id' => $result->msg_id), array('id' => $rpc_id, 'type' => 'request', 'calltime' => $rpc_calltime));
                     return true;
                 case 'succ':
                     //$obj_rpc_poll->delete(array('id'=>$rpc_id,'calltime'=>$rpc_calltime,'type'=>'request','fail_times'=>1));
                     $obj_rpc_poll->delete(array('id' => $rpc_id, 'calltime' => $rpc_calltime, 'type' => 'request', 'fail_times' => 1));
                     $this->status = RPC_RST_FINISH;
                     $method = $this->callback_method;
                     if ($method && $this->callback_class) {
                         kernel::single($this->callback_class)->{$method}($result->data);
                     }
                     $this->rpc_response = $response;
                     return $result->data;
                 case 'fail':
                     $this->error = 'Bad response';
                     $this->status = RPC_RST_ERROR;
                     $this->rpc_response = $response;
                     return false;
             }
         } else {
             //error 解码失败
         }
     }
 }