Example #1
0
 public function create_key($key)
 {
     if (isset($key[201])) {
         return parent::create_key($key);
     }
     return sprintf("%s/%s/%s", base_kvstore::kvprefix(), $this->prefix, $key);
 }
Example #2
0
 public function clear_by_app($app_id)
 {
     if (!$app_id) {
         return false;
     }
     base_kvstore::instance('imgbundle')->delete('imgbundle_' . $app_id);
 }
Example #3
0
 function login_hankshake()
 {
     if (base_kvstore::instance('ecos')->fetch('net.login_handshake', $value)) {
         echo $value;
     }
     base_kvstore::instance('ecos')->store('net.login_handshake', md5(microtime()));
 }
Example #4
0
 function check_certid()
 {
     $params['certi_app'] = 'open.login';
     $this->Certi = base_certificate::get('certificate_id');
     $this->Token = base_certificate::get('token');
     $params['certificate_id'] = $this->Certi;
     $params['format'] = 'json';
     /** 增加反查参数result和反查基础地址url **/
     $code = md5(microtime());
     base_kvstore::instance('ecos')->store('net.login_handshake', $code);
     $params['result'] = $code;
     $obj_apps = app::get('base')->model('apps');
     $tmp = $obj_apps->getList('*', array('app_id' => 'base'));
     $app_xml = $tmp[0];
     $params['version'] = $app_xml['local_ver'];
     $params['url'] = kernel::base_url(1);
     /** end **/
     $token = $this->Token;
     $str = '';
     ksort($params);
     foreach ($params as $key => $value) {
         $str .= $value;
     }
     $params['certi_ac'] = md5($str . $token);
     $http = kernel::single('base_httpclient');
     $http->set_timeout(20);
     $result = $http->post(config::get('link.license_center'), $params);
     $api_result = stripslashes($result);
     $api_arr = json_decode($api_result, true);
     return $api_arr;
 }
Example #5
0
 function display($tmpl_file, $app_id = null)
 {
     array_unshift($this->_files, $tmpl_file);
     $this->_vars = $this->pagedata;
     if ($p = strpos($tmpl_file, ':')) {
         $object = kernel::service('tpl_source.' . substr($tmpl_file, 0, $p));
         if ($object) {
             $tmpl_file_path = substr($tmpl_file, $p + 1);
             $last_modified = $object->last_modified($tmpl_file_path);
         }
     } else {
         $tmpl_file = realpath(APP_DIR . '/' . ($app_id ? $app_id : $this->app->app_id) . '/view/' . $tmpl_file);
         $last_modified = filemtime($tmpl_file);
     }
     if (!$last_modified) {
         //无文件
     }
     $compile_id = $this->compile_id($tmpl_file);
     if ($this->force_compile || base_kvstore::instance('cache/template')->fetch($compile_id, $compile_code, $last_modified) === false) {
         if ($object) {
             $compile_code = $this->_compiler()->compile($object->get_file_contents($tmpl_file_path));
         } else {
             $compile_code = $this->_compiler()->compile_file($tmpl_file);
         }
         if ($compile_code !== false) {
             base_kvstore::instance('cache/template')->store($compile_id, $compile_code);
         }
     }
     eval('?>' . $compile_code);
     array_shift($this->_files);
 }
