1
|
-<?php
|
|
|
2
|
-use Action\WebAction;
|
|
|
3
|
-use WebPlugin\Cache;
|
|
|
4
|
-use Configs\WebCacheConfig;
|
|
|
5
|
-use WebPlugin\AuthCode;
|
|
|
6
|
-use Index\HomeModel;
|
|
|
7
|
-class ToolsController extends WebAction
|
|
|
8
|
-{
|
|
|
9
|
- public function init()
|
|
|
10
|
- {
|
|
|
11
|
- $valid_passwords = array ('test' => '123456');
|
|
|
12
|
- $valid_users = array_keys($valid_passwords);
|
|
|
13
|
- $user = $pass = '';
|
|
|
14
|
- if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_USER']))
|
|
|
15
|
- {
|
|
|
16
|
- $user = $_SERVER['PHP_AUTH_USER'];
|
|
|
17
|
- $pass = $_SERVER['PHP_AUTH_PW'];
|
|
|
18
|
- }
|
|
|
19
|
- $validated = (in_array($user, $valid_users)) && ($pass == $valid_passwords[$user]);
|
|
|
20
|
- if (!$validated) {
|
|
|
21
|
- header('WWW-Authenticate: Basic realm="www.yohobuy.com"');
|
|
|
22
|
- header('HTTP/1.0 401 Unauthorized');
|
|
|
23
|
- die ("Not authorized");
|
|
|
24
|
- }
|
|
|
25
|
- }
|
|
|
26
|
-
|
|
|
27
|
- /**
|
|
|
28
|
- * 缓存html
|
|
|
29
|
- *
|
|
|
30
|
- */
|
|
|
31
|
- public function cacheAction()
|
|
|
32
|
- {
|
|
|
33
|
- //频道=>key
|
|
|
34
|
- $channels = array(
|
|
|
35
|
- '导航' => WebCacheConfig::KEY_WEB_HOME_NAVBAR_DATA,
|
|
|
36
|
- '男生首页'=> WebCacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_'.HomeModel::CODE_BOYS_CHANNEL,
|
|
|
37
|
- '女生首页'=> WebCacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_'.HomeModel::CODE_GIRLS_CHANNEL,
|
|
|
38
|
- 'kids首页'=> WebCacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_'.HomeModel::CODE_KIDS_CHANNEL,
|
|
|
39
|
- 'lifestyle首页'=> WebCacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_'.HomeModel::CODE_LIFESTYLE_CHANNEL,
|
|
|
40
|
- );
|
|
|
41
|
- $html = '';
|
|
|
42
|
- foreach ($channels as $key => $val) {
|
|
|
43
|
- $url = '/tools/cacheclear?key='.urlencode(AuthCode::encode($val, 'yohobuy'));
|
|
|
44
|
- $html.= sprintf('<li><a href="%s" target="_blank">清除%s缓存</a></li>',$url, $key);
|
|
|
45
|
- }
|
|
|
46
|
- echo $html;
|
|
|
47
|
- }
|
|
|
48
|
-
|
|
|
49
|
- /**
|
|
|
50
|
- * 清除缓存
|
|
|
51
|
- *
|
|
|
52
|
- * @return json
|
|
|
53
|
- */
|
|
|
54
|
- public function cacheclearAction()
|
|
|
55
|
- {
|
|
|
56
|
- $key = $this->get('key');
|
|
|
57
|
- if(!empty($key)) {
|
|
|
58
|
- $key = AuthCode::decode($key, 'yohobuy');
|
|
|
59
|
- if(!empty($key)) {
|
|
|
60
|
- //导航清除
|
|
|
61
|
- if($key == WebCacheConfig::KEY_WEB_HOME_NAVBAR_DATA) {
|
|
|
62
|
- $list = array(HomeModel::COOKIE_NAME_BOYS, HomeModel::COOKIE_NAME_GIRLS, HomeModel::COOKIE_NAME_KIDS, HomeModel::COOKIE_NAME_LIFESTYLE);
|
|
|
63
|
- foreach ($list as $val) {
|
|
|
64
|
- Cache::delete($key.'_'.$val);
|
|
|
65
|
- }
|
|
|
66
|
- } else {
|
|
|
67
|
- Cache::delete($key);
|
|
|
68
|
- }
|
|
|
69
|
- echo '清除成功';
|
|
|
70
|
- }
|
|
|
71
|
- }
|
|
|
72
|
- }
|
|
|
73
|
-
|
|
|
74
|
- public function logAction()
|
|
|
75
|
- {
|
|
|
76
|
- print_r($_SERVER);
|
|
|
77
|
- }
|
|
|
78
|
-}
|
|
|
79
|
-
|
1
|
+<?php
|
|
|
2
|
+use Action\WebAction;
|
|
|
3
|
+use WebPlugin\Cache;
|
|
|
4
|
+use Configs\WebCacheConfig;
|
|
|
5
|
+use WebPlugin\AuthCode;
|
|
|
6
|
+use Index\HomeModel;
|
|
|
7
|
+use Api\Yohobuy;
|
|
|
8
|
+use Api\Sign;
|
|
|
9
|
+use LibModels\Web\Home\IndexData;
|
|
|
10
|
+class ToolsController extends WebAction
|
|
|
11
|
+{
|
|
|
12
|
+ public function init()
|
|
|
13
|
+ {
|
|
|
14
|
+ if(APPLICATION_ENV == 'production') {
|
|
|
15
|
+ $valid_passwords = array ('yoho' => '9646abcdef');
|
|
|
16
|
+ } else {
|
|
|
17
|
+ $valid_passwords = array ('test' => '123456');
|
|
|
18
|
+ }
|
|
|
19
|
+
|
|
|
20
|
+ $valid_users = array_keys($valid_passwords);
|
|
|
21
|
+ $user = $pass = '';
|
|
|
22
|
+ if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_USER']))
|
|
|
23
|
+ {
|
|
|
24
|
+ $user = $_SERVER['PHP_AUTH_USER'];
|
|
|
25
|
+ $pass = $_SERVER['PHP_AUTH_PW'];
|
|
|
26
|
+ }
|
|
|
27
|
+ $validated = (in_array($user, $valid_users)) && ($pass == $valid_passwords[$user]);
|
|
|
28
|
+ if (!$validated) {
|
|
|
29
|
+ header('WWW-Authenticate: Basic realm="www.yohobuy.com"');
|
|
|
30
|
+ header('HTTP/1.0 401 Unauthorized');
|
|
|
31
|
+ die ("Not authorized");
|
|
|
32
|
+ }
|
|
|
33
|
+ }
|
|
|
34
|
+
|
|
|
35
|
+ /**
|
|
|
36
|
+ * 工具首页
|
|
|
37
|
+ */
|
|
|
38
|
+ public function indexAction()
|
|
|
39
|
+ {
|
|
|
40
|
+ $html = '<br/><h2>工具首页</h2><br/>';
|
|
|
41
|
+ $channels = array('JAVA API'=>'/tools/javaapi', '缓存页面' =>'/tools/cache');
|
|
|
42
|
+ foreach($channels as $name => $url) {
|
|
|
43
|
+ $html .= sprintf('<li style="font-size:18px;"><a href="%s" target="_blank">%s</a></li>',$url, $name);
|
|
|
44
|
+ }
|
|
|
45
|
+ echo $html;
|
|
|
46
|
+ }
|
|
|
47
|
+
|
|
|
48
|
+ /**
|
|
|
49
|
+ * java api测试
|
|
|
50
|
+ *
|
|
|
51
|
+ */
|
|
|
52
|
+ public function javaapiAction()
|
|
|
53
|
+ {
|
|
|
54
|
+ $html = '<br/><h3>java api测试</h3><br/>';
|
|
|
55
|
+ $channels = array('获取资源位'=> $this->getResourceUrl(), '获取最新上架' =>'');
|
|
|
56
|
+ foreach($channels as $name => $url) {
|
|
|
57
|
+ $html .= sprintf('<li style="font-size:18px;"><a href="%s" target="_blank">%s</a></li>',$url, $name);
|
|
|
58
|
+ }
|
|
|
59
|
+ echo $html;
|
|
|
60
|
+ }
|
|
|
61
|
+
|
|
|
62
|
+ /**
|
|
|
63
|
+ * 获取资源位地址
|
|
|
64
|
+ *
|
|
|
65
|
+ * @return string
|
|
|
66
|
+ */
|
|
|
67
|
+ private function getResourceUrl()
|
|
|
68
|
+ {
|
|
|
69
|
+ $client_type ='web';
|
|
|
70
|
+ $content_code = '0c911d3000f52e8ca7cffb74f5864c29';
|
|
|
71
|
+ $params = Yohobuy::param();
|
|
|
72
|
+ $params['content_code'] = $content_code;
|
|
|
73
|
+ $params['client_type'] = $client_type;
|
|
|
74
|
+ $params['private_key'] = Yohobuy::$privateKeyList[$client_type];
|
|
|
75
|
+ $params['client_secret'] = Sign::getSign($params);
|
|
|
76
|
+ return Yohobuy::httpBuildQuery(Yohobuy::SERVICE_URL.IndexData::URL_OPERATIONS_RESOURCE_GET, $params);
|
|
|
77
|
+ }
|
|
|
78
|
+
|
|
|
79
|
+ /**
|
|
|
80
|
+ * 缓存html
|
|
|
81
|
+ */
|
|
|
82
|
+ public function cacheAction()
|
|
|
83
|
+ {
|
|
|
84
|
+ //频道=>key
|
|
|
85
|
+ $channels = array(
|
|
|
86
|
+ '导航' => WebCacheConfig::KEY_WEB_HOME_NAVBAR_DATA,
|
|
|
87
|
+ '男生首页'=> WebCacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_'.HomeModel::CODE_BOYS_CHANNEL,
|
|
|
88
|
+ '女生首页'=> WebCacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_'.HomeModel::CODE_GIRLS_CHANNEL,
|
|
|
89
|
+ 'kids首页'=> WebCacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_'.HomeModel::CODE_KIDS_CHANNEL,
|
|
|
90
|
+ 'lifestyle首页'=> WebCacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_'.HomeModel::CODE_LIFESTYLE_CHANNEL,
|
|
|
91
|
+ );
|
|
|
92
|
+ $html = '<br/><h3>缓存页面</h3><br/>';
|
|
|
93
|
+ foreach ($channels as $key => $val) {
|
|
|
94
|
+ $url = '/tools/cacheclear?key='.urlencode(AuthCode::encode($val, 'yohobuy'));
|
|
|
95
|
+ $html.= sprintf('<li><a href="%s" target="_blank">清除%s缓存</a></li>',$url, $key);
|
|
|
96
|
+ }
|
|
|
97
|
+ echo $html;
|
|
|
98
|
+ }
|
|
|
99
|
+
|
|
|
100
|
+ /**
|
|
|
101
|
+ * 清除缓存
|
|
|
102
|
+ *
|
|
|
103
|
+ * @return json
|
|
|
104
|
+ */
|
|
|
105
|
+ public function cacheclearAction()
|
|
|
106
|
+ {
|
|
|
107
|
+ $key = $this->get('key');
|
|
|
108
|
+ if(!empty($key)) {
|
|
|
109
|
+ $key = AuthCode::decode($key, 'yohobuy');
|
|
|
110
|
+ if(!empty($key)) {
|
|
|
111
|
+ //导航清除
|
|
|
112
|
+ if($key == WebCacheConfig::KEY_WEB_HOME_NAVBAR_DATA) {
|
|
|
113
|
+ $list = array(HomeModel::COOKIE_NAME_BOYS, HomeModel::COOKIE_NAME_GIRLS, HomeModel::COOKIE_NAME_KIDS, HomeModel::COOKIE_NAME_LIFESTYLE);
|
|
|
114
|
+ foreach ($list as $val) {
|
|
|
115
|
+ Cache::delete($key.'_'.$val);
|
|
|
116
|
+ }
|
|
|
117
|
+ } else {
|
|
|
118
|
+ Cache::delete($key);
|
|
|
119
|
+ }
|
|
|
120
|
+ echo '清除成功';
|
|
|
121
|
+ }
|
|
|
122
|
+ }
|
|
|
123
|
+ }
|
|
|
124
|
+
|
|
|
125
|
+ public function logAction()
|
|
|
126
|
+ {
|
|
|
127
|
+ print_r($_SERVER);
|
|
|
128
|
+ }
|
|
|
129
|
+}
|
|
|
130
|
+
|
80
|
?> |
131
|
?> |