Esempio n. 1
0
 /**
  * 췽
  * @params object app object
  * @return null
  */
 public function __construct($app)
 {
     parent::__construct($app);
     header("cache-control: no-store, no-cache, must-revalidate");
     $this->certi_id = base_certificate::certi_id();
     $this->token = base_certificate::token();
 }
Esempio n. 2
0
 static function send_to_center($app_id, $data = null, $method = 'node.reg')
 {
     $app_info = app::get($app_id)->define();
     $obj_app = app::get($app_id);
     // 生成参数...
     $api_data = array('certi_app' => $method, 'certificate_id' => base_certificate::certi_id(), 'node_type' => 'ecos.' . $app_id, 'url' => kernel::base_url(true), 'version' => $app_info['version'], 'channel_ver' => $app_info['api_ver'], 'api_ver' => '1.2', 'format' => 'json', 'api_url' => kernel::base_url(1) . kernel::url_prefix() . '/api');
     //更新时,多带个参数
     if ($method == 'node.update') {
         $api_data['node_id'] = base_shopnode::node_id($app_id);
     }
     ksort($api_data);
     foreach ($api_data as $key => $value) {
         $str .= $value;
     }
     $api_data['certi_ac'] = strtoupper(md5($str . base_certificate::token()));
     $http = kernel::single('base_httpclient');
     $http->set_timeout(6);
     $result = $http->post(LICENSE_CENTER_V, $api_data);
     $result = json_decode($result, true);
     if ($result['res'] == 'succ') {
         return self::set_node_id($result['info'], $app_id);
     } else {
         return false;
     }
 }
Esempio n. 3
0
 public function pre_ceti_use()
 {
     if (!base_certificate::certi_id() || !base_certificate::token()) {
         return false;
     }
     return true;
 }
Esempio n. 4
0
 /**
  * 获取桌面widgets的html内容
  * @param null
  * @return string html内容
  */
 public function get_html()
 {
     $render = $this->render;
     $render->pagedata['page_url'] = SHOPEX_STAT_WEBURL;
     $render->pagedata['certi_id'] = base_certificate::certi_id();
     $render->pagedata['sign'] = md5($render->pagedata['certi_id'] . base_certificate::token());
     return $render->fetch('desktop/widgets/exstatistics.html');
 }
Esempio n. 5
0
 function post_install($options)
 {
     pam_account::register_account_type('b2c', 'member', '前台会员系统');
     kernel::log('Register b2c meta');
     $obj_goods = app::get('b2c')->model('goods');
     $col = array('adjunct' => array('type' => 'text', 'required' => false, 'label' => __('商品配件'), 'width' => 110, 'editable' => false));
     $obj_goods->meta_register($col);
     kernel::log('Initial b2c');
     kernel::single('base_initial', 'b2c')->init();
     kernel::log('Init b2c member');
     $attr_model = app::get('b2c')->model('member_attr')->init();
     if ($options['demodata']) {
         kernel::log('Import demo data');
         kernel::single('base_demo')->init();
     }
     $logo = app::get('b2c')->getConf('site.logo');
     $obj_image = app::get('image')->model('image');
     $app_dir = app::get('b2c')->app_dir;
     $obj_image->store($app_dir . '/initial/site_logo.png', $logo);
     $obj_image->store($app_dir . '/initial/default_images/spec_def.bmp', app::get('b2c')->getConf('spec.default.pic'));
     // set listener and modifier
     $app_b2c = app::get('b2c');
     $all = $app_b2c->getConf('system.event_listener');
     if ($this->arr_listener) {
         foreach ($this->arr_listener as $k => $v) {
             $k = strtolower($k);
             $v = strtolower($v);
             if (!isset($all[$k])) {
                 $all[$k] = array();
             }
             $all[$k][$v] = $v;
         }
     }
     $app_b2c->setConf('system.event_listener', $all);
     $all = $app_b2c->getConf('system.event_listener_key');
     if ($this->arr_lister_keys) {
         foreach ($this->arr_lister_keys as $k => $v) {
             $k = strtolower($k);
             $v = strtolower($v);
             if (!isset($all[$k])) {
                 $all[$k] = array();
             }
             $all[$k][$v] = $v;
         }
     }
     $app_b2c->setConf('system.event_listener_key', $all);
     // 获取node_id...
     if (!base_shopnode::node_id('b2c') && base_certificate::certi_id()) {
         base_shopnode::active('b2c');
     }
 }
Esempio n. 6
0
 /**
  *     ocs :
  *     $method = 'active.do_active'
  *     $ac = 'SHOPEX_ACTIVE'
  *
  *     其它产品默认
  */
 function check_code($code = null, $method = 'oem.do_active', $ac = 'SHOPEX_OEM')
 {
     if (!$code) {
         return false;
     }
     $certificate_id = base_certificate::certi_id();
     if (!$certificate_id) {
         base_certificate::register();
     }
     $certificate_id = base_certificate::certi_id();
     $token = base_certificate::token();
     $data = array('certi_app' => $method, 'certificate_id' => $certificate_id, 'active_key' => $_POST['auth_code'], 'ac' => md5($certificate_id . $ac));
     $result = kernel::single('base_httpclient')->post(LICENSE_CENTER_INFO, $data);
     $result = json_decode($result, true);
     return $result;
 }