Example #6
0
File: goods.php Project: noikiy/snk
 /**
  * 不破坏缓存情况下的商品统计
  */
 public function counter($args = array())
 {
     $args = array_merge((array) $args, $this->req_params);
     $mdl_goods = app::get('b2c')->model('goods');
     $gid = $args['goods_id'];
     if (!$gid) {
         return false;
     }
     $db = vmc::database();
     $kv = base_kvstore::instance('b2c_counter');
     foreach ($args as $key => $value) {
         $value = intval($value);
         $update_sql = false;
         if ($value < 1) {
             $value = 1;
         }
         switch ($key) {
             case 'view_count':
                 $this->history($gid);
                 //UV型统计 24小时同一IP记录一次
                 $c_key = 'view_count_uv_' . $gid . '_' . base_request::get_remote_addr();
                 cacheobject::get($c_key, $time);
                 $kv->fetch('view_w_count_time', $vw_last_update);
                 if (!$time || strtotime('+1 day', $time) < time()) {
                     //获得周标记
                     if ($vw_last_update > strtotime('-1 week')) {
                         $update_sql = "UPDATE vmc_b2c_goods SET view_count=view_count+{$value},view_w_count=view_w_count+{$value} WHERE goods_id={$gid}";
                     } else {
                         $update_sql = "UPDATE vmc_b2c_goods SET view_count=view_count+{$value},view_w_count={$value} WHERE goods_id={$gid}";
                         $kv->store('view_w_count_time', time());
                     }
                     cacheobject::set($c_key, time(), 86400 + time());
                 }
                 break;
             case 'buy_count':
                 //验证
                 if (md5($gid . 'buy_count' . $value * 1024) != $args['buy_count_sign']) {
                     break;
                 }
                 //获得周标记
                 $kv->fetch('buy_w_count_time', $bw_last_update);
                 if ($bw_last_update > strtotime('-1 week')) {
                     $update_sql = "UPDATE vmc_b2c_goods SET buy_count=buy_count+{$value},buy_w_count=buy_w_count+{$value} WHERE goods_id={$gid}";
                 } else {
                     $update_sql = "UPDATE vmc_b2c_goods SET buy_count=buy_count+{$value},buy_w_count={$value} WHERE goods_id={$gid}";
                     $kv->store('buy_w_count_time', time());
                 }
                 break;
             case 'comment_count':
                 if (md5($gid . 'comment_count' . $value * 1024) == $args['comment_count_sign']) {
                     $update_sql = "UPDATE vmc_b2c_goods SET comment_count=comment_count+{$value} WHERE goods_id={$gid}";
                 }
                 break;
         }
         if ($update_sql) {
             logger::info($update_sql);
             $db->exec($update_sql, true);
         }
     }
 }
Example #7
0
 public function display_admin_widget($tpl, $fetch = false, $widgets_app)
 {
     $this->_vars = $this->pagedata;
     $tmpl_file = realpath($tpl);
     $cur_theme = kernel::single('wap_theme_base')->get_default();
     if ($tmpl_file || ECAE_MODE) {
         $last_modified = filemtime($tmpl_file);
         $compile_id = $this->compile_id($cur_theme . $tpl);
         if ($this->force_compile || !cachemgr::get($compile_id . $last_modified, $compile_code)) {
             $file_content = kernel::single('wap_theme_file')->get_widgets_content($cur_theme, $tpl, $widgets_app);
             $compile_code = $this->_compiler()->compile($file_content);
             if ($compile_code !== false) {
                 base_kvstore::instance('cache/theme_admin_widget')->store($compile_id, $compile_code);
             }
         }
         ob_start();
         eval('?>' . $compile_code);
         $content = ob_get_contents();
         ob_end_clean();
         $this->pre_display($content);
     } else {
         $obj = kernel::single('base_render');
         $content = "<p class='notice' style='margin:0.3em'>{$tpl}<strong><{t app='wap'}>模板不存在,请重新编辑<{/t}></strong></p>";
     }
     if ($fetch === true) {
         return $content;
     } else {
         echo $content;
     }
 }
Example #8
0
 /**
  * 获得jsapi_ticket  应该全局存储与更新
  * @return string
  */
 private function getJsApiTicket($bind_id)
 {
     if (base_kvstore::instance('weixin')->fetch('basic_jsapi_ticket_' . $bind_id, $jsapi_ticket) !== false) {
         logger::info('kv获取jsapi_ticket' . $jsapi_ticket);
         return $jsapi_ticket;
     } else {
         $accessToken = kernel::single('weixin_wechat')->get_basic_accesstoken($bind_id);
         // 如果是企业号用以下 URL 获取 ticket
         // $url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=$accessToken";
         $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token={$accessToken}";
         $httpclient = kernel::single('base_httpclient');
         $response = $httpclient->set_timeout(6)->get($url);
         $result = json_decode($response, true);
         $jsapi_ticket = $result['ticket'];
         if ($jsapi_ticket) {
             if (!base_kvstore::instance('weixin')->store('basic_jsapi_ticket_' . $bind_id, $jsapi_ticket, $result['expires_in'])) {
                 // 微信jsapi_ticket的有效期,单位为秒
                 logger::info("KVSTORE写入公众账号绑定id为: {$bind_id} 的jsapi_ticket错误");
             }
             logger::info('远程获取jsapi_ticket' . $jsapi_ticket);
             return $jsapi_ticket;
         } else {
             //todo : 错误提示
         }
     }
 }
