You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

146 lines
4.4 KiB

<?php
/**
* ECTouch E-Commerce Project
* ============================================================================
* Copyright (c) 2014-2016 http://ectouch.cn All rights reserved.
* ----------------------------------------------------------------------------
* This is NOT a freeware, use is subject to license terms
* ----------------------------------------------------------------------------
* Licensed ( http://www.ectouch.cn/license )
* ----------------------------------------------------------------------------
*/
define('UC_CLIENT_VERSION', '1.6.0'); //note UCenter 版本标识
define('UC_CLIENT_RELEASE', '20110501');
define('API_SYNLOGIN', 1); //note 同步登录 API 接口开关
define('API_SYNLOGOUT', 1); //note 同步登出 API 接口开关
define('API_UPDATEHOSTS', 1); //note 更新域名解析缓存 开关
define('API_UPDATEAPPS', 1); //note 更新应用列表 开关
define('API_UPDATECLIENT', 1); //note 更新客户端缓存 开关
define('API_RETURN_SUCCEED', '1');
define('API_RETURN_FAILED', '-1');
define('API_RETURN_FORBIDDEN', '-2');
defined('ROOT_PATH') or define('ROOT_PATH', realpath('../') . '/');
//note 普通的 http 通知方式
if(!defined('IN_UC')) {
error_reporting(0);
require_once ROOT_PATH.'plugins/uc_client/config.inc.php';
require_once ROOT_PATH.'plugins/uc_client/client.php';
$code = @$_GET['code'];
parse_str(uc_authcode($code, 'DECODE', UC_KEY), $get);
$timestamp = time();
if($timestamp - $get['time'] > 3600) {
exit('Authracation has expiried');
}
if(empty($get)) {
exit('Invalid Request');
}
$action = $get['action'];
$post = uc_unserialize(file_get_contents('php://input'));
if(in_array($get['action'], array('test', 'synlogin', 'synlogout', 'updatehosts', 'updateapps', 'updateclient'))) {
$uc_note = new uc_note();
exit($uc_note->$get['action']($get, $post));
} else {
exit(API_RETURN_FAILED);
}
} else {
exit(API_RETURN_FAILED);
}
class uc_note {
var $db = '';
function uc_note() {
$this->db = $GLOBALS['db'];
}
function test($get, $post) {
return API_RETURN_SUCCEED;
}
function synlogin($get, $post) {
$uid = $get['uid'];
$username = $get['username'];
if(!API_SYNLOGIN) {
return API_RETURN_FORBIDDEN;
}
header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
// _setcookie('Example_auth', _authcode($uid."\t".$username, 'ENCODE'));
}
function synlogout($get, $post) {
if(!API_SYNLOGOUT) {
return API_RETURN_FORBIDDEN;
}
//note 同步登出 API 接口
header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
// _setcookie('Example_auth', '', -86400 * 365);
}
function updatehosts($get, $post) {
if(!API_UPDATEHOSTS) {
return API_RETURN_FORBIDDEN;
}
$cachefile = ROOT_PATH.'plugins/uc_client/data/cache/hosts.php';
$fp = fopen($cachefile, 'w');
$s = "<?php\r\n";
$s .= '$_CACHE[\'hosts\'] = '.var_export($post, TRUE).";\r\n";
fwrite($fp, $s);
fclose($fp);
return API_RETURN_SUCCEED;
}
function updateapps($get, $post) {
if(!API_UPDATEAPPS) {
return API_RETURN_FORBIDDEN;
}
$UC_API = $post['UC_API'];
//note 写 app 缓存文件
$cachefile = ROOT_PATH.'plugins/uc_client/data/cache/apps.php';
$fp = fopen($cachefile, 'w');
$s = "<?php\r\n";
$s .= '$_CACHE[\'apps\'] = '.var_export($post, TRUE).";\r\n";
fwrite($fp, $s);
fclose($fp);
//note 写配置文件
if(is_writeable(ROOT_PATH.'plugins/uc_client/config.inc.php')) {
$configfile = trim(file_get_contents(ROOT_PATH.'plugins/uc_client/config.inc.php'));
$configfile = substr($configfile, -2) == '?>' ? substr($configfile, 0, -2) : $configfile;
$configfile = preg_replace("/define\('UC_API',\s*'.*?'\);/i", "define('UC_API', '$UC_API');", $configfile);
if($fp = @fopen(ROOT_PATH.'plugins/uc_client/config.inc.php', 'w')) {
@fwrite($fp, trim($configfile));
@fclose($fp);
}
}
return API_RETURN_SUCCEED;
}
function updateclient($get, $post) {
if(!API_UPDATECLIENT) {
return API_RETURN_FORBIDDEN;
}
$cachefile = ROOT_PATH.'plugins/uc_client/data/cache/settings.php';
$fp = fopen($cachefile, 'w');
$s = "<?php\r\n";
$s .= '$_CACHE[\'settings\'] = '.var_export($post, TRUE).";\r\n";
fwrite($fp, $s);
fclose($fp);
return API_RETURN_SUCCEED;
}
}