Passed
Push — v6 ( 95b370...25ce72 )
by 光春
03:13
created
src/service/taobao/bin/top/security/SecurityClient.php 1 patch
Spacing   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -8,16 +8,16 @@  discard block
 block discarded – undo
8 8
 
9 9
 	class SecurityClient
10 10
 	{
11
-		private $topClient ;
12
-		private $randomNum ;
11
+		private $topClient;
12
+		private $randomNum;
13 13
 		private $securityUtil;
14 14
 		private $cacheClient = null;
15 15
 
16 16
 		function __construct($client, $random)
17 17
 		{
18 18
 
19
-			define('APP_SECRET_TYPE','2');
20
-			define('APP_USER_SECRET_TYPE','3');
19
+			define('APP_SECRET_TYPE', '2');
20
+			define('APP_USER_SECRET_TYPE', '3');
21 21
 
22 22
 			$this->topClient = $client;
23 23
 			$this->randomNum = $random;
@@ -38,9 +38,9 @@  discard block
 block discarded – undo
38 38
 	     * @see #search(String, String, String, Long)
39 39
 	     * @return
40 40
 	     */
41
-		function searchPrevious($data,$type,$session = null)
41
+		function searchPrevious($data, $type, $session = null)
42 42
 		{
43
-			return $this->searchInner($data,$type,$session,-1);
43
+			return $this->searchInner($data, $type, $session, -1);
44 44
 		}
45 45
 
46 46
 	    /**
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
 	     * @see #search(String, String, String, Long)
50 50
 	     * @return
51 51
 	     */
52
-		function search($data,$type,$session = null)
52
+		function search($data, $type, $session = null)
53 53
 		{
54
-			return $this->searchInner($data,$type,$session,null);
54
+			return $this->searchInner($data, $type, $session, null);
55 55
 		}
56 56
 
57 57
 	    /**
@@ -67,22 +67,22 @@  discard block
 block discarded – undo
67 67
 	     *            秘钥历史版本
68 68
 	     * @return
69 69
 	     */
70
-		function searchInner($data, $type, $session,$version)
70
+		function searchInner($data, $type, $session, $version)
71 71
 		{
72
-			if(empty($data) || empty($type)){
72
+			if (empty($data) || empty($type)) {
73 73
 				return $data;
74 74
 			}
75 75
 
76 76
 			$secretContext = null;
77 77
 			
78
-			$secretContext = $this->callSecretApiWithCache($session,$version);
79
-			$this->incrCounter(3,$type,$secretContext,true);
78
+			$secretContext = $this->callSecretApiWithCache($session, $version);
79
+			$this->incrCounter(3, $type, $secretContext, true);
80 80
 
81
-			if(empty($secretContext) || empty($secretContext->secret)) {
81
+			if (empty($secretContext) || empty($secretContext->secret)) {
82 82
 				return $data;
83 83
 			}
84 84
 
85
-			return $this->securityUtil->search($data, $type,$secretContext);
85
+			return $this->securityUtil->search($data, $type, $secretContext);
86 86
 		}
87 87
 
88 88
 
@@ -90,54 +90,54 @@  discard block
 block discarded – undo
90 90
 		* 单条数据解密,使用appkey级别公钥
91 91
 		* 非加密数据直接返回原文
92 92
 		*/
93
-		function decryptPublic($data,$type)
93
+		function decryptPublic($data, $type)
94 94
 		{
95
-			return $this->decrypt($data,$type,null);
95
+			return $this->decrypt($data, $type, null);
96 96
 		}
97 97
 		/**
98 98
 		* 单条数据解密
99 99
 		* 非加密数据直接返回原文
100 100
 		*/
101
-		function decrypt($data,$type,$session)
101
+		function decrypt($data, $type, $session)
102 102
 		{
103
-			if(empty($data) || empty($type)){
103
+			if (empty($data) || empty($type)) {
104 104
 				return $data;
105 105
 			}			
106
-			$secretData = $this->securityUtil->getSecretDataByType($data,$type);
107
-			if(empty($secretData)){
106
+			$secretData = $this->securityUtil->getSecretDataByType($data, $type);
107
+			if (empty($secretData)) {
108 108
 				return $data;
109 109
 			}
110 110
 
111
-			if($this->securityUtil->isPublicData($data,$type)){
112
-				$secretContext = $this->callSecretApiWithCache(null,$secretData->secretVersion);
113
-			} else {
114
-				$secretContext = $this->callSecretApiWithCache($session,$secretData->secretVersion);
111
+			if ($this->securityUtil->isPublicData($data, $type)) {
112
+				$secretContext = $this->callSecretApiWithCache(null, $secretData->secretVersion);
113
+			}else {
114
+				$secretContext = $this->callSecretApiWithCache($session, $secretData->secretVersion);
115 115
 			}
116
-			$this->incrCounter(2,$type,$secretContext,true);
116
+			$this->incrCounter(2, $type, $secretContext, true);
117 117
 			
118
-			return $this->securityUtil->decrypt($data,$type,$secretContext);
118
+			return $this->securityUtil->decrypt($data, $type, $secretContext);
119 119
 		}
120 120
 
121 121
 		/**
122 122
 		* 多条数据解密,使用appkey级别公钥
123 123
 		* 非加密数据直接返回原文
124 124
 		*/
125
-		function decryptBatchPublic($array,$type)
125
+		function decryptBatchPublic($array, $type)
126 126
 		{
127
-			if(empty($array) || empty($type)){
127
+			if (empty($array) || empty($type)) {
128 128
 				return null;
129 129
 			}
130 130
 
131 131
 			$result = array();
132 132
 			foreach ($array as $value) {
133
-				$secretData = $this->securityUtil->getSecretDataByType($value,$type);
134
-				$secretContext = $this->callSecretApiWithCache(null,$secretData->secretVersion);
133
+				$secretData = $this->securityUtil->getSecretDataByType($value, $type);
134
+				$secretContext = $this->callSecretApiWithCache(null, $secretData->secretVersion);
135 135
 
136
-				if(empty($secretData)){
136
+				if (empty($secretData)) {
137 137
 					$result[$value] = $value;
138
-				}else{
139
-					$result[$value] = $this->securityUtil->decrypt($value,$type,$secretContext);
140
-					$this->incrCounter(2,$type,$secretContext,true);
138
+				}else {
139
+					$result[$value] = $this->securityUtil->decrypt($value, $type, $secretContext);
140
+					$this->incrCounter(2, $type, $secretContext, true);
141 141
 				}
142 142
 
143 143
 				$this->flushCounter($secretContext);
@@ -150,26 +150,26 @@  discard block
 block discarded – undo
150 150
 		* 多条数据解密,必须是同一个type和用户,返回结果是 KV结果
151 151
 		* 非加密数据直接返回原文
152 152
 		*/
153
-		function decryptBatch($array,$type,$session)
153
+		function decryptBatch($array, $type, $session)
154 154
 		{
155
-			if(empty($array) || empty($type)){
155
+			if (empty($array) || empty($type)) {
156 156
 				return null;
157 157
 			}
158 158
 
159 159
 			$result = array();
160 160
 			foreach ($array as $value) {
161
-				$secretData = $this->securityUtil->getSecretDataByType($value,$type);
162
-				if(empty($secretData)){
161
+				$secretData = $this->securityUtil->getSecretDataByType($value, $type);
162
+				if (empty($secretData)) {
163 163
 					$result[$value] = $value;
164
-				} else if($this->securityUtil->isPublicData($value,$type)){
165
-					$appContext = $this->callSecretApiWithCache(null,$secretData->secretVersion);
166
-					$result[$value] = $this->securityUtil->decrypt($value,$type,$appContext);
167
-					$this->incrCounter(2,$type,$appContext,false);
164
+				}else if ($this->securityUtil->isPublicData($value, $type)) {
165
+					$appContext = $this->callSecretApiWithCache(null, $secretData->secretVersion);
166
+					$result[$value] = $this->securityUtil->decrypt($value, $type, $appContext);
167
+					$this->incrCounter(2, $type, $appContext, false);
168 168
 					$this->flushCounter($appContext);
169
-				} else {
170
-					$secretContext = $this->callSecretApiWithCache($session,$secretData->secretVersion);
171
-					$result[$value] = $this->securityUtil->decrypt($value,$type,$secretContext);
172
-					$this->incrCounter(2,$type,$secretContext,false);
169
+				}else {
170
+					$secretContext = $this->callSecretApiWithCache($session, $secretData->secretVersion);
171
+					$result[$value] = $this->securityUtil->decrypt($value, $type, $secretContext);
172
+					$this->incrCounter(2, $type, $secretContext, false);
173 173
 					$this->flushCounter($secretContext);
174 174
 				}
175 175
 			}
@@ -180,58 +180,58 @@  discard block
 block discarded – undo
180 180
 		/**
181 181
 		* 使用上一版本秘钥解密,app级别公钥
182 182
 		*/
183
-		function decryptPreviousPublic($data,$type)
183
+		function decryptPreviousPublic($data, $type)
184 184
 		{
185
-			$secretContext = $this->callSecretApiWithCache(null,-1);
186
-			return $this->securityUtil->decrypt($data,$type,$secretContext);
185
+			$secretContext = $this->callSecretApiWithCache(null, -1);
186
+			return $this->securityUtil->decrypt($data, $type, $secretContext);
187 187
 		}
188 188
 		/**
189 189
 		* 使用上一版本秘钥解密,一般只用于更新秘钥
190 190
 		*/
191
-		function decryptPrevious($data,$type,$session)
191
+		function decryptPrevious($data, $type, $session)
192 192
 		{
193
-			if($this->securityUtil->isPublicData($data,$type)){
194
-				$secretContext = $this->callSecretApiWithCache(null,-1);
195
-			} else {
196
-				$secretContext = $this->callSecretApiWithCache($session,-1);
193
+			if ($this->securityUtil->isPublicData($data, $type)) {
194
+				$secretContext = $this->callSecretApiWithCache(null, -1);
195
+			}else {
196
+				$secretContext = $this->callSecretApiWithCache($session, -1);
197 197
 			}
198
-			return $this->securityUtil->decrypt($data,$type,$secretContext);
198
+			return $this->securityUtil->decrypt($data, $type, $secretContext);
199 199
 		}
200 200
 
201 201
 		/**
202 202
 		* 加密单条数据,使用app级别公钥
203 203
 		*/
204
-		function encryptPublic($data,$type,$version = null)
204
+		function encryptPublic($data, $type, $version = null)
205 205
 		{
206
-			return $this->encrypt($data,$type,null,$version);
206
+			return $this->encrypt($data, $type, null, $version);
207 207
 		}
208 208
 		/**
209 209
 		* 加密单条数据
210 210
 		*/
211
-		function encrypt($data,$type,$session = null,$version = null)
211
+		function encrypt($data, $type, $session = null, $version = null)
212 212
 		{
213
-			if(empty($data) || empty($type)){
213
+			if (empty($data) || empty($type)) {
214 214
 				return null;
215 215
 			}
216
-			$secretContext = $this->callSecretApiWithCache($session,null);
217
-			$this->incrCounter(1,$type,$secretContext,true);
216
+			$secretContext = $this->callSecretApiWithCache($session, null);
217
+			$this->incrCounter(1, $type, $secretContext, true);
218 218
 
219
-			return $this->securityUtil->encrypt($data,$type,$version,$secretContext);
219
+			return $this->securityUtil->encrypt($data, $type, $version, $secretContext);
220 220
 		}
221 221
 
222 222
 		/**
223 223
 		* 加密多条数据,使用app级别公钥
224 224
 		*/
225
-		function encryptBatchPublic($array,$type,$version = null)
225
+		function encryptBatchPublic($array, $type, $version = null)
226 226
 		{
227
-			if(empty($array) || empty($type)){
227
+			if (empty($array) || empty($type)) {
228 228
 				return null;
229 229
 			}
230
-			$secretContext = $this->callSecretApiWithCache(null,null);
230
+			$secretContext = $this->callSecretApiWithCache(null, null);
231 231
 			$result = array();
232 232
 			foreach ($array as $value) {
233
-				$result[$value] = $this->securityUtil->encrypt($value,$type,$version,$secretContext);
234
-				$this->incrCounter(1,$type,$secretContext,false);
233
+				$result[$value] = $this->securityUtil->encrypt($value, $type, $version, $secretContext);
234
+				$this->incrCounter(1, $type, $secretContext, false);
235 235
 			}
236 236
 			$this->flushCounter($secretContext);
237 237
 
@@ -241,16 +241,16 @@  discard block
 block discarded – undo
241 241
 		/**
242 242
 		* 加密多条数据,必须是同一个type和用户,返回结果是 KV结果
243 243
 		*/
244
-		function encryptBatch($array,$type,$session,$version = null)
244
+		function encryptBatch($array, $type, $session, $version = null)
245 245
 		{
246
-			if(empty($array) || empty($type)){
246
+			if (empty($array) || empty($type)) {
247 247
 				return null;
248 248
 			}
249
-			$secretContext = $this->callSecretApiWithCache($session,null);
249
+			$secretContext = $this->callSecretApiWithCache($session, null);
250 250
 			$result = array();
251 251
 			foreach ($array as $value) {
252
-				$result[$value] = $this->securityUtil->encrypt($value,$type,$version,$secretContext);
253
-				$this->incrCounter(1,$type,$secretContext,false);
252
+				$result[$value] = $this->securityUtil->encrypt($value, $type, $version, $secretContext);
253
+				$this->incrCounter(1, $type, $secretContext, false);
254 254
 			}
255 255
 			$this->flushCounter($secretContext);
256 256
 			return $result;
@@ -259,22 +259,22 @@  discard block
 block discarded – undo
259 259
 		/**
260 260
 		* 使用上一版本秘钥加密,使用app级别公钥
261 261
 		*/
262
-		function encryptPreviousPublic($data,$type)
262
+		function encryptPreviousPublic($data, $type)
263 263
 		{
264
-			$secretContext = $this->callSecretApiWithCache(null,-1);
265
-			$this->incrCounter(1,$type,$secretContext,true);
264
+			$secretContext = $this->callSecretApiWithCache(null, -1);
265
+			$this->incrCounter(1, $type, $secretContext, true);
266 266
 
267
-			return $this->securityUtil->encrypt($data,$type,$secretContext->version,$secretContext);
267
+			return $this->securityUtil->encrypt($data, $type, $secretContext->version, $secretContext);
268 268
 		}
269 269
 		/**
270 270
 		* 使用上一版本秘钥加密,一般只用于更新秘钥
271 271
 		*/
272
-		function encryptPrevious($data,$type,$session)
272
+		function encryptPrevious($data, $type, $session)
273 273
 		{
274
-			$secretContext = $this->callSecretApiWithCache($session,-1);
275
-			$this->incrCounter(1,$type,$secretContext,true);
274
+			$secretContext = $this->callSecretApiWithCache($session, -1);
275
+			$this->incrCounter(1, $type, $secretContext, true);
276 276
 
277
-			return $this->securityUtil->encrypt($data,$type,$secretContext);
277
+			return $this->securityUtil->encrypt($data, $type, $secretContext);
278 278
 		}
279 279
 
280 280
 		/**
@@ -282,160 +282,160 @@  discard block
 block discarded – undo
282 282
 		*/
283 283
 		function initSecret($session)
284 284
 		{
285
-			return $this->callSecretApiWithCache($session,null);
285
+			return $this->callSecretApiWithCache($session, null);
286 286
 		}
287 287
 
288
-		function buildCacheKey($session,$secretVersion)
288
+		function buildCacheKey($session, $secretVersion)
289 289
 		{
290
-			if(empty($session)){
290
+			if (empty($session)) {
291 291
 				return $this->topClient->getAppkey();
292 292
 			}
293
-			if(empty($secretVersion)){
294
-				return $session ;
293
+			if (empty($secretVersion)) {
294
+				return $session;
295 295
 			}
296
-			return $session.'_'.$secretVersion ;
296
+			return $session.'_'.$secretVersion;
297 297
 		}
298 298
 
299 299
 
300 300
 		function generateCustomerSession($userId)
301 301
 		{
302
-			return '_'.$userId ;
302
+			return '_'.$userId;
303 303
 		}
304 304
 
305 305
 		/**
306 306
 		* 判断是否是已加密的数据
307 307
 		*/
308
-		function isEncryptData($data,$type)
308
+		function isEncryptData($data, $type)
309 309
 		{
310
-			if(empty($data) || empty($type)){
310
+			if (empty($data) || empty($type)) {
311 311
 				return false;
312 312
 			}
313
-			return $this->securityUtil->isEncryptData($data,$type);
313
+			return $this->securityUtil->isEncryptData($data, $type);
314 314
 		}
315 315
 
316 316
 		/**
317 317
 		* 判断是否是已加密的数据,数据必须是同一个类型
318 318
 		*/
319
-		function isEncryptDataArray($array,$type)
319
+		function isEncryptDataArray($array, $type)
320 320
 		{
321
-			if(empty($array) || empty($type)){
321
+			if (empty($array) || empty($type)) {
322 322
 				return false;
323 323
 			}
324
-			return $this->securityUtil->isEncryptDataArray($array,$type);
324
+			return $this->securityUtil->isEncryptDataArray($array, $type);
325 325
 		}
326 326
 
327 327
 		/**
328 328
 		* 判断数组中的数据是否存在密文,存在任何一个返回true,否则false
329 329
 		*/
330
-		function isPartEncryptData($array,$type)
330
+		function isPartEncryptData($array, $type)
331 331
 		{
332
-			if(empty($array) || empty($type)){
332
+			if (empty($array) || empty($type)) {
333 333
 				return false;
334 334
 			}
335
-			return $this->securityUtil->isPartEncryptData($array,$type);
335
+			return $this->securityUtil->isPartEncryptData($array, $type);
336 336
 		}
337 337
 
338 338
 		/**
339 339
 		* 获取秘钥,使用缓存
340 340
 		*/
341
-		function callSecretApiWithCache($session,$secretVersion)
341
+		function callSecretApiWithCache($session, $secretVersion)
342 342
 		{
343
-			if($this->cacheClient)
343
+			if ($this->cacheClient)
344 344
 			{
345 345
 				$time = time();
346
-				$cacheKey = $this->buildCacheKey($session,$secretVersion);
346
+				$cacheKey = $this->buildCacheKey($session, $secretVersion);
347 347
 				$secretContext = $this->cacheClient->getCache($cacheKey);
348 348
 
349
-				if($secretContext)
349
+				if ($secretContext)
350 350
 				{
351
-					if($this->canUpload($secretContext)){
352
-						if($this->report($secretContext)){
351
+					if ($this->canUpload($secretContext)) {
352
+						if ($this->report($secretContext)) {
353 353
 							$this->clearReport($secretContext);
354 354
 						}
355 355
 					}
356 356
 				}
357 357
 
358
-				if($secretContext && $secretContext->invalidTime > $time)
358
+				if ($secretContext && $secretContext->invalidTime > $time)
359 359
 				{
360 360
 					return $secretContext;
361 361
 				}
362 362
 			}
363 363
 
364
-			$secretContext = $this->callSecretApi($session,$secretVersion);
364
+			$secretContext = $this->callSecretApi($session, $secretVersion);
365 365
 
366
-			if($this->cacheClient)
366
+			if ($this->cacheClient)
367 367
 			{
368 368
 				$secretContext->cacheKey = $cacheKey;
369
-				$this->cacheClient->setCache($cacheKey,$secretContext);
369
+				$this->cacheClient->setCache($cacheKey, $secretContext);
370 370
 			}
371 371
 
372 372
 			return $secretContext;
373 373
 		}
374 374
 
375
-		function incrCounter($op,$type,$secretContext,$flush)
375
+		function incrCounter($op, $type, $secretContext, $flush)
376 376
 		{
377
-			if($op == 1){
377
+			if ($op == 1) {
378 378
 				switch ($type) {
379 379
 					case 'nick':
380
-					$secretContext->encryptNickNum ++ ;
380
+					$secretContext->encryptNickNum++;
381 381
 						break;
382 382
 					case 'simple':
383
-						$secretContext->encryptSimpleNum ++ ;
383
+						$secretContext->encryptSimpleNum++;
384 384
 						break;
385 385
 					case 'receiver_name':
386
-						$secretContext->encryptReceiverNameNum ++ ;
386
+						$secretContext->encryptReceiverNameNum++;
387 387
 						break;
388 388
 					case 'phone':
389
-						$secretContext->encryptPhoneNum ++ ;
389
+						$secretContext->encryptPhoneNum++;
390 390
 						break;
391 391
 					default:
392 392
 						break;
393 393
 				}
394
-			}else if($op == 2){
394
+			}else if ($op == 2) {
395 395
 				switch ($type) {
396 396
 					case 'nick':
397
-					$secretContext->decryptNickNum ++ ;
397
+					$secretContext->decryptNickNum++;
398 398
 						break;
399 399
 					case 'simple':
400
-						$secretContext->decryptSimpleNum ++ ;
400
+						$secretContext->decryptSimpleNum++;
401 401
 						break;
402 402
 					case 'receiver_name':
403
-						$secretContext->decryptReceiverNameNum ++ ;
403
+						$secretContext->decryptReceiverNameNum++;
404 404
 						break;
405 405
 					case 'phone':
406
-						$secretContext->decryptPhoneNum ++ ;
406
+						$secretContext->decryptPhoneNum++;
407 407
 						break;
408 408
 					default:
409 409
 						break;
410 410
 				}
411
-			}else{
411
+			}else {
412 412
 				switch ($type) {
413 413
 					case 'nick':
414
-					$secretContext->searchNickNum ++ ;
414
+					$secretContext->searchNickNum++;
415 415
 						break;
416 416
 					case 'simple':
417
-						$secretContext->searchSimpleNum ++ ;
417
+						$secretContext->searchSimpleNum++;
418 418
 						break;
419 419
 					case 'receiver_name':
420
-						$secretContext->searchReceiverNameNum ++ ;
420
+						$secretContext->searchReceiverNameNum++;
421 421
 						break;
422 422
 					case 'phone':
423
-						$secretContext->searchPhoneNum ++ ;
423
+						$secretContext->searchPhoneNum++;
424 424
 						break;
425 425
 					default:
426 426
 						break;
427 427
 				}
428 428
 			}
429 429
 
430
-			if($flush && $this->cacheClient){
431
-				$this->cacheClient->setCache($secretContext->cacheKey,$secretContext);
430
+			if ($flush && $this->cacheClient) {
431
+				$this->cacheClient->setCache($secretContext->cacheKey, $secretContext);
432 432
 			}
433 433
 		}
434 434
 
435 435
 		function flushCounter($secretContext)
436 436
 		{
437
-			if($this->cacheClient){
438
-				$this->cacheClient->setCache($secretContext->cacheKey,$secretContext);
437
+			if ($this->cacheClient) {
438
+				$this->cacheClient->setCache($secretContext->cacheKey, $secretContext);
439 439
 			}			
440 440
 		}
441 441
 
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
 		function canUpload($secretContext)
463 463
 		{
464 464
 			$current = time();
465
-			if($current - $secretContext->lastUploadTime > 300){
465
+			if ($current-$secretContext->lastUploadTime > 300) {
466 466
 				return true;
467 467
 			}
468 468
 			return false;
@@ -476,14 +476,14 @@  discard block
 block discarded – undo
476 476
 			$request = new TopSdkFeedbackUploadRequest;
477 477
 			$request->setContent($secretContext->toLogString());
478 478
 
479
-			if(empty($secretContext->session)){
479
+			if (empty($secretContext->session)) {
480 480
 				$request->setType(APP_SECRET_TYPE);
481
-			}else{
481
+			}else {
482 482
 				$request->setType(APP_USER_SECRET_TYPE);				
483 483
 			}
484 484
 
485
-			$response = $this->topClient->execute($request,$secretContext->session);
486
-			if($response->code == 0){
485
+			$response = $this->topClient->execute($request, $secretContext->session);
486
+			if ($response->code == 0) {
487 487
 				return true;
488 488
 			}
489 489
 			return false;
@@ -492,49 +492,49 @@  discard block
 block discarded – undo
492 492
 		/**
493 493
 		* 获取秘钥,不使用缓存
494 494
 		*/
495
-		function callSecretApi($session,$secretVersion)
495
+		function callSecretApi($session, $secretVersion)
496 496
 		{
497 497
 			$request = new TopSecretGetRequest;
498 498
 			$request->setRandomNum($this->randomNum);
499
-			if($secretVersion)
499
+			if ($secretVersion)
500 500
 			{
501
-				if(intval($secretVersion) < 0 || $session == null){
501
+				if (intval($secretVersion) < 0 || $session == null) {
502 502
 					$session = null;
503
-					$secretVersion = -1 * intval($secretVersion < 0);
503
+					$secretVersion = -1*intval($secretVersion < 0);
504 504
 				}
505 505
 				$request->setSecretVersion($secretVersion);
506 506
 			}
507 507
 			
508 508
 			$topSession = $session;
509
-			if($session != null && $session[0] == '_')
509
+			if ($session != null && $session[0] == '_')
510 510
 			{
511
-				$request->setCustomerUserId(substr($session,1));
511
+				$request->setCustomerUserId(substr($session, 1));
512 512
 				$topSession = null;
513 513
 			}
514 514
 
515
-			$response = $this->topClient->execute($request,$topSession);
516
-			if($response->code != 0){
515
+			$response = $this->topClient->execute($request, $topSession);
516
+			if ($response->code != 0) {
517 517
 				throw new Exception($response->msg);
518 518
 			}
519 519
 
520 520
 			$time = time();
521 521
 			$secretContext = new SecretContext();
522
-			$secretContext->maxInvalidTime = $time + intval($response->max_interval);
523
-			$secretContext->invalidTime = $time + intval($response->interval);
522
+			$secretContext->maxInvalidTime = $time+intval($response->max_interval);
523
+			$secretContext->invalidTime = $time+intval($response->interval);
524 524
 			$secretContext->secret = strval($response->secret);
525 525
 			$secretContext->session = $session;
526
-			if(!empty($response->app_config)){
526
+			if (!empty($response->app_config)) {
527 527
 				$tmpJson = json_decode($response->app_config);
528 528
 				$appConfig = array();
529
-				foreach ($tmpJson as $key => $value){
529
+				foreach ($tmpJson as $key => $value) {
530 530
 					$appConfig[$key] = $value;
531 531
 				}
532 532
 				$secretContext->appConfig = $appConfig;
533 533
 			}
534 534
 
535
-			if(empty($session)){
536
-				$secretContext->secretVersion = -1 * intval($response->secret_version);
537
-			}else{
535
+			if (empty($session)) {
536
+				$secretContext->secretVersion = -1*intval($response->secret_version);
537
+			}else {
538 538
 				$secretContext->secretVersion = intval($response->secret_version);
539 539
 			}
540 540
 			return $secretContext;
Please login to merge, or discard this patch.
src/service/taobao/bin/top/security/SecretContext.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
 				  .$this->decryptPhoneNum.','.$this->decryptNickNum.','.$this->decryptReceiverNameNum.','
38 38
 				  .$this->decryptSimpleNum.','.$this->decryptSearchNum.','.$this->searchPhoneNum.','
39 39
 				  .$this->searchNickNum.','.$this->searchReceiverNameNum.','.$this->searchSimpleNum.','
40
-				  .$this->searchSearchNum ;
40
+				  .$this->searchSearchNum;
41 41
 		}
42 42
 
43 43
 		function __construct()
Please login to merge, or discard this patch.
src/service/taobao/bin/top/security/SecretGetRequest.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -14,19 +14,19 @@
 block discarded – undo
14 14
 		return $this->apiParas;
15 15
 	}
16 16
 
17
-	public function setRandomNum($random){
17
+	public function setRandomNum($random) {
18 18
 		$this->apiParas['random_num'] = $random;
19 19
 	}
20 20
 
21
-	public function setCustomerUserId($customId){
21
+	public function setCustomerUserId($customId) {
22 22
 		$this->apiParas['customer_user_id'] = $customId;
23 23
 	}
24 24
 
25
-	public function setSecretVersion($version){
25
+	public function setSecretVersion($version) {
26 26
 		$this->apiParas['secret_version'] = $version;
27 27
 	}
28 28
 	
29
-	public function check(){}
29
+	public function check() {}
30 30
 	
31 31
 	public function putOtherTextParam($key, $value) {
32 32
 		$this->apiParas[$key] = $value;
Please login to merge, or discard this patch.
src/service/taobao/bin/top/security/SecurityTest.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 
12 12
     $session = '6101701a21788e0e44743d5f1032ccd5276f00ea6a2d9092050695162';
13 13
 
14
-    $client = new SecurityClient($c,'S7/xdg4AD7WooWY7+g11qoBpaVsEkonULDJPEiMcXPE=');
14
+    $client = new SecurityClient($c, 'S7/xdg4AD7WooWY7+g11qoBpaVsEkonULDJPEiMcXPE=');
15 15
     $yac = new YacCache;
16 16
     $client->setCacheClient($yac);
17 17
 
@@ -19,50 +19,50 @@  discard block
 block discarded – undo
19 19
     $val = '13834566786';
20 20
 
21 21
     echo "原文:13834566786".PHP_EOL;
22
-    $encryptValue = $client->encrypt($val,$type,$session);
22
+    $encryptValue = $client->encrypt($val, $type, $session);
23 23
     echo "加密后:".$encryptValue.PHP_EOL;
24
-    echo "search明文:".$val." -->".$client->search("6786",$type,$session).PHP_EOL;
24
+    echo "search明文:".$val." -->".$client->search("6786", $type, $session).PHP_EOL;
25 25
 
26
-    if($client->isEncryptData($encryptValue,$type))
26
+    if ($client->isEncryptData($encryptValue, $type))
27 27
     {
28
-    	$originalValue = $client->decrypt($encryptValue,$type,$session);
28
+    	$originalValue = $client->decrypt($encryptValue, $type, $session);
29 29
     	echo "解密后:".$originalValue.PHP_EOL;
30 30
     }
31 31
 
32
-    $originalValue = $client->decrypt('~YjW+T6rCmKcc0tGqzWIDaQ==~-113~','nick',$session);
32
+    $originalValue = $client->decrypt('~YjW+T6rCmKcc0tGqzWIDaQ==~-113~', 'nick', $session);
33 33
     echo "公钥解密后:".$originalValue.PHP_EOL;    
34 34
 
35 35
 
36 36
     $secArray = array('~YjW+T6rCmKcc0tGqzWIDaQ==~-113~');
37
-    $client->decryptBatch($secArray,'nick',$session);
37
+    $client->decryptBatch($secArray, 'nick', $session);
38 38
 
39 39
 
40
-	$typeArray = array('normal','nick','receiver_name');
40
+	$typeArray = array('normal', 'nick', 'receiver_name');
41 41
 
42 42
 	$val2 = '啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊看哦【啊啊啊的';
43 43
 
44 44
 	foreach ($typeArray as $type2) {
45 45
 		echo "==============================TOP================================".PHP_EOL;
46
-		$encty2 = $client->encrypt($val2,$type2,$session);
46
+		$encty2 = $client->encrypt($val2, $type2, $session);
47 47
 		echo $type2."|明文:".$val2." ---->密文:".$encty2.PHP_EOL;
48
-		if($client->isEncryptData($encty2,$type2))
48
+		if ($client->isEncryptData($encty2, $type2))
49 49
 		{
50
-			$originalValue = $client->decrypt($encty2,$type2,$session);
50
+			$originalValue = $client->decrypt($encty2, $type2, $session);
51 51
     		echo "解密后:".$originalValue.PHP_EOL;
52
-            echo "search明文:".$originalValue." -->".$client->search($originalValue,$type2,$session).PHP_EOL;
53
-		}else{
52
+            echo "search明文:".$originalValue." -->".$client->search($originalValue, $type2, $session).PHP_EOL;
53
+		}else {
54 54
 			echo "不是加密数据".PHP_EOL;
55 55
 		}
56 56
 	}
57 57
 
58
-    $encryptNick = $client->encrypt("xxxuxxxuxxxu","nick");
58
+    $encryptNick = $client->encrypt("xxxuxxxuxxxu", "nick");
59 59
     echo "加密后:".$encryptNick.PHP_EOL;
60
-    echo "search明文:xxxuxxxuxxxu -->".$client->search("xxxu","nick").PHP_EOL;
61
-    if($client->isEncryptData($encryptNick,"nick"))
60
+    echo "search明文:xxxuxxxuxxxu -->".$client->search("xxxu", "nick").PHP_EOL;
61
+    if ($client->isEncryptData($encryptNick, "nick"))
62 62
     {
63
-        $originalNick = $client->decryptPublic($encryptNick,"nick");
63
+        $originalNick = $client->decryptPublic($encryptNick, "nick");
64 64
         echo "解密后:".$originalNick.PHP_EOL;
65
-    }else{
65
+    }else {
66 66
         echo "不是加密数据 ".$encryptNick.PHP_EOL;
67 67
     }
68 68
 ?>
69 69
\ No newline at end of file
Please login to merge, or discard this patch.
src/service/taobao/bin/top/security/SecretCounterUtil.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 
7 7
 	class SecretCounterUtil
8 8
 	{
9
-		private $topClient ;
9
+		private $topClient;
10 10
 		private $cacheClient = null;
11 11
 
12 12
 		private $counterMap;
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 		*/
24 24
 		function __destruct()
25 25
 		{
26
-			if($this->cacheClient == null){
26
+			if ($this->cacheClient == null) {
27 27
 
28 28
 			}
29 29
 		}
@@ -38,59 +38,59 @@  discard block
 block discarded – undo
38 38
 			$this->cacheClient = $cache;
39 39
 		}
40 40
 
41
-		function incrDecrypt($delt,$session,$type)
41
+		function incrDecrypt($delt, $session, $type)
42 42
 		{
43 43
 			$item = getItem($session);
44
-			if($item == null){
44
+			if ($item == null) {
45 45
 				$item = new SecretCounter();
46
-				putItem($session,$item);
46
+				putItem($session, $item);
47 47
 			}
48 48
 
49
-			if($type == "nick"){
49
+			if ($type == "nick") {
50 50
 				$item->$decryptNickNum += $delt;
51
-			}else if($type == "receiver_name"){
52
-				$item->$decryptReceiverNameNum += $delt ;	
53
-			}else if($type == "phone"){
54
-				$item->$decryptPhoneNum += $delt ;	
55
-			}else if($type == "simple"){
56
-				$item->$decryptSimpleNum += $delt ;	
51
+			}else if ($type == "receiver_name") {
52
+				$item->$decryptReceiverNameNum += $delt;	
53
+			}else if ($type == "phone") {
54
+				$item->$decryptPhoneNum += $delt;	
55
+			}else if ($type == "simple") {
56
+				$item->$decryptSimpleNum += $delt;	
57 57
 			}
58 58
 		}
59 59
 
60
-		function incrEncrypt($delt,$session,$type)
60
+		function incrEncrypt($delt, $session, $type)
61 61
 		{
62 62
 			$item = getItem($session);
63
-			if($item == null){
63
+			if ($item == null) {
64 64
 				$item = new SecretCounter();
65
-				putItem($session,$item);
65
+				putItem($session, $item);
66 66
 			}
67 67
 
68
-			if($type == "nick"){
69
-				$item->$encryptNickNum += $delt ;
70
-			}else if($type == "receiver_name"){
71
-				$item->$encryptReceiverNameNum += $delt ;	
72
-			}else if($type == "phone"){
73
-				$item->$encryptPhoneNum += $delt ;	
74
-			}else if($type == "simple"){
75
-				$item->$encryptSimpleNum += $delt ;	
68
+			if ($type == "nick") {
69
+				$item->$encryptNickNum += $delt;
70
+			}else if ($type == "receiver_name") {
71
+				$item->$encryptReceiverNameNum += $delt;	
72
+			}else if ($type == "phone") {
73
+				$item->$encryptPhoneNum += $delt;	
74
+			}else if ($type == "simple") {
75
+				$item->$encryptSimpleNum += $delt;	
76 76
 			}
77 77
 		}
78 78
 
79 79
 		function getItem($session)
80 80
 		{
81
-			if($this->cacheClient == null){
81
+			if ($this->cacheClient == null) {
82 82
 				return $counterMap[$session];
83
-			}else{
83
+			}else {
84 84
 				return $this->cacheClient->getCache('s_'.$session);
85 85
 			}
86 86
 		}
87 87
 
88
-		function putItem($session,$item)
88
+		function putItem($session, $item)
89 89
 		{
90
-			if($this->cacheClient == null){
90
+			if ($this->cacheClient == null) {
91 91
 				$counterMap[$session] = $item;
92
-			}else{
93
-				$this->cacheClient->setCache('s_'.$session,$item);
92
+			}else {
93
+				$this->cacheClient->setCache('s_'.$session, $item);
94 94
 			}
95 95
 		}
96 96
 	}
Please login to merge, or discard this patch.
src/service/taobao/bin/top/ApplicationVar.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -9,11 +9,11 @@  discard block
 block discarded – undo
9 9
 
10 10
 	function __construct()
11 11
  	{
12
-    $this->save_file = __DIR__.'/httpdns.conf' ;
12
+    $this->save_file = __DIR__.'/httpdns.conf';
13 13
  		$this->application = array();
14 14
  	}
15 15
 
16
- 	public function setValue($var_name,$var_value)
16
+ 	public function setValue($var_name, $var_value)
17 17
   {
18 18
    		if (!is_string($var_name) || empty($var_name))
19 19
     		return false;
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
    		$this->application[$var_name] = $var_value;
22 22
   }
23 23
 
24
-  public function write(){
24
+  public function write() {
25 25
       $this->app_data = @serialize($this->application);    
26 26
       $this->__writeToFile();
27 27
   }
@@ -35,10 +35,10 @@  discard block
 block discarded – undo
35 35
 
36 36
  	function __writeToFile()
37 37
  	{
38
-  		$fp = @fopen($this->save_file,"w");
39
-      if(flock($fp , LOCK_EX | LOCK_NB)){
40
-          @fwrite($fp,$this->app_data);
41
-          flock($fp , LOCK_UN);
38
+  		$fp = @fopen($this->save_file, "w");
39
+      if (flock($fp, LOCK_EX | LOCK_NB)) {
40
+          @fwrite($fp, $this->app_data);
41
+          flock($fp, LOCK_UN);
42 42
       }
43 43
       @fclose($fp);
44 44
  	}
Please login to merge, or discard this patch.
src/service/taobao/bin/top/TopLogger.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@
 block discarded – undo
36 36
 		{
37 37
 			$logData = implode($this->conf["separator"], $logData);
38 38
 		}
39
-		$logData = $logData. "\n";
39
+		$logData = $logData."\n";
40 40
 		fwrite($this->getFileHandle(), $logData);
41 41
 	}
42 42
 }
Please login to merge, or discard this patch.
src/service/taobao/bin/top/request/TopSdkFeedbackUploadRequest.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@
 block discarded – undo
54 54
 	public function check()
55 55
 	{
56 56
 		
57
-		RequestCheckUtil::checkNotNull($this->type,"type");
57
+		RequestCheckUtil::checkNotNull($this->type, "type");
58 58
 	}
59 59
 	
60 60
 	public function putOtherTextParam($key, $value) {
Please login to merge, or discard this patch.
src/service/taobao/bin/top/request/TbkDgNewuserOrderGetRequest.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -118,9 +118,9 @@
 block discarded – undo
118 118
 	public function check()
119 119
 	{
120 120
 		
121
-		RequestCheckUtil::checkNotNull($this->activityId,"activityId");
122
-		RequestCheckUtil::checkMaxValue($this->pageSize,100,"pageSize");
123
-		RequestCheckUtil::checkMinValue($this->pageSize,1,"pageSize");
121
+		RequestCheckUtil::checkNotNull($this->activityId, "activityId");
122
+		RequestCheckUtil::checkMaxValue($this->pageSize, 100, "pageSize");
123
+		RequestCheckUtil::checkMinValue($this->pageSize, 1, "pageSize");
124 124
 	}
125 125
 	
126 126
 	public function putOtherTextParam($key, $value) {
Please login to merge, or discard this patch.