Example #9
0
 public function __construct(&$app)
 {
     $api_info = base_rpc_service::$api_info;
     if ($api_info['from_node_id'] && $api_info['from_api_v']) {
         $obj_b2c_shop =& app::get('b2c')->model('shop');
         $shop_info = $obj_b2c_shop->getList('node_type', array('node_id' => $api_info['from_node_id'], 'status' => 'bind'));
         if (!($node_type = $shop_info[0]['node_type'])) {
             kernel::log('no data in b2c_shop! from_node_id: ' . $api_info['from_node_id']);
             trigger_error('server reject!', E_USER_ERROR);
         }
         base_kvstore::instance('b2c_apiv')->fetch('apiv.mapper', $apiv_mapper);
         if (!$apiv_mapper) {
             kernel::log('no apiv_mapper!');
             trigger_error('server reject!', E_USER_ERROR);
         }
         $local_apiv = $apiv_mapper[$node_type . '_' . $api_info['from_api_v']];
         if (!$local_apiv) {
             kernel::log('no data in apiv_mapper! node_type: ' . $node_type . ', node_apiv: ' . $api_info['from_api_v']);
             trigger_error('server reject!', E_USER_ERROR);
         }
     } else {
         $local_apiv = '2.0';
     }
     $this->apiv = $local_apiv;
 }
Example #10
0
 public function display_admin_widget($tpl, $fetch = false, $widgets_app)
 {
     $this->_vars = $this->pagedata;
     $tmpl_file = realpath($tpl);
     $cur_theme = kernel::single('site_theme_base')->get_default();
     if ($tmpl_file || ECAE_MODE) {
         $last_modified = filemtime($tmpl_file);
         $compile_id = $this->compile_id($cur_theme . $tpl);
         if ($this->force_compile || !cachemgr::get($compile_id . $last_modified, $compile_code)) {
             $file_content = kernel::single('site_theme_tmpl_file')->get_widgets_content($cur_theme, $tpl, $widgets_app);
             $compile_code = $this->_compiler()->compile($file_content);
             if ($compile_code !== false) {
                 base_kvstore::instance('cache/theme_admin_widget')->store($compile_id, $compile_code);
             }
         }
         ob_start();
         eval('?>' . $compile_code);
         $content = ob_get_contents();
         ob_end_clean();
         $this->pre_display($content);
     } else {
         $obj = kernel::single('base_render');
         $obj->pagedata['tpl'] = $tpl;
         $content = $obj->fetch('admin/theme/widgets_tpl_lost.html', 'site');
         //todo: 无模板提示
     }
     if ($fetch === true) {
         return $content;
     } else {
         echo $content;
     }
 }
Example #11
0
 public function delete_vcode($account, $type, $vcodeData)
 {
     $vcode = $this->randomkeys(6);
     $vcodeData['vcode'] = $vcode;
     $key = $this->get_vcode_key($account, $type);
     base_kvstore::instance('vcode/account')->store($key, $vcodeData, $this->ttl);
     return $vcodeData;
 }
Example #12
0
 private function _set_session($value, $ttl)
 {
     if (!config::get('cache.enabled', true)) {
         return base_kvstore::instance('sessions')->store($this->_get_cache_key(), $value, $ttl);
     } else {
         return cacheobject::set($this->_get_cache_key(), $value, $ttl + time());
     }
 }
Example #13
0
 public function destory()
 {
     if (!$this->_session_started) {
         return false;
     }
     $this->_session_started = false;
     return base_kvstore::instance('sessions')->store($this->_sess_id, array(), 1);
 }
Example #14
0
 private function _set_session($value, $ttl)
 {
     if (WITHOUT_CACHE === true) {
         return base_kvstore::instance('sessions')->store($this->_get_cache_key(), $value, $ttl);
     } else {
         return cacheobject::set($this->_get_cache_key(), $value, $ttl + time());
     }
 }
Example #15
0
 public function refresh_genurl_map()
 {
     $maps = app::get('wap')->model('route_statics')->getList('static, url', array('enable' => 'true'));
     foreach ($maps as $map) {
         $data[$map['url']] = $map['static'];
     }
     base_kvstore::instance($this->_kvprefix)->store('genurl_map', $data);
     app::get('wap')->setConf('statics.genurl_map_modify', microtime());
 }
