commit | author | age
|
19351a
|
1 |
<?php |
B |
2 |
/** |
|
3 |
* UCenter API |
|
4 |
* =========================================================== |
|
5 |
* |
|
6 |
|
|
7 |
* ---------------------------------------------------------- |
|
8 |
|
|
9 |
* ========================================================== |
|
10 |
|
|
11 |
* $Id: uc.php 17217 2011-01-19 06:29:08Z $ |
|
12 |
*/ |
|
13 |
|
|
14 |
define('UC_CLIENT_VERSION', '1.5.0'); //note UCenter 版本标识 |
|
15 |
define('UC_CLIENT_RELEASE', '20081031'); |
|
16 |
|
|
17 |
define('API_DELETEUSER', 1); //note 用户删除 API 接口开关 |
|
18 |
define('API_RENAMEUSER', 1); //note 用户改名 API 接口开关 |
|
19 |
define('API_GETTAG', 1); //note 获取标签 API 接口开关 |
|
20 |
define('API_SYNLOGIN', 1); //note 同步登录 API 接口开关 |
|
21 |
define('API_SYNLOGOUT', 1); //note 同步登出 API 接口开关 |
|
22 |
define('API_UPDATEPW', 1); //note 更改用户密码 开关 |
|
23 |
define('API_UPDATEBADWORDS', 1);//note 更新关键字列表 开关 |
|
24 |
define('API_UPDATEHOSTS', 1); //note 更新域名解析缓存 开关 |
|
25 |
define('API_UPDATEAPPS', 1); //note 更新应用列表 开关 |
|
26 |
define('API_UPDATECLIENT', 1); //note 更新客户端缓存 开关 |
|
27 |
define('API_UPDATECREDIT', 1); //note 更新用户积分 开关 |
|
28 |
define('API_GETCREDITSETTINGS', 1); //note 向 UCenter 提供积分设置 开关 |
|
29 |
define('API_GETCREDIT', 1); //note 获取用户的某项积分 开关 |
|
30 |
define('API_UPDATECREDITSETTINGS', 1); //note 更新应用积分设置 开关 |
|
31 |
|
|
32 |
define('API_RETURN_SUCCEED', '1'); |
|
33 |
define('API_RETURN_FAILED', '-1'); |
|
34 |
define('API_RETURN_FORBIDDEN', '-2'); |
|
35 |
|
|
36 |
define('IN_ECS', TRUE); |
|
37 |
require './init.php'; |
|
38 |
//数据验证 |
|
39 |
if(!defined('IN_UC')) |
|
40 |
{ |
|
41 |
error_reporting(0); |
|
42 |
set_magic_quotes_runtime(0); |
|
43 |
defined('MAGIC_QUOTES_GPC') || define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc()); |
|
44 |
|
|
45 |
$_DCACHE = $get = $post = array(); |
|
46 |
|
|
47 |
$code = @$_GET['code']; |
|
48 |
parse_str(_authcode($code, 'DECODE', UC_KEY), $get); |
|
49 |
if(MAGIC_QUOTES_GPC) |
|
50 |
{ |
|
51 |
$get = _stripslashes($get); |
|
52 |
} |
|
53 |
|
|
54 |
$timestamp = time(); |
|
55 |
if($timestamp - $get['time'] > 3600) |
|
56 |
{ |
|
57 |
exit('Authracation has expiried'); |
|
58 |
} |
|
59 |
if(empty($get)) |
|
60 |
{ |
|
61 |
exit('Invalid Request'); |
|
62 |
} |
|
63 |
} |
|
64 |
|
|
65 |
$action = $get['action']; |
|
66 |
include(ROOT_PATH . 'uc_client/lib/xml.class.php'); |
|
67 |
$post = xml_unserialize(file_get_contents('php://input')); |
|
68 |
|
|
69 |
if(in_array($get['action'], array('test', 'deleteuser', 'renameuser', 'gettag', 'synlogin', 'synlogout', 'updatepw', 'updatebadwords', 'updatehosts', 'updateapps', 'updateclient', 'updatecredit', 'getcreditsettings', 'updatecreditsettings'))) |
|
70 |
{ |
|
71 |
$uc_note = new uc_note(); |
|
72 |
exit($uc_note->$get['action']($get, $post)); |
|
73 |
} |
|
74 |
else |
|
75 |
{ |
|
76 |
exit(API_RETURN_FAILED); |
|
77 |
} |
|
78 |
|
|
79 |
$ecs_url = str_replace('/api', '', $ecs->url()); |
|
80 |
|
|
81 |
class uc_note |
|
82 |
{ |
|
83 |
var $db = ''; |
|
84 |
var $tablepre = ''; |
|
85 |
var $appdir = ''; |
|
86 |
|
|
87 |
function _serialize($arr, $htmlon = 0) |
|
88 |
{ |
|
89 |
if(!function_exists('xml_serialize')) |
|
90 |
{ |
|
91 |
include(ROOT_PATH . 'uc_client/lib/xml.class.php'); |
|
92 |
} |
|
93 |
return xml_serialize($arr, $htmlon); |
|
94 |
} |
|
95 |
|
|
96 |
function uc_note() |
|
97 |
{ |
|
98 |
$this->appdir = ROOT_PATH; |
|
99 |
$this->db = $GLOBALS['db']; |
|
100 |
} |
|
101 |
|
|
102 |
function test($get, $post) |
|
103 |
{ |
|
104 |
return API_RETURN_SUCCEED; |
|
105 |
} |
|
106 |
|
|
107 |
function deleteuser($get, $post) |
|
108 |
{ |
|
109 |
$uids = $get['ids']; |
|
110 |
if(!API_DELETEUSER) |
|
111 |
{ |
|
112 |
return API_RETURN_FORBIDDEN; |
|
113 |
} |
|
114 |
|
|
115 |
if (delete_user($uids)) |
|
116 |
{ |
|
117 |
return API_RETURN_SUCCEED; |
|
118 |
} |
|
119 |
} |
|
120 |
|
|
121 |
function renameuser($get, $post) |
|
122 |
{ |
|
123 |
$uid = $get['uid']; |
|
124 |
$usernameold = $get['oldusername']; |
|
125 |
$usernamenew = $get['newusername']; |
|
126 |
if(!API_RENAMEUSER) |
|
127 |
{ |
|
128 |
return API_RETURN_FORBIDDEN; |
|
129 |
} |
|
130 |
$this->db->query("UPDATE " . $GLOBALS['ecs']->table("users") . " SET user_name='$usernamenew' WHERE user_id='$uid'"); |
|
131 |
$this->db->query("UPDATE " . $GLOBALS['ecs']->table("affiliate_log") . " SET user_name='$usernamenew' WHERE user_name='$usernameold'"); |
|
132 |
$this->db->query("UPDATE " . $GLOBALS['ecs']->table("comment") . " SET user_name='$usernamenew' WHERE user_name='$usernameold'"); |
|
133 |
$this->db->query("UPDATE " . $GLOBALS['ecs']->table("feedback") . " SET user_name='$usernamenew' WHERE user_name='$usernameold'"); |
|
134 |
clear_cache_files(); |
|
135 |
return API_RETURN_SUCCEED; |
|
136 |
} |
|
137 |
|
|
138 |
function gettag($get, $post) |
|
139 |
{ |
|
140 |
$name = $get['id']; |
|
141 |
if(!API_GETTAG) |
|
142 |
{ |
|
143 |
return API_RETURN_FORBIDDEN; |
|
144 |
} |
|
145 |
$tags = fetch_tag($name); |
|
146 |
$return = array($name, $tags); |
|
147 |
include_once(ROOT_PATH . 'uc_client/client.php'); |
|
148 |
return uc_serialize($return, 1); |
|
149 |
} |
|
150 |
|
|
151 |
function synlogin($get, $post) |
|
152 |
{ |
|
153 |
$uid = intval($get['uid']); |
|
154 |
$username = $get['username']; |
|
155 |
if(!API_SYNLOGIN) |
|
156 |
{ |
|
157 |
return API_RETURN_FORBIDDEN; |
|
158 |
} |
|
159 |
header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"'); |
|
160 |
set_login($uid, $username); |
|
161 |
} |
|
162 |
|
|
163 |
function synlogout($get, $post) |
|
164 |
{ |
|
165 |
if(!API_SYNLOGOUT) |
|
166 |
{ |
|
167 |
return API_RETURN_FORBIDDEN; |
|
168 |
} |
|
169 |
|
|
170 |
header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"'); |
|
171 |
set_cookie(); |
|
172 |
set_session(); |
|
173 |
} |
|
174 |
|
|
175 |
function updatepw($get, $post) |
|
176 |
{ |
|
177 |
if(!API_UPDATEPW) |
|
178 |
{ |
|
179 |
return API_RETURN_FORBIDDEN; |
|
180 |
} |
|
181 |
$username = $get['username']; |
|
182 |
#$password = md5($get['password']); |
|
183 |
$newpw = md5(time().rand(100000, 999999)); |
|
184 |
$this->db->query("UPDATE " . $GLOBALS['ecs']->table('users') . " SET password='$newpw' WHERE user_name='$username'"); |
|
185 |
return API_RETURN_SUCCEED; |
|
186 |
} |
|
187 |
|
|
188 |
function updatebadwords($get, $post) |
|
189 |
{ |
|
190 |
if(!API_UPDATEBADWORDS) |
|
191 |
{ |
|
192 |
return API_RETURN_FORBIDDEN; |
|
193 |
} |
|
194 |
$cachefile = $this->appdir.'./uc_client/data/cache/badwords.php'; |
|
195 |
$fp = fopen($cachefile, 'w'); |
|
196 |
$data = array(); |
|
197 |
if(is_array($post)) { |
|
198 |
foreach($post as $k => $v) { |
|
199 |
$data['findpattern'][$k] = $v['findpattern']; |
|
200 |
$data['replace'][$k] = $v['replacement']; |
|
201 |
} |
|
202 |
} |
|
203 |
$s = "<?php\r\n"; |
|
204 |
$s .= '$_CACHE[\'badwords\'] = '.var_export($data, TRUE).";\r\n"; |
|
205 |
fwrite($fp, $s); |
|
206 |
fclose($fp); |
|
207 |
return API_RETURN_SUCCEED; |
|
208 |
} |
|
209 |
|
|
210 |
function updatehosts($get, $post) |
|
211 |
{ |
|
212 |
if(!API_UPDATEHOSTS) |
|
213 |
{ |
|
214 |
return API_RETURN_FORBIDDEN; |
|
215 |
} |
|
216 |
$cachefile = $this->appdir . './uc_client/data/cache/hosts.php'; |
|
217 |
$fp = fopen($cachefile, 'w'); |
|
218 |
$s = "<?php\r\n"; |
|
219 |
$s .= '$_CACHE[\'hosts\'] = '.var_export($post, TRUE).";\r\n"; |
|
220 |
fwrite($fp, $s); |
|
221 |
fclose($fp); |
|
222 |
return API_RETURN_SUCCEED; |
|
223 |
} |
|
224 |
|
|
225 |
function updateapps($get, $post) |
|
226 |
{ |
|
227 |
if(!API_UPDATEAPPS) |
|
228 |
{ |
|
229 |
return API_RETURN_FORBIDDEN; |
|
230 |
} |
|
231 |
$UC_API = $post['UC_API']; |
|
232 |
|
|
233 |
$cachefile = $this->appdir . './uc_client/data/cache/apps.php'; |
|
234 |
$fp = fopen($cachefile, 'w'); |
|
235 |
$s = "<?php\r\n"; |
|
236 |
$s .= '$_CACHE[\'apps\'] = '.var_export($post, TRUE).";\r\n"; |
|
237 |
fwrite($fp, $s); |
|
238 |
fclose($fp); |
|
239 |
#clear_cache_files(); |
|
240 |
return API_RETURN_SUCCEED; |
|
241 |
} |
|
242 |
|
|
243 |
function updateclient($get, $post) |
|
244 |
{ |
|
245 |
if(!API_UPDATECLIENT) |
|
246 |
{ |
|
247 |
return API_RETURN_FORBIDDEN; |
|
248 |
} |
|
249 |
$cachefile = $this->appdir . './uc_client/data/cache/settings.php'; |
|
250 |
$fp = fopen($cachefile, 'w'); |
|
251 |
$s = "<?php\r\n"; |
|
252 |
$s .= '$_CACHE[\'settings\'] = '.var_export($post, TRUE).";\r\n"; |
|
253 |
fwrite($fp, $s); |
|
254 |
fclose($fp); |
|
255 |
return API_RETURN_SUCCEED; |
|
256 |
} |
|
257 |
|
|
258 |
function updatecredit($get, $post) |
|
259 |
{ |
|
260 |
if(!API_UPDATECREDIT) |
|
261 |
{ |
|
262 |
return API_RETURN_FORBIDDEN; |
|
263 |
} |
|
264 |
$cfg = unserialize($GLOBALS['_CFG']['integrate_config']); |
|
265 |
$credit = intval($get['credit']); |
|
266 |
$amount = intval($get['amount']); |
|
267 |
$uid = intval($get['uid']); |
|
268 |
$points = array(0 => 'rank_points', 1 => 'pay_points'); |
|
269 |
$sql = "UPDATE " . $GLOBALS['ecs']-> table('users') . " SET {$points[$credit]} = {$points[$credit]} + '$amount' WHERE user_id = $uid"; |
|
270 |
$this->db->query($sql); |
|
271 |
if ($this->db->affected_rows() <= 0) |
|
272 |
{ |
|
273 |
return API_RETURN_FAILED; |
|
274 |
} |
|
275 |
$sql = "INSERT INTO " . $GLOBALS['ecs']->table('account_log') . "(user_id, {$points[$credit]}, change_time, change_desc, change_type)" . |
|
276 |
" VALUES ('$uid', '$amount', '". gmtime() ."', '" . $cfg['uc_lang']['exchange'] . "', '99')"; |
|
277 |
$this->db->query($sql); |
|
278 |
return API_RETURN_SUCCEED; |
|
279 |
} |
|
280 |
|
|
281 |
function getcredit($get, $post) |
|
282 |
{ |
|
283 |
if(!API_GETCREDIT) |
|
284 |
{ |
|
285 |
return API_RETURN_FORBIDDEN; |
|
286 |
} |
|
287 |
|
|
288 |
/*$uid = intval($get['uid']); |
|
289 |
$credit = intval($get['credit']); |
|
290 |
return $credit >= 1 && $credit <= 8 ? $this->db->result_first("SELECT extcredits$credit FROM ".$this->tablepre."members WHERE uid='$uid'") : 0;*/ |
|
291 |
} |
|
292 |
|
|
293 |
function getcreditsettings($get, $post) |
|
294 |
{ |
|
295 |
if(!API_GETCREDITSETTINGS) |
|
296 |
{ |
|
297 |
return API_RETURN_FORBIDDEN; |
|
298 |
} |
|
299 |
$cfg = unserialize($GLOBALS['_CFG']['integrate_config']); |
|
300 |
$credits = $cfg['uc_lang']['credits']; |
|
301 |
include_once(ROOT_PATH . 'uc_client/client.php'); |
|
302 |
return uc_serialize($credits); |
|
303 |
} |
|
304 |
|
|
305 |
function updatecreditsettings($get, $post) |
|
306 |
{ |
|
307 |
if(!API_UPDATECREDITSETTINGS) |
|
308 |
{ |
|
309 |
return API_RETURN_FORBIDDEN; |
|
310 |
} |
|
311 |
|
|
312 |
$outextcredits = array(); |
|
313 |
foreach($get['credit'] as $appid => $credititems) |
|
314 |
{ |
|
315 |
if($appid == UC_APPID) |
|
316 |
{ |
|
317 |
foreach($credititems as $value) |
|
318 |
{ |
|
319 |
$outextcredits[] = array |
|
320 |
( |
|
321 |
'appiddesc' => $value['appiddesc'], |
|
322 |
'creditdesc' => $value['creditdesc'], |
|
323 |
'creditsrc' => $value['creditsrc'], |
|
324 |
'title' => $value['title'], |
|
325 |
'unit' => $value['unit'], |
|
326 |
'ratio' => $value['ratio'] |
|
327 |
); |
|
328 |
} |
|
329 |
} |
|
330 |
} |
|
331 |
$this->db->query("UPDATE " . $GLOBALS['ecs']->table("shop_config") . " SET value='".serialize($outextcredits)."' WHERE code='points_rule'"); |
|
332 |
return API_RETURN_SUCCEED; |
|
333 |
} |
|
334 |
} |
|
335 |
|
|
336 |
/** |
|
337 |
* 删除用户接口函数 |
|
338 |
* |
|
339 |
* @access public |
|
340 |
* @param int $uids |
|
341 |
* @return void |
|
342 |
*/ |
|
343 |
function delete_user($uids = '') |
|
344 |
{ |
|
345 |
if (empty($uids)) |
|
346 |
{ |
|
347 |
return; |
|
348 |
} |
|
349 |
else |
|
350 |
{ |
|
351 |
$uids = stripslashes($uids); |
|
352 |
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('users') . " WHERE user_id IN ($uids)"; |
|
353 |
$result = $GLOBALS['db']->query($sql); |
|
354 |
return true; |
|
355 |
} |
|
356 |
} |
|
357 |
|
|
358 |
/** |
|
359 |
* 设置用户登陆 |
|
360 |
* |
|
361 |
* @access public |
|
362 |
* @param int $uid |
|
363 |
* @return void |
|
364 |
*/ |
|
365 |
function set_login($user_id = '', $user_name = '') |
|
366 |
{ |
|
367 |
if (empty($user_id)) |
|
368 |
{ |
|
369 |
return ; |
|
370 |
} |
|
371 |
else |
|
372 |
{ |
|
373 |
$sql = "SELECT user_name, email FROM " . $GLOBALS['ecs']->table('users') . " WHERE user_id='$user_id' LIMIT 1"; |
|
374 |
$row = $GLOBALS['db']->getRow($sql); |
|
375 |
if ($row) |
|
376 |
{ |
|
377 |
set_cookie($user_id, $row['user_name'], $row['email']); |
|
378 |
set_session($user_id, $row['user_name'], $row['email']); |
|
379 |
include_once(ROOT_PATH . 'includes/lib_main.php'); |
|
380 |
update_user_info(); |
|
381 |
} |
|
382 |
else |
|
383 |
{ |
|
384 |
include_once(ROOT_PATH . 'uc_client/client.php'); |
|
385 |
if($data = uc_get_user($user_name)) |
|
386 |
{ |
|
387 |
list($uid, $uname, $email) = $data; |
|
388 |
$sql = "REPLACE INTO " . $GLOBALS['ecs']->table('users') ."(user_id, user_name, email) VALUES('$uid', '$uname', '$email')"; |
|
389 |
$GLOBALS['db']->query($sql); |
|
390 |
set_login($uid); |
|
391 |
} |
|
392 |
else |
|
393 |
{ |
|
394 |
return false; |
|
395 |
} |
|
396 |
} |
|
397 |
} |
|
398 |
} |
|
399 |
|
|
400 |
/** |
|
401 |
* 设置cookie |
|
402 |
* |
|
403 |
* @access public |
|
404 |
* @param |
|
405 |
* @return void |
|
406 |
*/ |
|
407 |
function set_cookie($user_id='', $user_name = '', $email = '') |
|
408 |
{ |
|
409 |
if (empty($user_id)) |
|
410 |
{ |
|
411 |
/* 摧毁cookie */ |
|
412 |
$time = time() - 3600; |
|
413 |
setcookie('ECS[user_id]', '', $time); |
|
414 |
setcookie('ECS[username]', '', $time); |
|
415 |
setcookie('ECS[email]', '', $time); |
|
416 |
} |
|
417 |
else |
|
418 |
{ |
|
419 |
/* 设置cookie */ |
|
420 |
$time = time() + 3600 * 24 * 30; |
|
421 |
setcookie("ECS[user_id]", $user_id, $time, $GLOBALS['cookie_path'], $GLOBALS['cookie_domain']); |
|
422 |
setcookie("ECS[username]", $user_name, $time, $GLOBALS['cookie_path'], $GLOBALS['cookie_domain']); |
|
423 |
setcookie("ECS[email]", $email, $time, $GLOBALS['cookie_path'], $GLOBALS['cookie_domain']); |
|
424 |
} |
|
425 |
} |
|
426 |
|
|
427 |
/** |
|
428 |
* 设置指定用户SESSION |
|
429 |
* |
|
430 |
* @access public |
|
431 |
* @param |
|
432 |
* @return void |
|
433 |
*/ |
|
434 |
function set_session ($user_id = '', $user_name = '', $email = '') |
|
435 |
{ |
|
436 |
if (empty($user_id)) |
|
437 |
{ |
|
438 |
$GLOBALS['sess']->destroy_session(); |
|
439 |
} |
|
440 |
else |
|
441 |
{ |
|
442 |
$_SESSION['user_id'] = $user_id; |
|
443 |
$_SESSION['user_name'] = $user_name; |
|
444 |
$_SESSION['email'] = $email; |
|
445 |
} |
|
446 |
} |
|
447 |
|
|
448 |
/** |
|
449 |
* 获取EC的TAG数据 |
|
450 |
* |
|
451 |
* @access public |
|
452 |
* @param string $tagname |
|
453 |
* @param int $num 获取的数量 默认取最新的100条 |
|
454 |
* @return array |
|
455 |
*/ |
|
456 |
function fetch_tag($tagname, $num=100) |
|
457 |
{ |
|
458 |
$rewrite = intval($GLOBALS['_CFG']['rewrite']) > 0; |
|
459 |
$sql = "SELECT t.*, u.user_name, g.goods_name, g.goods_img, g.shop_price FROM " . $GLOBALS['ecs']->table('tag') . " as t, " . $GLOBALS['ecs']->table('users') ." as u, " . |
|
460 |
$GLOBALS['ecs']->table('goods') ." as g WHERE tag_words = '$tagname' AND t.user_id = u.user_id AND g.goods_id = t.goods_id ORDER BY t.tag_id DESC LIMIT " . $num; |
|
461 |
$arr = $GLOBALS['db']->getAll($sql); |
|
462 |
$tag_list = array(); |
|
463 |
foreach ($arr as $k=>$v) |
|
464 |
{ |
|
465 |
$tag_list[$k]['goods_name'] = $v['goods_name']; |
|
466 |
$tag_list[$k]['uid'] = $v['user_id']; |
|
467 |
$tag_list[$k]['username'] = $v['user_name']; |
|
468 |
$tag_list[$k]['dateline'] = time(); |
|
469 |
$tag_list[$k]['url'] = $GLOBALS['ecs_url'] . 'goods.php?id=' . $v['goods_id']; |
|
470 |
$tag_list[$k]['image'] = $GLOBALS['ecs_url'] . $v['goods_img']; |
|
471 |
$tag_list[$k]['goods_price'] = $v['shop_price']; |
|
472 |
} |
|
473 |
|
|
474 |
return $tag_list; |
|
475 |
} |
|
476 |
|
|
477 |
/** |
|
478 |
* uc自带函数1 |
|
479 |
* |
|
480 |
* @access public |
|
481 |
* @param string $string |
|
482 |
* |
|
483 |
* @return string $string |
|
484 |
*/ |
|
485 |
function _setcookie($var, $value, $life = 0, $prefix = 1) |
|
486 |
{ |
|
487 |
global $cookiepre, $cookiedomain, $cookiepath, $timestamp, $_SERVER; |
|
488 |
setcookie(($prefix ? $cookiepre : '').$var, $value, |
|
489 |
$life ? $timestamp + $life : 0, $cookiepath, |
|
490 |
$cookiedomain, $_SERVER['SERVER_PORT'] == 443 ? 1 : 0); |
|
491 |
} |
|
492 |
|
|
493 |
/** |
|
494 |
* uc自带函数2 |
|
495 |
* |
|
496 |
* @access public |
|
497 |
* |
|
498 |
* @return string $string |
|
499 |
*/ |
|
500 |
function _authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) |
|
501 |
{ |
|
502 |
$ckey_length = 4; |
|
503 |
$key = md5($key ? $key : UC_KEY); |
|
504 |
$keya = md5(substr($key, 0, 16)); |
|
505 |
$keyb = md5(substr($key, 16, 16)); |
|
506 |
$keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : ''; |
|
507 |
|
|
508 |
$cryptkey = $keya.md5($keya.$keyc); |
|
509 |
$key_length = strlen($cryptkey); |
|
510 |
|
|
511 |
$string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string; |
|
512 |
$string_length = strlen($string); |
|
513 |
|
|
514 |
$result = ''; |
|
515 |
$box = range(0, 255); |
|
516 |
|
|
517 |
$rndkey = array(); |
|
518 |
for($i = 0; $i <= 255; $i++) |
|
519 |
{ |
|
520 |
$rndkey[$i] = ord($cryptkey[$i % $key_length]); |
|
521 |
} |
|
522 |
|
|
523 |
for($j = $i = 0; $i < 256; $i++) |
|
524 |
{ |
|
525 |
$j = ($j + $box[$i] + $rndkey[$i]) % 256; |
|
526 |
$tmp = $box[$i]; |
|
527 |
$box[$i] = $box[$j]; |
|
528 |
$box[$j] = $tmp; |
|
529 |
} |
|
530 |
|
|
531 |
for($a = $j = $i = 0; $i < $string_length; $i++) |
|
532 |
{ |
|
533 |
$a = ($a + 1) % 256; |
|
534 |
$j = ($j + $box[$a]) % 256; |
|
535 |
$tmp = $box[$a]; |
|
536 |
$box[$a] = $box[$j]; |
|
537 |
$box[$j] = $tmp; |
|
538 |
$result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256])); |
|
539 |
} |
|
540 |
|
|
541 |
if($operation == 'DECODE') |
|
542 |
{ |
|
543 |
if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) |
|
544 |
{ |
|
545 |
return substr($result, 26); |
|
546 |
} |
|
547 |
else |
|
548 |
{ |
|
549 |
return ''; |
|
550 |
} |
|
551 |
} |
|
552 |
else |
|
553 |
{ |
|
554 |
return $keyc.str_replace('=', '', base64_encode($result)); |
|
555 |
} |
|
556 |
} |
|
557 |
|
|
558 |
/** |
|
559 |
* uc自带函数3 |
|
560 |
* |
|
561 |
* @access public |
|
562 |
* @param string $string |
|
563 |
* |
|
564 |
* @return string $string |
|
565 |
*/ |
|
566 |
function _stripslashes($string) |
|
567 |
{ |
|
568 |
if(is_array($string)) |
|
569 |
{ |
|
570 |
foreach($string as $key => $val) |
|
571 |
{ |
|
572 |
$string[$key] = _stripslashes($val); |
|
573 |
} |
|
574 |
} |
|
575 |
else |
|
576 |
{ |
|
577 |
$string = stripslashes($string); |
|
578 |
} |
|
579 |
return $string; |
|
580 |
} |
|
581 |
|
|
582 |
?> |