* * @return float */ private function executionTime() { return microtime(true) - $this->executionTimeStart; } } spl_autoload_register(function ($className) { if (strpos($className, 'RpcClient_') !== 0) { return false; } eval(sprintf('class %s extends \\PHPClient\\JMTextRpcClient {}', $className)); }); if (false) { $config = array('rpc_secret_key' => '769af463a39f077a0340a189e9c1ec28', 'User' => array('uri' => 'tcp://127.0.0.1:2201', 'user' => 'Optool', 'secret' => '{1BA09530-F9E6-478D-9965-7EB31A59537E}'), 'Item' => array('uri' => 'tcp://127.0.0.1:2201', 'user' => 'Optool', 'secret' => '{1BA09530-F9E6-478D-9965-7EB31A59537E}'), 'Order' => array('uri' => 'tcp://127.0.0.1:2201', 'user' => 'Optool', 'secret' => '{1BA09530-F9E6-478D-9965-7EB31A59537E}')); JMTextRpcClient::on('send', function ($data) { echo 'Send => ', $data, PHP_EOL; }); JMTextRpcClient::on('recv', function ($data) { echo 'Recv <= ', $data, PHP_EOL; }); JMTextRpcClient::config($config); //$test = RpcClient_Item_Iwc::instance(); //var_export($test->getInventoryByWarehouses(array(100223,100002,100003,100006), array('BJ08','GZ07','SH05'))); $test = RpcClient_User_Address::instance($config); //var_dump($test->getListByUid(5100)); $test->getListByUid(5100, function () { var_dump(func_get_args()); }); }
/** * 处理业务逻辑 查询log 查询统计信息 * @see PHPServerWorker::dealProcess() */ public function dealProcess($recv_str) { $time_start = microtime(true); HTTP::decode($recv_str); $rsp_data = ''; if (!empty($_POST)) { // 传的是json文本 if (!empty($_POST['req_data'])) { $req_text = trim($_POST['req_data']); // 文本前有非json字符 if ($req_text[0] != "{" && $req_text[0] != "[") { for ($i = 0, $j = strlen($req_text); $i < $j; $i++) { if ($req_text[$i] == "{" || $req_text[$i] == "[") { $req_text = substr($req_text, $i); break; } } } $len = strlen($req_text); if ($req_text[$len - 1] != "}" && $req_text[$len - 1] != "]") { for ($i = $len - 1; $i > 0; $i--) { if ($req_text[$i] == "]" || $req_text[$i] == "}") { $req_text = substr($req_text, 0, $i + 1); break; } } } $req_data = json_decode($req_text, true); if (isset($req_data[0])) { $req_data = $req_data[0]; } if (isset($req_data['data'])) { $req_data = json_decode($req_data['data'], true); } if (is_array($req_data)) { if (isset($req_data['class'])) { $_POST['class'] = str_replace('RpcClient_', '', $req_data['class']); } if (isset($req_data['method'])) { $_POST['func'] = $req_data['method']; } if (isset($req_data['params'])) { $_POST['value'] = $req_data['params']; if (is_array($_POST['value'])) { foreach ($_POST['value'] as $key => $value) { if (!is_scalar($value)) { $_POST['value'][$key] = var_export($value, true); } else { if ($value === true) { $_POST['value'][$key] = 'true'; } elseif ($value === false) { $_POST['value'][$key] = 'false'; } elseif ($value === null) { $_POST['value'][$key] = 'null'; } } } } } } } $class = isset($_POST['class']) ? $_POST['class'] : ''; $func = isset($_POST['func']) ? $_POST['func'] : ''; $param = isset($_POST['value']) ? $_POST['value'] : ''; $post_address = isset($_POST['address']) ? $_POST['address'] : '127.0.0.1:2201'; list($address_ip, $address_port) = explode(':', $post_address); if (get_magic_quotes_gpc() && !empty($_POST['value']) && is_array($_POST['value'])) { foreach ($_POST['value'] as $index => $value) { $_POST['value'][$index] = stripslashes(trim($value)); } } if ($param) { foreach ($param as $index => $value) { if (stripos($value, 'array') === 0 || stripos($value, 'true') === 0 || stripos($value, 'false') === 0 || stripos($value, 'null') === 0 || stripos($value, 'object') === 0) { eval('$param[' . $index . ']=' . $value . ';'); } } } global $reqText, $rspText; JMTextRpcClient::on('send', function ($data) { global $reqText; $reqText = $data; }); JMTextRpcClient::on('recv', function ($data) { global $rspText; $rspText = $data; }); try { if (!class_exists('RpcClient_' . $class)) { eval('class RpcClient_' . $class . ' extends JMTextRpcClient {}'); } $remote_class = 'RpcClient_' . $class; $config = array('rpc_secret_key' => '769af463a39f077a0340a189e9c1ec28', 'User' => array('host' => $address_ip, 'port' => $address_port, 'user' => 'Optool', 'secret' => '{1BA09530-F9E6-478D-9965-7EB31A59537E}'), 'Item' => array('host' => $address_ip, 'port' => $address_port, 'user' => 'Optool', 'secret' => '{1BA09530-F9E6-478D-9965-7EB31A59537E}'), 'Order' => array('host' => $address_ip, 'port' => $address_port, 'user' => 'Optool', 'secret' => '{1BA09530-F9E6-478D-9965-7EB31A59537E}'), 'Cart' => array('host' => $address_ip, 'port' => $address_port, 'user' => 'Optool', 'secret' => '{1BA09530-F9E6-478D-9965-7EB31A59537E}')); $test = $remote_class::instance($config); //call_user_func_array(array($test, 'asend_'.$func), $param); //$rsp_data = call_user_func_array(array($test, 'arecv_'.$func), $param); $rsp_data = call_user_func_array(array($test, $func), $param); } catch (Exception $e) { $rsp_data = $e . ''; } if (isset($_POST['req_data'])) { $reqText = $_POST['req_data']; } return $this->display($reqText, $rspText, $rsp_data, '', microtime(true) - $time_start); } $this->display('', '', '', '', microtime(true) - $time_start); }