Example #16
0
 public static function fetch_widgets_css($tmpl, &$css, &$last_modified)
 {
     if (base_kvstore::instance('wap_themes')->fetch('wap_widgets_css_' . $tmpl, $data)) {
         $last_modified = $data['last_modified'];
         $css = $data['css'];
         return true;
     }
     return false;
 }
Example #17
0
 function clear_by_app($app_id)
 {
     if (!$app_id) {
         return false;
     }
     if ($app_id == 'b2c') {
         base_kvstore::instance('b2c_apiv')->store('apiv.mapper', '');
     }
 }
Example #18
0
 public function get($key, $default = null)
 {
     $value = null;
     base_kvstore::instance('prism')->fetch($key, $value);
     if ($value == null) {
         return $default;
     } else {
         return $value;
     }
 }
Example #19
0
 function login_hankshake()
 {
     if (base_kvstore::instance('ecos')->fetch('net.login_handshake', $value)) {
         echo $value;
     } else {
         $code = md5(microtime());
         base_kvstore::instance('ecos')->store('net.login_handshake', $code);
         echo $code;
     }
 }
Example #20
0
 function __construct($prefix)
 {
     if (!isset(self::$_mongodb)) {
         $server = defined('MONGODB_SERVER_CONFIG') ? MONGODB_SERVER_CONFIG : "mongodb://localhost:27017";
         $option = defined('MONGODB_OPTION_CONFIG') ? eval(MONGODB_OPTION_CONFIG) : array("connect" => TRUE);
         $m = new MongoClient($server, $option);
         $db = $m->vmcshop_kvstore;
         self::$_mongodb = $db->selectCollection(base_kvstore::kvprefix());
     }
     $this->prefix = $prefix;
 }
Example #21
0
 public function get_prev_modify()
 {
     if (!isset($this->_prev_modify)) {
         if (base_kvstore::instance('system')->fetch($this->_get_prev_prefix(), $prev_modify) === true && !is_null($prev_modify)) {
             $this->_prev_modify = $prev_modify;
         } else {
             $this->_prev_modify = 1;
         }
     }
     return $this->_prev_modify;
 }
Example #22
0
 static function verify($key, $value)
 {
     $value = strtolower($value);
     $sess_id = vmc::singleton('base_session')->sess_id();
     $key = $key . $sess_id;
     base_kvstore::instance('vcode/image')->fetch($key, $vcode);
     if ($vcode == strval($value)) {
         return true;
     }
     return false;
 }
Example #23
0
 public function set_modified($type, $key, $time = 0)
 {
     $now = $time > 0 ? $time : time();
     if (is_array($key)) {
         foreach ($key as $k) {
             base_kvstore::instance('cache/expires/' . strtolower($type))->store(strtolower($k), $now);
         }
     } else {
         base_kvstore::instance('cache/expires/' . strtolower($type))->store(strtolower($key), $now);
     }
     return true;
 }
Example #24
0
 private function auto_delete_kvstore()
 {
     $rows = kernel::database()->select('SELECT `prefix`, `key` FROM sdb_base_kvstore WHERE ttl>0 AND (dateline+ttl)<' . time());
     foreach ($rows as $row) {
         $single = base_kvstore::instance($row['prefix']);
         $single->get_controller()->delete($row['key']);
         if (get_class($single->get_controller()) != 'base_kvstore_mysql') {
             kernel::single('base_kvstore_mysql', $row['prefix'])->delete($row['key']);
         }
         //todo: 删除持久化数据
     }
 }
Example #25
0
 function clear_by_app($app_id)
 {
     if (!$app_id) {
         return false;
     }
     base_kvstore::instance('apilist')->fetch('api_list_array', $apilist);
     foreach ((array) $apilist[$app_id] as $key) {
         app::get('base')->setConf($key, '');
     }
     $apilist[$app_id] = array();
     base_kvstore::instance('apilist')->store('api_list_array', $apilist);
 }
/**
 * ShopEx licence
 *
 * @copyright  Copyright (c) 2005-2010 ShopEx Technologies Inc. (http://www.shopex.cn)
 * @license  http://ecos.shopex.cn/ ShopEx License
 */
