function index() { $mobileshop_url = $this->app->getConf('mobileshop.url'); $mobileshop_token = $this->app->getConf('mobileshop.token'); if (!empty($mobileshop_url)) { $wlshop = app::get('b2c')->model('shop'); $node_ids = $wlshop->getList('node_id', array('node_type' => 'shopex_wmall', 'status' => 'bind')); foreach ($node_ids as $value) { if (!empty($value['node_id'])) { $node_id = $value['node_id']; } } $callinfo['node_id'] = $node_id; $callinfo['shop_url'] = kernel::base_url(1) . kernel::url_prefix() . "/"; $callinfo['shop_license'] = base_certificate::get('certificate_id'); $callinfo['shop_node'] = base_shopnode::node_id('b2c'); $callinfo['shop_name'] = app::get('site')->getConf('site.name'); $callinfo['type'] = '1'; $callinfo['sign'] = $this->get_sign($callinfo, $mobileshop_token); $this->pagedata['ifseturl'] = 1; $this->pagedata['node_id'] = $callinfo['node_id']; $this->pagedata['type'] = $callinfo['type']; $this->pagedata['shop_license'] = $callinfo['shop_license']; $this->pagedata['shop_node'] = $callinfo['shop_node']; $this->pagedata['shop_url'] = $callinfo['shop_url']; $this->pagedata['shop_name'] = $callinfo['shop_name']; $this->pagedata['sign'] = $callinfo['sign']; $this->pagedata['mobileshop_url'] = $mobileshop_url; } else { $this->pagedata['ifseturl'] = 0; } $this->page('admin/index.html'); }
function index($method = 'apply', $app_id = 'b2c', &$callback = '', $api_url = '') { $this->Certi = base_certificate::get('certificate_id'); $this->Token = base_certificate::get('token'); $this->Node_id = base_shopnode::node_id($app_id); $token = $this->Token; $sess_id = kernel::single('base_session')->sess_id(); $apply['certi_id'] = $this->Certi; if ($this->Node_id) { $apply['node_idnode_id'] = $this->Node_id; } $apply['sess_id'] = $sess_id; $str = ''; ksort($apply); foreach ($apply as $key => $value) { $str .= $value; } $apply['certi_ac'] = md5($str . $token); if ($method == 'apply') { if ($apply['node_idnode_id']) { $this->pagedata['_PAGE_CONTENT'] = '<iframe width="100%" height="100%" src="' . MATRIX_RELATION_URL . '?source=apply&certi_id=' . $apply['certi_id'] . '&node_id=' . $apply['node_idnode_id'] . '&sess_id=' . $apply['sess_id'] . '&certi_ac=' . $apply['certi_ac'] . '&callback=' . $callback . '&api_url=' . $api_url . '" ></iframe>'; } else { $this->pagedata['_PAGE_CONTENT'] = '<iframe width="100%" height="100%" src="' . MATRIX_RELATION_URL . '?source=apply&certi_id=' . $apply['certi_id'] . '&sess_id=' . $apply['sess_id'] . '&certi_ac=' . $apply['certi_ac'] . '&callback=' . $callback . '&api_url=' . $api_url . '" ></iframe>'; } } elseif ($method == 'accept') { if ($apply['node_idnode_id']) { $this->pagedata['_PAGE_CONTENT'] = '<iframe width="100%" height="100%" src="' . MATRIX_RELATION_URL . '?source=accept&certi_id=' . $apply['certi_id'] . '&node_id=' . $apply['node_idnode_id'] . '&sess_id=' . $apply['sess_id'] . '&certi_ac=' . $apply['certi_ac'] . '&callback=' . $callback . '" ></iframe>'; } else { $this->pagedata['_PAGE_CONTENT'] = '<iframe width="100%" height="100%" src="' . MATRIX_RELATION_URL . '?source=accept&certi_id=' . $apply['certi_id'] . '&sess_id=' . $apply['sess_id'] . '&certi_ac=' . $apply['certi_ac'] . '&callback=' . $callback . '" ></iframe>'; } } else { $this->pagedata['_PAGE_CONTENT'] = ""; } $this->page(); }
public function setConf($apiName) { $conn = system_prism_init_util::getUserConn(); $apiId = system_prism_init_util::getApiId($apiName); $params = ['Id' => $apiId, 'key' => 'token', 'value' => base_shopnode::token()]; $this->call($conn, '/api/platform/service/config/set', $params, 'post'); return true; }
public static function isValidate($params) { $token = base_shopnode::token(); $sign_type = $params['sign_type']; $sign = $params['sign']; unset($params['sign']); return $sign_type == "MD5" && $sign == self::sign($params, $token); }
function index($method = 'apply', $app_id = 'b2c', $callback = '', $api_url = '', $user_id = '', $user_name = '', $api_v = '') { $this->Certi = base_certificate::get('certificate_id'); $_node_token = base_shopnode::get('token', $app_id); $this->Token = $_node_token ? $_node_token : base_certificate::get('token'); $this->Node_id = base_shopnode::node_id($app_id); $token = $this->Token; $sess_id = kernel::single('base_session')->sess_id(); $apply['certi_id'] = $this->Certi; if ($this->Node_id) { $apply['node_idnode_id'] = $this->Node_id; } $apply['sess_id'] = $sess_id; $str = ''; ksort($apply); foreach ($apply as $key => $value) { $str .= $value; } $apply['certi_ac'] = md5($str . $token); if ($method == 'apply') { if ($apply['node_idnode_id']) { $_url = MATRIX_RELATION_URL . '?source=apply&certi_id=' . $apply['certi_id'] . '&node_id=' . $apply['node_idnode_id'] . '&sess_id=' . $apply['sess_id'] . '&certi_ac=' . $apply['certi_ac'] . '&callback=' . $callback . '&api_url=' . $api_url . '&op_id=' . $user_id . '&op_user='******'&api_v=' . $api_v; } else { $_url = MATRIX_RELATION_URL . '?source=apply&certi_id=' . $apply['certi_id'] . '&sess_id=' . $apply['sess_id'] . '&certi_ac=' . $apply['certi_ac'] . '&callback=' . $callback . '&api_url=' . $api_url . '&op_id=' . $user_id . '&op_user='******'&api_v=' . $api_v; } } elseif ($method == 'accept') { if ($apply['node_idnode_id']) { $_url = MATRIX_RELATION_URL . '?source=accept&certi_id=' . $apply['certi_id'] . '&node_id=' . $apply['node_idnode_id'] . '&sess_id=' . $apply['sess_id'] . '&certi_ac=' . $apply['certi_ac'] . '&callback=' . $callback . '&api_url=' . $api_url . '&op_id=' . $user_id . '&op_user='******'&api_v=' . $api_v; } else { $_url = MATRIX_RELATION_URL . '?source=accept&certi_id=' . $apply['certi_id'] . '&sess_id=' . $apply['sess_id'] . '&certi_ac=' . $apply['certi_ac'] . '&callback=' . $callback . '&api_url=' . $api_url . '&op_id=' . $user_id . '&op_user='******'&api_v=' . $api_v; } } else { $this->pagedata['_PAGE_CONTENT'] = ""; } // 私有矩阵iframe url if ('private' == app::get('system')->getConf('system.matrix.set')) { $params = array('source' => $method, 'node_id' => $apply['node_idnode_id'], 'callback' => $callback); $sign = kernel::single('system_shopmatrix')->get_sign($params, $apply['node_idnode_id']); $iframe_url = kernel::single('system_shopmatrix')->get_iframe_url($this->Node_id); if ($method == 'apply') { if ($apply['node_idnode_id']) { $_url = $iframe_url . '?source=apply&node_id=' . $apply['node_idnode_id'] . '&callback=' . $callback . '&sign=' . $sign; } } elseif ($method == 'accept') { if ($apply['node_idnode_id']) { $_url = $iframe_url . '?source=accept&node_id=' . $apply['node_idnode_id'] . '&callback=' . $callback . '&sign=' . $sign; } } else { $this->pagedata['_PAGE_CONTENT'] = ""; } } if ($_url) { echo "<script>new Dialog('{$_url}',{iframe:true,title:'TITLE',width:.8,height:.8});</script>"; } //$this->page(); }
function get_sign($params, $node_id = "") { if (!$node_id) { $node_id = base_shopnode::node_id('b2c'); } $token = $this->get_token($node_id); if ($token) { return kernel::single('system_request')->gen_sign($params, $token); } return false; }
function index() { $callback_url = ''; $api_url = kernel::base_url(1) . kernel::url_prefix() . '/api'; $ceti_id = base_certificate::get('certificate_id'); $node_id = base_shopnode::node_id($this->app->app_id); $obj_user = kernel::single('desktop_user'); $user_id = $obj_user->user_data['user_id']; $user_name = $obj_user->user_data['name']; $api_v = $this->app->getConf("api.local.version"); $this->finder('b2c_mdl_shop', array('title' => app::get('b2c')->_('数据互联') . app::get('b2c')->_('证书:') . $ceti_id . ', ' . app::get('b2c')->_('节点:') . $node_id, 'actions' => array(array('label' => app::get('b2c')->_('新建绑定关系'), 'icon' => 'add.gif', 'href' => 'index.php?app=b2c&ctl=admin_shoprelation&act=addnew', 'target' => '_blank'), array('label' => app::get('b2c')->_('查看绑定情况'), 'icon' => 'add.gif', 'onclick' => 'new Request({evalScripts:true,url:\'index.php?ctl=shoprelation&act=index&p[0]=accept&p[1]=' . $this->app->app_id . '&p[2]=' . $callback . '&p[3]=' . $api_url . '&p[4]=' . $user_id . '&p[5]=' . $user_name . '&p[6]=' . $api_v . '\'}).get()')))); }
static function register($data = null) { $sys_params = base_setup_config::deploy_info(); $code = md5(microtime()); base_kvstore::instance('ecos')->store('net.handshake', $code); $app_exclusion = app::get('base')->getConf('system.main_app'); /** 得到框架的总版本号 **/ $obj_apps = app::get('base')->model('apps'); $tmp = $obj_apps->getList('*', array('app_id' => 'base')); $app_xml = $tmp[0]; $app_xml['version'] = $app_xml['local_ver']; if (defined('CERTIFICATE_SAS') && constant('CERTIFICATE_SAS')) { $data = array('certi_app' => 'open.reg', 'app_id' => 'ecos.' . $app_exclusion['app_id'], 'url' => $data ? $data : kernel::base_url(1), 'result' => $code, 'version' => $app_xml['version']); } else { $conf = base_setup_config::deploy_info(); $data = array('certi_app' => 'open.reg', 'identifier' => base_enterprise::ent_id(), 'password' => base_enterprise::ent_ac(), 'product_key' => $conf['product_key'], 'url' => $data ? $data : kernel::base_url(1), 'result' => $code, 'version' => $app_xml['version'], 'api_ver' => '1.3'); } $http = kernel::single('base_httpclient'); $http->set_timeout(6); $result = $http->post(LICENSE_CENTER, $data); //todo: 声称获取一个唯一iD,发给飞飞 $result = json_decode($result, 1); if ($result['res'] == 'succ') { if ($result['info']) { /* if ($result['info']['node_id']) { $arr_shop_node_id = array( 'node_id' => $result['info']['node_id'], ); base_shopnode::set_node_id($arr_shop_node_id,$app_exclusion['app_id']); unset($result['info']['node_id']); } */ //1.3接口不再返回node_id信息 base_shopnode::register($app_exclusion['app_id']); $certificate = $result['info']; $flag = self::set_certificate($certificate); if ($flag) { app::get('base')->setConf('certificate_code_url', $data['url']); return true; } else { return false; } } } else { //throw new Exception(LICENSE_CENTER." return ".$result['res']."error is-- ".$result['code'].",".$result['msg']); logger::error('create certificate_id faile, reason:' . LICENSE_CENTER . " return " . $result['res'] . "error is " . $result['code'] . "," . $result['msg'], false, LOG_ERR); return false; } }
function getmatrix() { $matrix = app::get('system')->model('matrixset'); $list = $matrix->getList('*'); $node_id = base_shopnode::node_id('b2c'); $node_type = "ecos.b2c"; foreach ($list as $key => $value) { $arr = array('api_url' => $value['api_url'], 'iframe_url' => $value['iframe_url'], 'shopname' => $value['shopname'], 'token' => $value['token'], 'matrixset_id' => intval($value['matrixset_id'])); } $arr['node_id'] = $node_id; $arr['node_type'] = $node_type; echo json_encode($arr); //echo "{api_url: 1, iframe_url:2, shopname: 'xxxx', node_id: 4, node_type: 'yyy', token: 5}"; }
static function get($code = 'node_id', $app_id = 'b2c') { if (!function_exists('get_node_id')) { if (self::$snode === null) { if ($shopnode = app::get($app_id)->getConf('shop_site_node_id')) { self::$snode = unserialize($shopnode); } else { self::$snode = array(); } } } else { self::$snode = get_node_id(); } return self::$snode[$code]; }
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; } }
function index() { //如果没有请求到证书,可以重新请求 if (!base_certificate::certi_id() || !base_certificate::token()) { base_certificate::register(); } if (!base_shopnode::node_id() && base_certificate::certi_id() && base_certificate::token()) { $obj_buildin = kernel::single('base_shell_buildin'); $obj_buildin->command_active_node_id('ceti_node_id'); } $this->pagedata['tip'] = base_application_tips::tip(); //设置shell_base_url if (app::get('base')->getConf('shell_base_url') !== kernel::base_url(1)) { app::get('base')->setConf('shell_base_url', kernel::base_url(1)); } $user = kernel::single('desktop_user'); $is_super = $user->is_super(); $group = $user->group(); $group = (array) $group; //桌面挂件排序,用户自定义 $layout_map = array('t-1' => 'top', 'l-1' => 'left', 'l-2' => 'right', 'b-1' => 'bottom'); foreach (kernel::servicelist('desktop.widgets') as $key => $obj) { if ($is_super || in_array(get_class($obj), $group)) { $class_full_name = get_class($obj); $key = $obj->get_width(); $item = array('title' => $obj->get_title(), 'html' => $obj->get_html(), 'width' => $obj->get_width(), 'className' => $obj->get_className(), 'class_full_name' => $class_full_name, 'layout' => $layout); $widgets[$key][] = $item; } } foreach ((array) $widgets as $key => $arr) { $layout = $layout_map[$key]; if ($user->get_conf('arr_dashboard_widgets_' . $layout . '_sort', $sort_conf) && $sort_conf) { //echo $sort_conf.'<br/><br/>'; $sort_conf = explode(',', $sort_conf); array_multisort($sort_conf, SORT_STRING, $arr); } $widgets[$key] = $arr; } $this->pagedata['left'] = $widgets['l-1']; $this->pagedata['right'] = $widgets['l-2']; $this->pagedata['top'] = $widgets['t-1']; $this->pagedata['bottom'] = $widgets['b-1']; $deploy = kernel::single('base_xml')->xml2array(file_get_contents(ROOT_DIR . '/config/deploy.xml'), 'base_deploy'); $this->pagedata['deploy'] = $deploy; $this->page('dashboard.html'); }
function register($url, $params) { $method = 'matrix.node.reg'; //base_shopnode::token('b2c'), $token = $params['token']; $headers = array('Connection' => 'Close'); $query_params = array('method' => $method, 'format' => 'json', 'from_node_id' => base_shopnode::node_id('b2c'), 'v' => 'v2_0', 'timestamp' => date('Y-m-d H:m:s', time()), 'token' => $token); $query_params = array_merge((array) $params, $query_params); $query_params['sign'] = $this->gen_sign($query_params, $token); $core_http = kernel::single('base_httpclient'); $response = $core_http->set_timeout(6)->post($url, $query_params, $headers); $result = json_decode($response, true); if ($result['rsp'] == 'succ') { return true; } else { return false; } }
function active() { if ($_GET['ent_id'] && $_GET['ent_ac'] && $_GET['ent_sign'] && $_GET['ent_email']) { //判断数据是否是中心过来的 if (md5($_GET['ent_id'] . $_GET['ent_ac'] . 'ShopEXUser') == $_GET['ent_sign']) { //检测企业帐号是否正确 base_enterprise::set_version(); base_enterprise::set_token(); if (!base_enterprise::is_valid('json', $_GET['ent_id'])) { header("Content-type: text/html; charset=utf-8"); $active_url = kernel::router()->app->base_url(1) . '/index.php?app=entermembercenter&ctl=register'; header('Location:' . $active_url); exit; } else { $arr_enterprise = array('ent_id' => $_GET['ent_id'], 'ent_ac' => $_GET['ent_ac'], 'ent_email' => $_GET['ent_email']); base_enterprise::set_enterprise_info($arr_enterprise); if (!base_certificate::certi_id() || !base_certificate::token()) { $flag = base_certificate::register(); } if (!$flag) { header("Content-type: text/html; charset=utf-8"); $active_url = kernel::router()->app->base_url(1) . '/index.php?app=entermembercenter&ctl=register'; header('Location:' . $active_url); exit; } if (!base_shopnode::node_id() && base_certificate::certi_id() && base_certificate::token()) { $obj_buildin = kernel::single('base_shell_buildin'); $obj_buildin->command_active_node_id('ceti_node_id'); } } } } else { header("Content-type: text/html; charset=utf-8"); $active_url = kernel::router()->app->base_url(1) . '/index.php?app=entermembercenter&ctl=register'; header('Location:' . $active_url); exit; } $url = kernel::router()->gen_url(array(), 1); $url = base64_encode($url); $login_html = 'index.php?ctl=passport&act=index&url=' . $url; header("Content-type: text/html; charset=utf-8"); header('Location:' . $login_html); exit; }
function clean($type = "clean") { //清除node_id $config = base_setup_config::deploy_info(); foreach ($config['package']['app'] as $k => $app) { $applist[] = $app['id']; } foreach ($applist as $str_app_id) { $app_xml = kernel::single('base_xml')->xml2array(file_get_contents(app::get($str_app_id)->app_dir . '/app.xml'), 'base_app'); if (isset($app_xml['node_id']) && $app_xml['node_id'] == "true" && base_shopnode::node_id($str_app_id)) { // 获取节点. base_shopnode::delete_node_id($str_app_id); } } //清除证书 base_certificate::del_certificate(); //清除shopex_id base_enterprise::set_enterprise_info(null); }
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; } }
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 解码失败 } } }
function index($method = 'apply', $app_id = 'b2c', $callback = '', $api_url = '', $user_id = '', $user_name = '', $api_v = '') { $this->Certi = base_certificate::get('certificate_id'); $_node_token = base_shopnode::get('token', $app_id); $this->Token = $_node_token ? $_node_token : base_certificate::get('token'); $this->Node_id = base_shopnode::node_id($app_id); $token = $this->Token; $sess_id = kernel::single('base_session')->sess_id(); $apply['certi_id'] = $this->Certi; if ($this->Node_id) { $apply['node_idnode_id'] = $this->Node_id; } $apply['sess_id'] = $sess_id; $str = ''; ksort($apply); foreach ($apply as $key => $value) { $str .= $value; } $apply['certi_ac'] = md5($str . $token); $matrixRelationUrl = config::get('link.matrix_relation_url'); if ($method == 'apply') { if ($apply['node_idnode_id']) { $_url = $matrixRelationUrl . '?source=apply&certi_id=' . $apply['certi_id'] . '&node_id=' . $apply['node_idnode_id'] . '&sess_id=' . $apply['sess_id'] . '&certi_ac=' . $apply['certi_ac'] . '&callback=' . $callback . '&api_url=' . $api_url . '&op_id=' . $user_id . '&op_user='******'&api_v=' . $api_v; } else { $_url = $matrixRelationUrl . '?source=apply&certi_id=' . $apply['certi_id'] . '&sess_id=' . $apply['sess_id'] . '&certi_ac=' . $apply['certi_ac'] . '&callback=' . $callback . '&api_url=' . $api_url . '&op_id=' . $user_id . '&op_user='******'&api_v=' . $api_v; } } elseif ($method == 'accept') { if ($apply['node_idnode_id']) { $_url = $matrixRelationUrl . '?source=accept&certi_id=' . $apply['certi_id'] . '&node_id=' . $apply['node_idnode_id'] . '&sess_id=' . $apply['sess_id'] . '&certi_ac=' . $apply['certi_ac'] . '&callback=' . $callback . '&api_url=' . $api_url . '&op_id=' . $user_id . '&op_user='******'&api_v=' . $api_v; } else { $_url = $matrixRelationUrl . '?source=accept&certi_id=' . $apply['certi_id'] . '&sess_id=' . $apply['sess_id'] . '&certi_ac=' . $apply['certi_ac'] . '&callback=' . $callback . '&api_url=' . $api_url . '&op_id=' . $user_id . '&op_user='******'&api_v=' . $api_v; } } else { $this->pagedata['_PAGE_CONTENT'] = ""; } if ($_url) { echo "<script>new Dialog('{$_url}',{iframe:true,title:'TITLE',width:.8,height:.8});</script>"; } }
function test_api() { $str = "不是21-P,sdf"; $pmatch = preg_match("/.*?(\\d+)P.*/i", $str, $matches); echo $pmatch; print_r($matches); exit; $certi = base_certificate::get('certificate_id'); $app_id = 'b2c'; $_node_token = base_shopnode::get('token', $app_id); $token = base_certificate::token(); /* $params=array( 'V'=>1.0, 'Method'=>'b2c.order.detail', 'app_id'=>$app_id, 'Date'=>'2014-02-26 17:16:30', 'certi_id'=>$app_id, 'node_id'=>$node_id, ); */ $headers = array('Connection' => 'Close'); $query_params = array('method' => 'diyapi.hello.get_hello', 'date' => date('Y-m-d H:m:s', time()), 'direct' => 'true'); $query_params['sign'] = $sign = $this->get_sign($query_params, $token); $core_http = kernel::single('base_httpclient'); $response = $core_http->set_timeout(6)->post('http://vip.hcyy.cn/index.php/api', $query_params, $headers); //$result = json_decode($response,true); print_r($response); echo "==============custom====== 00 999 "; print_r($query_params); echo "certi = " . $certi . ' ####### token=' . $token . '++++++' . $sign . '====== app_node_token=' . $_node_token; exit; echo kernel::single('system_request')->gen_sign($params, $token); $this->pagedata['project_name'] = $params; $this->display('default_api.html'); }
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 解码失败 } } }
/** * 网店节点显示 * @param null * @return null */ public function index() { $this->pagedata['node_id'] = base_shopnode::node_id($this->app->app_id); $this->pagedata['node_type'] = base_shopnode::node_type($this->app->app_id); $this->page('admin/shopnode.html'); }
function post_uninstall() { pam_account::unregister_account_type('member'); // set listener and modifier $app_b2c = app::get('b2c'); $all = $app_b2c->getConf('system.event_listener'); $len = strlen($ident) + 1; foreach ($all as $k => $m) { if ($all[$k][$m] == $this->arr_listener[$k]) { unset($all[$k][$m]); } } $app_b2c->setConf('system.event_listener', $all); $all = $app_b2c->getConf('system.event_listener_key'); foreach ($all as $k => $m) { if ($all[$k][$m] == $this->arr_lister_keys[$k]) { unset($all[$k][$m]); } } $app_b2c->setConf('system.event_listener_key', $all); // 获取node_id... if (base_shopnode::node_id('b2c')) { base_shopnode::delete_node_id('b2c'); } }
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); }
function command_update() { $options = $this->get_options(); if ($options['sync'] || $options['sync-only']) { kernel::single('base_application_manage')->sync(); } else { kernel::single('base_application_manage')->update_local(); } if ($options['sync-only']) { return true; } $args = func_get_args(); if (!$args) { $rows = app::get('base')->model('apps')->getList('app_id', array('installed' => 1)); foreach ($rows as $r) { if ($r['app_id'] == 'base') { continue; } $args[] = $r['app_id']; } } array_unshift($args, 'base'); //todo:总是需要先更新base $args = array_unique($args); if (!$options['ignore-download']) { foreach ($args as $app_id) { //kernel::single('base_application_manage')->download($app_id,$options['force-download']); //todo:临时去掉 } } if ($options['force-update-db']) { base_application_dbtable::$force_update = true; } if ($options['custom-force-update-db']) { if (defined('CUSTOM_CORE_DIR')) { foreach (utils::tree(CUSTOM_CORE_DIR) as $k => $v) { if (is_file($v)) { touch($v); } } } } if (!$options['download-only']) { foreach ($args as $app_id) { $appinfo = app::get('base')->model('apps')->getList('*', array('app_id' => $app_id)); if (version_compare($appinfo[0]['local_ver'], $appinfo[0]['dbver'], '>') || $options['force-update-app']) { app::get($app_id)->runtask('pre_update', array('dbver' => $appinfo[0]['dbver'])); kernel::single('base_application_manage')->update_app_content($app_id); app::get($app_id)->runtask('post_update', array('dbver' => $appinfo[0]['dbver'])); app::get('base')->model('apps')->update(array('dbver' => $appinfo[0]['local_ver']), array('app_id' => $app_id)); } else { kernel::single('base_application_manage')->update_app_content($app_id); } //新更版本等信息 $app_info = app::get($app_id)->define(); if (isset($app_info['node_id']) && $app_info['node_id'] == "true" && base_shopnode::node_id($app_id)) { if (base_shopnode::update($app_id)) { kernel::log('Applications info send to center, ok.'); } } } kernel::log('Applications database and services is up-to-date, ok.'); } }
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 解码失败 } } }