Esempio n. 7
0
 /**
  * 获取桌面widgets的html内容
  * @param null
  * @return string html内容
  */
 public function get_html()
 {
     $render = $this->render;
     $render->pagedata['page_url'] = SHOPEX_STAT_WEBURL;
     $render->pagedata['certi_id'] = base_certificate::certi_id();
     $render->pagedata['sign'] = md5($render->pagedata['certi_id'] . base_certificate::token());
     $render->pagedata['stats_url'] = 'http://stats.shopex.cn/index.php';
     $render->pagedata['callback_url'] = urlencode('http://' . base_request::get_host() . app::get('site')->router()->gen_url(array('app' => 'stats', 'ctl' => 'site_openstats', 'act' => 'index')));
     $is_open = $this->app->getConf('site.stats.is_open');
     if ($is_open) {
         // 取到生意经的授权
         return $render->fetch('desktop/widgets/exstatistics.html');
     } else {
         // 显示激活页面
         return $render->fetch('desktop/widgets/activation.html');
     }
 }
Esempio n. 8
0
 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');
 }
Esempio n. 9
0
 static function register($app_id, $data = null)
 {
     $obj_app = app::get($app_id);
     // 生成参数...
     $project_name = str_replace($_SERVER['DOCUMENT_ROOT'], "", str_replace("\\", "/", realpath(dirname(__FILE__) . '/../../../../')));
     $data = array('certi_app' => 'node.reg', 'certificate_id' => base_certificate::certi_id(), 'node_type' => 'ecos.' . $app_id, 'url' => $_SERVER['SERVER_NAME'] . $project_name);
     $data['certi_ac'] = self::gen_sign_ac($data);
     // 申请获取一个唯一node_id
     $http = kernel::single('base_httpclient');
     $http->timeout = 3;
     $result = $http->post(LICENSE_CENTER, $data);
     $result = json_decode($result, true);
     if ($result['res'] == 'succ') {
         self::set_node_id($result['info'], $app_id);
     } else {
         return false;
     }
 }
Esempio n. 10
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. 11
0
 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;
 }
Esempio n. 12
0
 public function success()
 {
     /** 获取证书,企业号的验证 **/
     $active_url = kernel::base_url(1) . '/index.php/entermembercenter/default/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");
                 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_enterprise::ent_id() || !base_enterprise::ent_email() || !base_enterprise::ent_ac()) {
                     header("Content-type: text/html; charset=utf-8");
                     header('Location:' . $active_url);
                     exit;
                 }
                 base_certificate::register();
                 if (base_certificate::certi_id() && base_certificate::token()) {
                     $this->get_active_node_id();
                 }
             }
         } else {
             // 出现异常的情况
             header("Content-type: text/html; charset=utf-8");
             header('Location:' . $active_url);
             exit;
         }
     } else {
         header("Content-type: text/html; charset=utf-8");
         header('Location:' . $active_url);
         exit;
     }
     $success_url = kernel::base_url(1) . '/index.php/setup/default/success';
     header("Content-type: text/html; charset=utf-8");
     header('Location:' . $success_url);
     exit;
 }
Esempio n. 13
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. 14
0
 public function index()
 {
     if (!$this->token) {
         $this->begin('index.php?app=desktop&ctl=default&act=workground&wg=b2c.wrokground.sale');
         $this->end(false, app::get('stats')->_('LICENSE错误!'));
     }
     $sign = md5($this->certi_id . $this->token);
     $shoex_stat_webUrl = SHOPEX_STAT_WEBURL . "?site_id=" . $this->certi_id . "&sign=" . $sign . "&innerdesktop=true";
     $this->pagedata['shoex_stat_webUrl'] = $shoex_stat_webUrl;
     $this->pagedata['certi_id'] = base_certificate::certi_id();
     $this->pagedata['sign'] = md5($this->pagedata['certi_id'] . base_certificate::token());
     $this->pagedata['stats_url'] = SHOPEX_STAT_WEBURL;
     $this->pagedata['callback_url'] = urlencode('http://' . base_request::get_host() . app::get('site')->router()->gen_url(array('app' => 'stats', 'ctl' => 'site_openstats', 'act' => 'index')));
     $is_open = $this->app->getConf('site.stats.is_open');
     if ($is_open) {
         // 显示生意经统计页面
         $this->page('admin/bussiness/index.html');
     } else {
         // 显示激活页面
         $this->page('admin/bussiness/activation.html');
     }
 }