function theme_widget_items_category(&$setting)
{
    // 判断是否首页
    if (route::currentRouteName() == 'topc') {
        $returnData['isindex'] = true;
    }
    if (false && base_kvstore::instance('topc_category')->fetch('category_ex_vertical_widget.data', $cat_list)) {
        return $cat_list;
    }
    $returnData['data'] = app::get('topc')->rpcCall('category.cat.get.list', array('fields' => 'cat_id,cat_name'));
    return $returnData;
}
Example #27
0
 function upLicense()
 {
     if ($_FILES) {
         if ($_FILES['license']['name']) {
             $fileName = explode('.', $_FILES['license']['name']);
             if ('CER' != $fileName['1']) {
                 $this->begin();
                 $this->end(false, app::get('desktop')->_("证书格式不对"));
             } else {
                 $content = file_get_contents($_FILES['license']['tmp_name']);
                 list($certificate_id, $token) = explode('|||', $content);
                 /** 验证证书是否合法 **/
                 $sys_params = base_setup_config::deploy_info();
                 $code = md5(microtime());
                 base_kvstore::instance('ecos')->store('net.login_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'];
                 $conf = base_setup_config::deploy_info();
                 $data = array('certi_app' => 'open.login', 'certificate_id' => $certificate_id, 'url' => kernel::base_url(1), 'version' => '0.14', 'ver_detail' => $app_xml['version'], 'result' => $code, 'format' => 'json');
                 ksort($data);
                 foreach ($data as $key => $value) {
                     $str .= $value;
                 }
                 $data['certi_ac'] = md5($str . $token);
                 $http = kernel::single('base_httpclient');
                 $http->set_timeout(6);
                 $result = $http->post(LICENSE_CENTER, $data);
                 $result = json_decode($result, 1);
                 if ($result['res'] != 'succ') {
                     $this->begin();
                     $this->end(false, app::get('desktop')->_("上传证书无效"));
                 }
                 $result = base_certificate::set_certificate(array('certificate_id' => $certificate_id, 'token' => $token));
                 if (!$result) {
                     $this->begin();
                     $this->end(false, app::get('desktop')->_("证书重置失败,请先上传文件"));
                 } else {
                     $this->begin();
                     $this->end(true, app::get('desktop')->_("证书上传成功"));
                 }
             }
         } else {
             $this->begin();
             $this->end(false, app::get('desktop')->_("请选择要上传的文件"));
         }
     } else {
     }
 }
Example #28
0
 function __construct($prefix)
 {
     if (!isset(self::$_mongodb)) {
         $hosts = (array) config::get('kvstore.base_kvstore_mongodb.hosts', 'mongodb://localhost:27017');
         $options = config::get('kvstore.base_kvstore_mongodb.options', array("connect" => TRUE));
         $hosts = implode(',', $hosts);
         $m = new MongoClient($hosts, $options);
         $db = $m->ecos;
         //todo 需要改成config配置
         self::$_mongodb = $db->selectCollection(base_kvstore::kvprefix());
     }
     $this->prefix = $prefix;
 }
Example #29
0
 public function command_list()
 {
     base_kvstore::instance('apilist')->fetch('api_list_array', $apilist);
     foreach ((array) $apilist as $app_id => $row) {
         logger::info("提供API的APP:" . $app_id);
         foreach ((array) $row as $key) {
             $module = app::get('base')->getConf($key);
             $key = substr($key, 4);
             //logger::info("  -API类型为:".$module['apiType']);
             logger::info("  API:" . $key . '  ' . $module['title']);
         }
     }
 }
Example #30
0
 function __construct($prefix)
 {
     if (!isset(self::$_mongodb)) {
         $server = defined('MONGODB_SERVER_CONFIG') ? MONGODB_SERVER_CONFIG : "mongodb://localhost:27017";
         $option = defined('MONGODB_OPTION_CONFIG') ? eval(MONGODB_OPEION_CONFIG) : array("connect" => TRUE);
         $m = new Mongo($server, $option);
         // var_dump($m);exit;
         $db = $m->ecos;
         //todo 需要改成config配置
         self::$_mongodb = $db->selectCollection(base_kvstore::kvprefix());
     }
     $this->prefix = $prefix;
 }