Esempio n. 15
0
    /**
     * 抛出数据给rpc,抛出点页面的底部
     * @param null
     * @return null
     */
    public function print_footer()
    {
        /**
         * 得到页面的属性,app,controller and action
         */
        $obj_base_component_request = kernel::single('base_component_request');
        $ctl_name = $obj_base_component_request->get_ctl_name();
        $act_name = $obj_base_component_request->get_act_name();
        $app_name = $obj_base_component_request->get_app_name();
        /**
         * app version
         */
        $obj_apps = app::get('base')->model('apps');
        $rows = $obj_apps->getList('local_ver', array('app_id' => $app_name));
        $app_ver = $rows[0]['local_ver'];
        $RSC_RPC = $this->app->getConf('site.rsc_rpc.url');
        // 开始抛出符合条件数据
        if ($this->app->getConf('site.rsc_rpc') && $RSC_RPC && ($certificate = base_certificate::certi_id())) {
            $RSC_RPC_STR = '<script>
            withBrowserStore(function(store){
                function randomChar(l)
                {
                    var  x="0123456789qwertyuioplkjhgfdsazxcvbnm";
                    var  tmp="";
                    for(var i=0;i<  l;i++)
                    {
                    tmp  +=  x.charAt(Math.ceil(Math.random()*100000000)%x.length);
                    }
                    return  tmp;
                }

                var lf = decodeURI(window.location.href);
                var pagetitle = document.title;
                var new_hs = "";
                var pos = lf.indexOf("#r-");
                var pos2 = lf.indexOf("%23r-");
                var stats = "";
                var rsc_rpc_url = "' . $RSC_RPC . '";
                var certi_id = "' . $certificate . '";
                var js_session_id = "' . md5(md5(kernel::single("base_session")->sess_id())) . '";
                var page_type = "' . urlencode($app_name) . ':' . urlencode($ctl_name) . ':' . urlencode($act_name) . '";
                var app_version = "ecos_' . $app_name . '(' . $app_ver . ')";
                var rstimestamp = "' . time() . '";

                if(pos!=-1||pos2!=-1)
                {
                    if(pos2!=-1){
                    pos=pos2+2;
                    }
                    new_hs=lf.substr(pos+1);
                }

                var old_hs = Cookie.read("S[SHOPEX_ADV_HS]");
                if(new_hs && old_hs!=new_hs)
                {
                    Cookie.set("S[SHOPEX_ADV_HS]",new_hs);
                }

                var shopex_stats = JSON.decode(Cookie.read("S[SHOPEX_STATINFO]"));
                if (shopex_stats)
                {
                    Cookie.write("S[SHOPEX_STATINFO]","",{path:"/"});
                }

                Object.each(shopex_stats,function(value, key){
                    stats += "&" + key + "=" + value;
                });

                if (!stats && Browser.Plugins.Flash.version)
                {
                    new Request({
                        url:"' . kernel::router()->gen_url(array('app' => 'stats', 'ctl' => 'site_statsajax', 'act' => 'index')) . '",
                        method:"post",
                        data:"method=getkvstore",
                        onSuccess:function(response){
                            response = JSON.decode(response);
                            var res = response;
                            if (res){
                                page_type="order:index";
                            }
                            Object.each(res,function(value, key){
                                stats += "&" + key + "=" + value;
                            });

                            store.get("jsapi",function(data){
                                var script = document.createElement("script");

                                var _src = rsc_rpc_url + "/jsapi?certi_id="+certi_id+"&_dep="+js_session_id+"&pt=" + page_type + "&app="+app_version+"&uid="+(encodeURIComponent(Cookie.read("S[MEMBER]") || "").split("-")[0])+"&ref="+encodeURIComponent(document.referrer)+"&sz="+JSON.encode(window.getSize())+"&hs="+encodeURIComponent(Cookie.read("S[SHOPEX_ADV_HS]") || new_hs)+"&rt="+ rstimestamp + stats + "&_pagetitle=" + pagetitle;
                                if(data){
                                    try{
                                    data = JSON.decode(data);
                                    }catch(e){}

                                    if($type(data)=="object"){
                                        _src +="&"+Hash.toQueryString(data);
                                    }else if($type(data)=="string"){
                                        _src +="&"+data;
                                    }
                                }

                                script.setAttribute("src",_src);
                                document.head.appendChild(script);

                            });
                        }
                    }).send();
                }
                else
                {
                    store.get("jsapi",function(data){
                        var script = document.createElement("script");

                        var _src = rsc_rpc_url + "/jsapi?certi_id="+certi_id+"&_dep="+js_session_id+"&pt=" + page_type + "&app="+app_version+"&uid="+(encodeURIComponent(Cookie.read("S[MEMBER]") || "").split("-")[0])+"&ref="+encodeURIComponent(document.referrer)+"&sz="+JSON.encode(window.getSize())+"&hs="+encodeURIComponent(Cookie.read("S[SHOPEX_ADV_HS]") || new_hs)+"&rt="+ rstimestamp + stats + "&_pagetitle=" + pagetitle;
                        if(data){
                            try{
                            data = JSON.decode(data);
                            }catch(e){}

                            if($type(data)=="object"){
                                _src +="&"+Hash.toQueryString(data);
                            }else if($type(data)=="string"){
                                _src +="&"+data;
                            }
                        }

                        script.setAttribute("src",_src);
                        document.head.appendChild(script);
                    });
                }

            });
            </script>';
        }
        return $RSC_RPC_STR;
    }
Esempio n. 16
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. 17
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 解码失败
         }
     }
 }