Passed
Push — v6 ( f71c30...fe03e1 )
by 光春
04:16
created
src/service/taobao/bin/QimenCloud/QimenCloudClient.php 1 patch
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -29,9 +29,9 @@  discard block
 block discarded – undo
29 29
 		return $this->appkey;
30 30
 	}
31 31
 
32
-	public function __construct($appkey = "",$secretKey = ""){
32
+	public function __construct($appkey = "", $secretKey = "") {
33 33
 		$this->appkey = $appkey;
34
-		$this->secretKey = $secretKey ;
34
+		$this->secretKey = $secretKey;
35 35
 	}
36 36
 
37 37
 	protected function generateSign($params)
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 		$stringToBeSigned = $this->secretKey;
42 42
 		foreach ($params as $k => $v)
43 43
 		{
44
-			if(!is_array($v) && "@" != substr($v, 0, 1))
44
+			if (!is_array($v) && "@" != substr($v, 0, 1))
45 45
 			{
46 46
 				$stringToBeSigned .= "$k$v";
47 47
 			}
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
 		if ($this->connectTimeout) {
65 65
 			curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
66 66
 		}
67
-		curl_setopt ( $ch, CURLOPT_USERAGENT, "top-sdk-php" );
67
+		curl_setopt($ch, CURLOPT_USERAGENT, "top-sdk-php");
68 68
 		//https 请求
69
-		if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) {
69
+		if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") {
70 70
 			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
71 71
 			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
72 72
 		}
@@ -77,14 +77,14 @@  discard block
 block discarded – undo
77 77
 			$postMultipart = false;
78 78
 			foreach ($postFields as $k => $v)
79 79
 			{
80
-				if("@" != substr($v, 0, 1))//判断是不是文件上传
80
+				if ("@" != substr($v, 0, 1))//判断是不是文件上传
81 81
 				{
82
-					$postBodyString .= "$k=" . urlencode($v) . "&"; 
82
+					$postBodyString .= "$k=".urlencode($v)."&"; 
83 83
 				}
84 84
 				else//文件上传用multipart/form-data,否则用www-form-urlencoded
85 85
 				{
86 86
 					$postMultipart = true;
87
-					if(class_exists('\CURLFile')){
87
+					if (class_exists('\CURLFile')) {
88 88
 						$postFields[$k] = new \CURLFile(substr($v, 1));
89 89
 					}
90 90
 				}
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 			{
96 96
 				if (class_exists('\CURLFile')) {
97 97
 				    curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
98
-				} else {
98
+				}else {
99 99
 				    if (defined('CURLOPT_SAFE_UPLOAD')) {
100 100
 				        curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
101 101
 				    }
@@ -105,22 +105,22 @@  discard block
 block discarded – undo
105 105
 			else
106 106
 			{
107 107
 				$header = array("content-type: application/x-www-form-urlencoded; charset=UTF-8");
108
-				curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
109
-				curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString,0,-1));
108
+				curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
109
+				curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString, 0, -1));
110 110
 			}
111 111
 		}
112 112
 		$reponse = curl_exec($ch);
113 113
 		
114 114
 		if (curl_errno($ch))
115 115
 		{
116
-			throw new Exception(curl_error($ch),0);
116
+			throw new Exception(curl_error($ch), 0);
117 117
 		}
118 118
 		else
119 119
 		{
120 120
 			$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
121 121
 			if (200 !== $httpStatusCode)
122 122
 			{
123
-				throw new Exception($reponse,$httpStatusCode);
123
+				throw new Exception($reponse, $httpStatusCode);
124 124
 			}
125 125
 		}
126 126
 		curl_close($ch);
@@ -138,44 +138,44 @@  discard block
 block discarded – undo
138 138
 		if ($this->connectTimeout) {
139 139
 			curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
140 140
 		}
141
-		curl_setopt ( $ch, CURLOPT_USERAGENT, "top-sdk-php" );
141
+		curl_setopt($ch, CURLOPT_USERAGENT, "top-sdk-php");
142 142
 		//https 请求
143
-		if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) {
143
+		if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") {
144 144
 			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
145 145
 			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
146 146
 		}
147 147
 		//生成分隔符
148
-		$delimiter = '-------------' . uniqid();
148
+		$delimiter = '-------------'.uniqid();
149 149
 		//先将post的普通数据生成主体字符串
150 150
 		$data = '';
151
-		if($postFields != null){
151
+		if ($postFields != null) {
152 152
 			foreach ($postFields as $name => $content) {
153
-			    $data .= "--" . $delimiter . "\r\n";
154
-			    $data .= 'Content-Disposition: form-data; name="' . $name . '"';
153
+			    $data .= "--".$delimiter."\r\n";
154
+			    $data .= 'Content-Disposition: form-data; name="'.$name.'"';
155 155
 			    //multipart/form-data 不需要urlencode,参见 http:stackoverflow.com/questions/6603928/should-i-url-encode-post-data
156
-			    $data .= "\r\n\r\n" . $content . "\r\n";
156
+			    $data .= "\r\n\r\n".$content."\r\n";
157 157
 			}
158
-			unset($name,$content);
158
+			unset($name, $content);
159 159
 		}
160 160
 
161 161
 		//将上传的文件生成主体字符串
162
-		if($fileFields != null){
162
+		if ($fileFields != null) {
163 163
 			foreach ($fileFields as $name => $file) {
164
-			    $data .= "--" . $delimiter . "\r\n";
165
-			    $data .= 'Content-Disposition: form-data; name="' . $name . '"; filename="' . $file['name'] . "\" \r\n";
166
-			    $data .= 'Content-Type: ' . $file['type'] . "\r\n\r\n";//多了个文档类型
164
+			    $data .= "--".$delimiter."\r\n";
165
+			    $data .= 'Content-Disposition: form-data; name="'.$name.'"; filename="'.$file['name']."\" \r\n";
166
+			    $data .= 'Content-Type: '.$file['type']."\r\n\r\n"; //多了个文档类型
167 167
 
168
-			    $data .= $file['content'] . "\r\n";
168
+			    $data .= $file['content']."\r\n";
169 169
 			}
170
-			unset($name,$file);
170
+			unset($name, $file);
171 171
 		}
172 172
 		//主体结束的分隔符
173
-		$data .= "--" . $delimiter . "--";
173
+		$data .= "--".$delimiter."--";
174 174
 
175 175
 		curl_setopt($ch, CURLOPT_POST, true);
176
-		curl_setopt($ch, CURLOPT_HTTPHEADER , array(
177
-		    'Content-Type: multipart/form-data; boundary=' . $delimiter,
178
-		    'Content-Length: ' . strlen($data))
176
+		curl_setopt($ch, CURLOPT_HTTPHEADER, array(
177
+		    'Content-Type: multipart/form-data; boundary='.$delimiter,
178
+		    'Content-Length: '.strlen($data))
179 179
 		); 
180 180
 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
181 181
 		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
@@ -185,14 +185,14 @@  discard block
 block discarded – undo
185 185
 
186 186
 		if (curl_errno($ch))
187 187
 		{
188
-			throw new Exception(curl_error($ch),0);
188
+			throw new Exception(curl_error($ch), 0);
189 189
 		}
190 190
 		else
191 191
 		{
192 192
 			$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
193 193
 			if (200 !== $httpStatusCode)
194 194
 			{
195
-				throw new Exception($reponse,$httpStatusCode);
195
+				throw new Exception($reponse, $httpStatusCode);
196 196
 			}
197 197
 		}
198 198
 		curl_close($ch);
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 	{
204 204
 		$localIp = isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : "CLI";
205 205
 		$logger = new TopLogger;
206
-		$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_comm_err_" . $this->appkey . "_" . date("Y-m-d") . ".log";
206
+		$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/').'/'."logs/top_comm_err_".$this->appkey."_".date("Y-m-d").".log";
207 207
 		$logger->conf["separator"] = "^_^";
208 208
 		$logData = array(
209 209
 		date("Y-m-d H:i:s"),
@@ -214,19 +214,19 @@  discard block
 block discarded – undo
214 214
 		$this->sdkVersion,
215 215
 		$requestUrl,
216 216
 		$errorCode,
217
-		str_replace("\n","",$responseTxt)
217
+		str_replace("\n", "", $responseTxt)
218 218
 		);
219 219
 		$logger->log($logData);
220 220
 	}
221 221
 
222
-	public function execute($request, $session = null,$bestUrl = null)
222
+	public function execute($request, $session = null, $bestUrl = null)
223 223
 	{
224
-		if($this->gatewayUrl == null) {
224
+		if ($this->gatewayUrl == null) {
225 225
 			throw new Exception("client-check-error:Need Set gatewayUrl.", 40);
226 226
 		}
227 227
 
228
-		$result =  new ResultSet(); 
229
-		if($this->checkRequest) {
228
+		$result = new ResultSet(); 
229
+		if ($this->checkRequest) {
230 230
 			try {
231 231
 				$request->check();
232 232
 			} catch (Exception $e) {
@@ -254,10 +254,10 @@  discard block
 block discarded – undo
254 254
 
255 255
 
256 256
 		//系统参数放入GET请求串
257
-		if($bestUrl){
257
+		if ($bestUrl) {
258 258
 			$requestUrl = $bestUrl."?";
259 259
 			$sysParams["partner_id"] = $this->getClusterTag();
260
-		}else{
260
+		}else {
261 261
 			$requestUrl = $this->gatewayUrl."?";
262 262
 			$sysParams["partner_id"] = $this->sdkVersion;
263 263
 		}
@@ -267,12 +267,12 @@  discard block
 block discarded – undo
267 267
 		foreach ($sysParams as $sysParamKey => $sysParamValue)
268 268
 		{
269 269
 			// if(strcmp($sysParamKey,"timestamp") != 0)
270
-			$requestUrl .= "$sysParamKey=" . urlencode($sysParamValue) . "&";
270
+			$requestUrl .= "$sysParamKey=".urlencode($sysParamValue)."&";
271 271
 		}
272 272
 
273 273
 		$fileFields = array();
274 274
 		foreach ($apiParams as $key => $value) {
275
-			if(is_array($value) && array_key_exists('type',$value) && array_key_exists('content',$value) ){
275
+			if (is_array($value) && array_key_exists('type', $value) && array_key_exists('content', $value)) {
276 276
 				$value['name'] = $key;
277 277
 				$fileFields[$key] = $value;
278 278
 				unset($apiParams[$key]);
@@ -285,15 +285,15 @@  discard block
 block discarded – undo
285 285
 		//发起HTTP请求
286 286
 		try
287 287
 		{
288
-			if(count($fileFields) > 0){
288
+			if (count($fileFields) > 0) {
289 289
 				$resp = $this->curl_with_memory_file($requestUrl, $apiParams, $fileFields);
290
-			}else{
290
+			}else {
291 291
 				$resp = $this->curl($requestUrl, $apiParams);
292 292
 			}
293 293
 		}
294 294
 		catch (Exception $e)
295 295
 		{
296
-			$this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_ERROR_" . $e->getCode(),$e->getMessage());
296
+			$this->logCommunicationError($sysParams["method"], $requestUrl, "HTTP_ERROR_".$e->getCode(), $e->getMessage());
297 297
 			$result->code = $e->getCode();
298 298
 			$result->msg = $e->getMessage();
299 299
 			return $result;
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 				}
316 316
 			}
317 317
 		}
318
-		else if("xml" == $this->format)
318
+		else if ("xml" == $this->format)
319 319
 		{
320 320
 			$respObject = @simplexml_load_string($resp);
321 321
 			if (false !== $respObject)
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 		//返回的HTTP文本不是标准JSON或者XML,记下错误日志
328 328
 		if (false === $respWellFormed)
329 329
 		{
330
-			$this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_RESPONSE_NOT_WELL_FORMED",$resp);
330
+			$this->logCommunicationError($sysParams["method"], $requestUrl, "HTTP_RESPONSE_NOT_WELL_FORMED", $resp);
331 331
 			$result->code = 0;
332 332
 			$result->msg = "HTTP_RESPONSE_NOT_WELL_FORMED";
333 333
 			return $result;
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
 		if (isset($respObject->code))
338 338
 		{
339 339
 			$logger = new TopLogger;
340
-			$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_biz_err_" . $this->appkey . "_" . date("Y-m-d") . ".log";
340
+			$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/').'/'."logs/top_biz_err_".$this->appkey."_".date("Y-m-d").".log";
341 341
 			$logger->log(array(
342 342
 				date("Y-m-d H:i:s"),
343 343
 				$resp
@@ -354,21 +354,21 @@  discard block
 block discarded – undo
354 354
 		}
355 355
 		$inflector = new LtInflector;
356 356
 		$inflector->conf["separator"] = ".";
357
-		$requestClassName = ucfirst($inflector->camelize(substr($paramsArray["method"], 7))) . "Request";
357
+		$requestClassName = ucfirst($inflector->camelize(substr($paramsArray["method"], 7)))."Request";
358 358
 		if (!class_exists($requestClassName))
359 359
 		{
360
-			trigger_error("No such api: " . $paramsArray["method"]);
360
+			trigger_error("No such api: ".$paramsArray["method"]);
361 361
 		}
362 362
 
363 363
 		$session = isset($paramsArray["session"]) ? $paramsArray["session"] : null;
364 364
 
365 365
 		$req = new $requestClassName;
366
-		foreach($paramsArray as $paraKey => $paraValue)
366
+		foreach ($paramsArray as $paraKey => $paraValue)
367 367
 		{
368 368
 			$inflector->conf["separator"] = "_";
369 369
 			$setterMethodName = $inflector->camelize($paraKey);
370 370
 			$inflector->conf["separator"] = ".";
371
-			$setterMethodName = "set" . $inflector->camelize($setterMethodName);
371
+			$setterMethodName = "set".$inflector->camelize($setterMethodName);
372 372
 			if (method_exists($req, $setterMethodName))
373 373
 			{
374 374
 				$req->$setterMethodName($paraValue);
@@ -379,6 +379,6 @@  discard block
 block discarded – undo
379 379
 
380 380
 	private function getClusterTag()
381 381
     {
382
-	    return substr($this->sdkVersion,0,11)."-cluster".substr($this->sdkVersion,11);
382
+	    return substr($this->sdkVersion, 0, 11)."-cluster".substr($this->sdkVersion, 11);
383 383
     }
384 384
 }
Please login to merge, or discard this patch.
src/service/taobao/bin/top/test.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -7,8 +7,8 @@
 block discarded – undo
7 7
 
8 8
     $req = new HttpdnsGetRequest;
9 9
 
10
-    $req->putOtherTextParam("name","test");
11
-    $req->putOtherTextParam("value",0);
10
+    $req->putOtherTextParam("name", "test");
11
+    $req->putOtherTextParam("value", 0);
12 12
 
13 13
     var_dump($c->execute($req));
14 14
 ?>
15 15
\ No newline at end of file
Please login to merge, or discard this patch.
src/service/taobao/bin/top/HttpdnsGetRequest.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@
 block discarded – undo
14 14
 		return $this->apiParas;
15 15
 	}
16 16
 	
17
-	public function check(){}
17
+	public function check() {}
18 18
 	
19 19
 	public function putOtherTextParam($key, $value) {
20 20
 		$this->apiParas[$key] = $value;
Please login to merge, or discard this patch.
src/service/taobao/bin/top/SpiUtils.php 1 patch
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-class SpiUtils{
2
+class SpiUtils {
3 3
 	private static $top_sign_list = "HTTP_TOP_SIGN_LIST";
4 4
 	private static $timestamp = "timestamp";
5 5
 	private static $header_real_ip = array("X_Real_IP", "X_Forwarded_For", "Proxy_Client_IP",
@@ -11,8 +11,8 @@  discard block
 block discarded – undo
11 11
 	 * @param secret app对应的secret
12 12
 	 * @return true:校验通过;false:校验不通过
13 13
 	 */
14
-	public static function checkSign4FormRequest($secret){
15
-		return self::checkSign(null,null,$secret);
14
+	public static function checkSign4FormRequest($secret) {
15
+		return self::checkSign(null, null, $secret);
16 16
 	}
17 17
 
18 18
 	/**
@@ -23,8 +23,8 @@  discard block
 block discarded – undo
23 23
 	 * @param secret app对应的secret
24 24
 	 * @return true:校验通过;false:校验不通过
25 25
 	 */
26
-	public static function checkSign4TextRequest($body,$secret){
27
-		return self::checkSign(null,$body,$secret);
26
+	public static function checkSign4TextRequest($body, $secret) {
27
+		return self::checkSign(null, $body, $secret);
28 28
 	}
29 29
 	
30 30
 	/**
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	 * @param secret app对应的secret
36 36
 	 * @return true:校验通过;false:校验不通过
37 37
 	 */
38
-	public static function checkSign4FileRequest($form, $secret){
38
+	public static function checkSign4FileRequest($form, $secret) {
39 39
 		return self::checkSign($form, null, $secret);
40 40
 	}
41 41
 
@@ -43,29 +43,29 @@  discard block
 block discarded – undo
43 43
 		$params = array();
44 44
 		// 1. 获取header参数
45 45
 		$headerMap = self::getHeaderMap();
46
-		foreach ($headerMap as $k => $v){
47
-			$params[$k] = $v ;
46
+		foreach ($headerMap as $k => $v) {
47
+			$params[$k] = $v;
48 48
 		}
49 49
 
50 50
 		// 2. 获取url参数
51 51
 		$queryMap = self::getQueryMap();
52
-		foreach ($queryMap as $k => $v){
53
-			$params[$k] = $v ;
52
+		foreach ($queryMap as $k => $v) {
53
+			$params[$k] = $v;
54 54
 		}
55 55
 
56 56
 		// 3. 获取form参数
57 57
 		if ($form == null && $body == null) {
58 58
 			$formMap = self::getFormMap();
59
-			foreach ($formMap as $k => $v){
60
-				$params[$k] = $v ;
59
+			foreach ($formMap as $k => $v) {
60
+				$params[$k] = $v;
61 61
 			}
62
-		} else if ($form != null) {
63
-			foreach ($form as $k => $v){
64
-				$params[$k] = $v ;
62
+		}else if ($form != null) {
63
+			foreach ($form as $k => $v) {
64
+				$params[$k] = $v;
65 65
 			}
66 66
 		}
67 67
 
68
-		if($body == null){
68
+		if ($body == null) {
69 69
 			$body = file_get_contents('php://input');
70 70
 		}
71 71
 
@@ -73,9 +73,9 @@  discard block
 block discarded – undo
73 73
 		$localSign = self::sign($params, $body, $secret);
74 74
 		if (strcmp($remoteSign, $localSign) == 0) {
75 75
 			return true;
76
-		} else {
76
+		}else {
77 77
 			$paramStr = self::getParamStrFromMap($params);
78
-			self::logCommunicationError($remoteSign,$localSign,$paramStr,$body);
78
+			self::logCommunicationError($remoteSign, $localSign, $paramStr, $body);
79 79
 			return false;
80 80
 		}
81 81
 	}
@@ -84,18 +84,18 @@  discard block
 block discarded – undo
84 84
 		$headerMap = array();
85 85
 		$signList = $_SERVER['HTTP_TOP_SIGN_LIST']; // 只获取参与签名的头部字段
86 86
 
87
-		if(!$signList) {
87
+		if (!$signList) {
88 88
 			return $headerMap;
89 89
 		}
90 90
 
91 91
 		$signList = trim($signList);
92
-		if (strlen($signList) > 0){
92
+		if (strlen($signList) > 0) {
93 93
 			$params = split(",", $signList);
94
-			foreach ($_SERVER as $k => $v){
95
-				if (substr($k, 0, 5) == 'HTTP_'){
96
-					foreach($params as $kk){
94
+			foreach ($_SERVER as $k => $v) {
95
+				if (substr($k, 0, 5) == 'HTTP_') {
96
+					foreach ($params as $kk) {
97 97
 						$upperkey = strtoupper($kk);
98
-						if(self::endWith($k,$upperkey)){
98
+						if (self::endWith($k, $upperkey)) {
99 99
 							$headerMap[$kk] = $v;
100 100
 						}
101 101
 					}
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 		return $headerMap;
106 106
 	}
107 107
 
108
-	private static function getQueryMap(){
108
+	private static function getQueryMap() {
109 109
 		$queryStr = $_SERVER["QUERY_STRING"];
110 110
 		$resultArray = array();
111 111
 		foreach (explode('&', $queryStr) as $pair) {
@@ -115,35 +115,35 @@  discard block
 block discarded – undo
115 115
 
116 116
 		        if (preg_match('/(?P<name>\w+)\[(?P<index>\w+)\]/', $subKey, $matches)) {
117 117
 		            $resultArray[$matches['name']][$matches['index']][$subVal] = $value;
118
-		        } else {
118
+		        }else {
119 119
 		            $resultArray[$subKey][$subVal] = urldecode($value);
120 120
 		        }
121
-		    } else {
121
+		    }else {
122 122
 		        $resultArray[$key] = urldecode($value);
123 123
 		    }
124 124
 		}
125 125
 		return $resultArray;
126 126
 	}
127 127
 
128
-	private static function checkRemoteIp(){
128
+	private static function checkRemoteIp() {
129 129
 		$remoteIp = $_SERVER["REMOTE_ADDR"];
130
-		foreach ($header_real_ip as $k){
130
+		foreach ($header_real_ip as $k) {
131 131
 			$realIp = $_SERVER[$k];
132 132
 			$realIp = trim($realIp);
133
-			if(strlen($realIp) > 0 && strcasecmp("unknown",$realIp)){
133
+			if (strlen($realIp) > 0 && strcasecmp("unknown", $realIp)) {
134 134
 				$remoteIp = $realIp;
135 135
 				break;
136 136
 			}
137 137
 		}
138
-		return self::startsWith($remoteIp,"140.205.144.") || self::startsWith($remoteIp,"40.205.145.");
138
+		return self::startsWith($remoteIp, "140.205.144.") || self::startsWith($remoteIp, "40.205.145.");
139 139
 	}
140 140
 
141
-	private static function getFormMap(){
141
+	private static function getFormMap() {
142 142
 		$resultArray = array();
143
-		foreach($_POST as $key=>$v) { 
144
-			$resultArray[$key] = $v ;
143
+		foreach ($_POST as $key=>$v) { 
144
+			$resultArray[$key] = $v;
145 145
 		}
146
-		return $resultArray ;	
146
+		return $resultArray;	
147 147
 	}
148 148
 
149 149
 	private static function startsWith($haystack, $needle) {
@@ -152,30 +152,30 @@  discard block
 block discarded – undo
152 152
 
153 153
 	private static function endWith($haystack, $needle) {   
154 154
 	    $length = strlen($needle);  
155
-	    if($length == 0)
155
+	    if ($length == 0)
156 156
 	    {    
157 157
 	        return true;  
158 158
 	    }  
159 159
 	    return (substr($haystack, -$length) === $needle);
160 160
  	}
161 161
 
162
-	private static function checkTimestamp(){
162
+	private static function checkTimestamp() {
163 163
 		$ts = $_POST['timestamp'];
164
-		if($ts){
164
+		if ($ts) {
165 165
 			$clientTimestamp = strtotime($ts);
166 166
 			$current = $_SERVER['REQUEST_TIME'];
167
-			return ($current - $clientTimestamp) <= 5*60*1000;
168
-		}else{
167
+			return ($current-$clientTimestamp) <= 5*60*1000;
168
+		}else {
169 169
 			return false;
170 170
 		}
171 171
 	}
172 172
 
173
-	private static function getParamStrFromMap($params){
173
+	private static function getParamStrFromMap($params) {
174 174
 		ksort($params);
175 175
 		$stringToBeSigned = "";
176 176
 		foreach ($params as $k => $v)
177 177
 		{
178
-			if(strcmp("sign", $k) != 0)
178
+			if (strcmp("sign", $k) != 0)
179 179
 			{
180 180
 				$stringToBeSigned .= "$k$v";
181 181
 			}
@@ -184,13 +184,13 @@  discard block
 block discarded – undo
184 184
 		return $stringToBeSigned;
185 185
 	}
186 186
 
187
-	private static function sign($params,$body,$secret){
187
+	private static function sign($params, $body, $secret) {
188 188
 		ksort($params);
189 189
 
190 190
 		$stringToBeSigned = $secret;
191 191
 		$stringToBeSigned .= self::getParamStrFromMap($params);
192 192
 
193
-		if($body)
193
+		if ($body)
194 194
 			$stringToBeSigned .= $body;
195 195
 		$stringToBeSigned .= $secret;
196 196
 		return strtoupper(md5($stringToBeSigned));
@@ -200,18 +200,18 @@  discard block
 block discarded – undo
200 200
 	{
201 201
 		$localIp = isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : "CLI";
202 202
 		$logger = new TopLogger;
203
-		$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_comm_err_". date("Y-m-d") . ".log";
203
+		$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/').'/'."logs/top_comm_err_".date("Y-m-d").".log";
204 204
 		$logger->conf["separator"] = "^_^";
205 205
 		$logData = array(
206
-		"checkTopSign error" ,
207
-		"remoteSign=".$remoteSign ,
208
-		"localSign=".$localSign ,
209
-		"paramStr=".$paramStr ,
206
+		"checkTopSign error",
207
+		"remoteSign=".$remoteSign,
208
+		"localSign=".$localSign,
209
+		"paramStr=".$paramStr,
210 210
 		"body=".$body
211 211
 		);
212 212
 		$logger->log($logData);
213 213
 	}
214
-	private static function clear_blank($str, $glue='')
214
+	private static function clear_blank($str, $glue = '')
215 215
 	{
216 216
 		$replace = array(" ", "\r", "\n", "\t"); return str_replace($replace, $glue, $str);
217 217
 	}
Please login to merge, or discard this patch.
src/service/taobao/bin/top/TopClient.php 1 patch
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -27,9 +27,9 @@  discard block
 block discarded – undo
27 27
 		return $this->appkey;
28 28
 	}
29 29
 
30
-	public function __construct($appkey = "",$secretKey = ""){
30
+	public function __construct($appkey = "", $secretKey = "") {
31 31
 		$this->appkey = $appkey;
32
-		$this->secretKey = $secretKey ;
32
+		$this->secretKey = $secretKey;
33 33
 	}
34 34
 
35 35
 	protected function generateSign($params)
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 		$stringToBeSigned = $this->secretKey;
40 40
 		foreach ($params as $k => $v)
41 41
 		{
42
-			if(!is_array($v) && "@" != substr($v, 0, 1))
42
+			if (!is_array($v) && "@" != substr($v, 0, 1))
43 43
 			{
44 44
 				$stringToBeSigned .= "$k$v";
45 45
 			}
@@ -62,9 +62,9 @@  discard block
 block discarded – undo
62 62
 		if ($this->connectTimeout) {
63 63
 			curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
64 64
 		}
65
-		curl_setopt ( $ch, CURLOPT_USERAGENT, "top-sdk-php" );
65
+		curl_setopt($ch, CURLOPT_USERAGENT, "top-sdk-php");
66 66
 		//https 请求
67
-		if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) {
67
+		if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") {
68 68
 			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
69 69
 			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
70 70
 		}
@@ -75,14 +75,14 @@  discard block
 block discarded – undo
75 75
 			$postMultipart = false;
76 76
 			foreach ($postFields as $k => $v)
77 77
 			{
78
-				if("@" != substr($v, 0, 1))//判断是不是文件上传
78
+				if ("@" != substr($v, 0, 1))//判断是不是文件上传
79 79
 				{
80
-					$postBodyString .= "$k=" . urlencode($v) . "&"; 
80
+					$postBodyString .= "$k=".urlencode($v)."&"; 
81 81
 				}
82 82
 				else//文件上传用multipart/form-data,否则用www-form-urlencoded
83 83
 				{
84 84
 					$postMultipart = true;
85
-					if(class_exists('\CURLFile')){
85
+					if (class_exists('\CURLFile')) {
86 86
 						$postFields[$k] = new \CURLFile(substr($v, 1));
87 87
 					}
88 88
 				}
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 			{
94 94
 				if (class_exists('\CURLFile')) {
95 95
 				    curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
96
-				} else {
96
+				}else {
97 97
 				    if (defined('CURLOPT_SAFE_UPLOAD')) {
98 98
 				        curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
99 99
 				    }
@@ -103,22 +103,22 @@  discard block
 block discarded – undo
103 103
 			else
104 104
 			{
105 105
 				$header = array("content-type: application/x-www-form-urlencoded; charset=UTF-8");
106
-				curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
107
-				curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString,0,-1));
106
+				curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
107
+				curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString, 0, -1));
108 108
 			}
109 109
 		}
110 110
 		$reponse = curl_exec($ch);
111 111
 		
112 112
 		if (curl_errno($ch))
113 113
 		{
114
-			throw new Exception(curl_error($ch),0);
114
+			throw new Exception(curl_error($ch), 0);
115 115
 		}
116 116
 		else
117 117
 		{
118 118
 			$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
119 119
 			if (200 !== $httpStatusCode)
120 120
 			{
121
-				throw new Exception($reponse,$httpStatusCode);
121
+				throw new Exception($reponse, $httpStatusCode);
122 122
 			}
123 123
 		}
124 124
 		curl_close($ch);
@@ -136,44 +136,44 @@  discard block
 block discarded – undo
136 136
 		if ($this->connectTimeout) {
137 137
 			curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
138 138
 		}
139
-		curl_setopt ( $ch, CURLOPT_USERAGENT, "top-sdk-php" );
139
+		curl_setopt($ch, CURLOPT_USERAGENT, "top-sdk-php");
140 140
 		//https 请求
141
-		if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) {
141
+		if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") {
142 142
 			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
143 143
 			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
144 144
 		}
145 145
 		//生成分隔符
146
-		$delimiter = '-------------' . uniqid();
146
+		$delimiter = '-------------'.uniqid();
147 147
 		//先将post的普通数据生成主体字符串
148 148
 		$data = '';
149
-		if($postFields != null){
149
+		if ($postFields != null) {
150 150
 			foreach ($postFields as $name => $content) {
151
-			    $data .= "--" . $delimiter . "\r\n";
152
-			    $data .= 'Content-Disposition: form-data; name="' . $name . '"';
151
+			    $data .= "--".$delimiter."\r\n";
152
+			    $data .= 'Content-Disposition: form-data; name="'.$name.'"';
153 153
 			    //multipart/form-data 不需要urlencode,参见 http:stackoverflow.com/questions/6603928/should-i-url-encode-post-data
154
-			    $data .= "\r\n\r\n" . $content . "\r\n";
154
+			    $data .= "\r\n\r\n".$content."\r\n";
155 155
 			}
156
-			unset($name,$content);
156
+			unset($name, $content);
157 157
 		}
158 158
 
159 159
 		//将上传的文件生成主体字符串
160
-		if($fileFields != null){
160
+		if ($fileFields != null) {
161 161
 			foreach ($fileFields as $name => $file) {
162
-			    $data .= "--" . $delimiter . "\r\n";
163
-			    $data .= 'Content-Disposition: form-data; name="' . $name . '"; filename="' . $file['name'] . "\" \r\n";
164
-			    $data .= 'Content-Type: ' . $file['type'] . "\r\n\r\n";//多了个文档类型
162
+			    $data .= "--".$delimiter."\r\n";
163
+			    $data .= 'Content-Disposition: form-data; name="'.$name.'"; filename="'.$file['name']."\" \r\n";
164
+			    $data .= 'Content-Type: '.$file['type']."\r\n\r\n"; //多了个文档类型
165 165
 
166
-			    $data .= $file['content'] . "\r\n";
166
+			    $data .= $file['content']."\r\n";
167 167
 			}
168
-			unset($name,$file);
168
+			unset($name, $file);
169 169
 		}
170 170
 		//主体结束的分隔符
171
-		$data .= "--" . $delimiter . "--";
171
+		$data .= "--".$delimiter."--";
172 172
 
173 173
 		curl_setopt($ch, CURLOPT_POST, true);
174
-		curl_setopt($ch, CURLOPT_HTTPHEADER , array(
175
-		    'Content-Type: multipart/form-data; boundary=' . $delimiter,
176
-		    'Content-Length: ' . strlen($data))
174
+		curl_setopt($ch, CURLOPT_HTTPHEADER, array(
175
+		    'Content-Type: multipart/form-data; boundary='.$delimiter,
176
+		    'Content-Length: '.strlen($data))
177 177
 		); 
178 178
 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
179 179
 		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
@@ -183,14 +183,14 @@  discard block
 block discarded – undo
183 183
 
184 184
 		if (curl_errno($ch))
185 185
 		{
186
-			throw new Exception(curl_error($ch),0);
186
+			throw new Exception(curl_error($ch), 0);
187 187
 		}
188 188
 		else
189 189
 		{
190 190
 			$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
191 191
 			if (200 !== $httpStatusCode)
192 192
 			{
193
-				throw new Exception($reponse,$httpStatusCode);
193
+				throw new Exception($reponse, $httpStatusCode);
194 194
 			}
195 195
 		}
196 196
 		curl_close($ch);
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 	{
202 202
 		$localIp = isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : "CLI";
203 203
 		$logger = new TopLogger;
204
-		$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_comm_err_" . $this->appkey . "_" . date("Y-m-d") . ".log";
204
+		$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/').'/'."logs/top_comm_err_".$this->appkey."_".date("Y-m-d").".log";
205 205
 		$logger->conf["separator"] = "^_^";
206 206
 		$logData = array(
207 207
 		date("Y-m-d H:i:s"),
@@ -212,15 +212,15 @@  discard block
 block discarded – undo
212 212
 		$this->sdkVersion,
213 213
 		$requestUrl,
214 214
 		$errorCode,
215
-		str_replace("\n","",$responseTxt)
215
+		str_replace("\n", "", $responseTxt)
216 216
 		);
217 217
 		$logger->log($logData);
218 218
 	}
219 219
 
220
-	public function execute($request, $session = null,$bestUrl = null)
220
+	public function execute($request, $session = null, $bestUrl = null)
221 221
 	{
222
-		$result =  new ResultSet(); 
223
-		if($this->checkRequest) {
222
+		$result = new ResultSet(); 
223
+		if ($this->checkRequest) {
224 224
 			try {
225 225
 				$request->check();
226 226
 			} catch (Exception $e) {
@@ -247,10 +247,10 @@  discard block
 block discarded – undo
247 247
 
248 248
 
249 249
 		//系统参数放入GET请求串
250
-		if($bestUrl){
250
+		if ($bestUrl) {
251 251
 			$requestUrl = $bestUrl."?";
252 252
 			$sysParams["partner_id"] = $this->getClusterTag();
253
-		}else{
253
+		}else {
254 254
 			$requestUrl = $this->gatewayUrl."?";
255 255
 			$sysParams["partner_id"] = $this->sdkVersion;
256 256
 		}
@@ -260,12 +260,12 @@  discard block
 block discarded – undo
260 260
 		foreach ($sysParams as $sysParamKey => $sysParamValue)
261 261
 		{
262 262
 			// if(strcmp($sysParamKey,"timestamp") != 0)
263
-			$requestUrl .= "$sysParamKey=" . urlencode($sysParamValue) . "&";
263
+			$requestUrl .= "$sysParamKey=".urlencode($sysParamValue)."&";
264 264
 		}
265 265
 
266 266
 		$fileFields = array();
267 267
 		foreach ($apiParams as $key => $value) {
268
-			if(is_array($value) && array_key_exists('type',$value) && array_key_exists('content',$value) ){
268
+			if (is_array($value) && array_key_exists('type', $value) && array_key_exists('content', $value)) {
269 269
 				$value['name'] = $key;
270 270
 				$fileFields[$key] = $value;
271 271
 				unset($apiParams[$key]);
@@ -278,15 +278,15 @@  discard block
 block discarded – undo
278 278
 		//发起HTTP请求
279 279
 		try
280 280
 		{
281
-			if(count($fileFields) > 0){
281
+			if (count($fileFields) > 0) {
282 282
 				$resp = $this->curl_with_memory_file($requestUrl, $apiParams, $fileFields);
283
-			}else{
283
+			}else {
284 284
 				$resp = $this->curl($requestUrl, $apiParams);
285 285
 			}
286 286
 		}
287 287
 		catch (Exception $e)
288 288
 		{
289
-			$this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_ERROR_" . $e->getCode(),$e->getMessage());
289
+			$this->logCommunicationError($sysParams["method"], $requestUrl, "HTTP_ERROR_".$e->getCode(), $e->getMessage());
290 290
 			$result->code = $e->getCode();
291 291
 			$result->msg = $e->getMessage();
292 292
 			return $result;
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
 				}
309 309
 			}
310 310
 		}
311
-		else if("xml" == $this->format)
311
+		else if ("xml" == $this->format)
312 312
 		{
313 313
 			$respObject = @simplexml_load_string($resp);
314 314
 			if (false !== $respObject)
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 		//返回的HTTP文本不是标准JSON或者XML,记下错误日志
321 321
 		if (false === $respWellFormed)
322 322
 		{
323
-			$this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_RESPONSE_NOT_WELL_FORMED",$resp);
323
+			$this->logCommunicationError($sysParams["method"], $requestUrl, "HTTP_RESPONSE_NOT_WELL_FORMED", $resp);
324 324
 			$result->code = 0;
325 325
 			$result->msg = "HTTP_RESPONSE_NOT_WELL_FORMED";
326 326
 			return $result;
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 		if (isset($respObject->code))
331 331
 		{
332 332
 			$logger = new TopLogger;
333
-			$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_biz_err_" . $this->appkey . "_" . date("Y-m-d") . ".log";
333
+			$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/').'/'."logs/top_biz_err_".$this->appkey."_".date("Y-m-d").".log";
334 334
 			$logger->log(array(
335 335
 				date("Y-m-d H:i:s"),
336 336
 				$resp
@@ -347,21 +347,21 @@  discard block
 block discarded – undo
347 347
 		}
348 348
 		$inflector = new LtInflector;
349 349
 		$inflector->conf["separator"] = ".";
350
-		$requestClassName = ucfirst($inflector->camelize(substr($paramsArray["method"], 7))) . "Request";
350
+		$requestClassName = ucfirst($inflector->camelize(substr($paramsArray["method"], 7)))."Request";
351 351
 		if (!class_exists($requestClassName))
352 352
 		{
353
-			trigger_error("No such api: " . $paramsArray["method"]);
353
+			trigger_error("No such api: ".$paramsArray["method"]);
354 354
 		}
355 355
 
356 356
 		$session = isset($paramsArray["session"]) ? $paramsArray["session"] : null;
357 357
 
358 358
 		$req = new $requestClassName;
359
-		foreach($paramsArray as $paraKey => $paraValue)
359
+		foreach ($paramsArray as $paraKey => $paraValue)
360 360
 		{
361 361
 			$inflector->conf["separator"] = "_";
362 362
 			$setterMethodName = $inflector->camelize($paraKey);
363 363
 			$inflector->conf["separator"] = ".";
364
-			$setterMethodName = "set" . $inflector->camelize($setterMethodName);
364
+			$setterMethodName = "set".$inflector->camelize($setterMethodName);
365 365
 			if (method_exists($req, $setterMethodName))
366 366
 			{
367 367
 				$req->$setterMethodName($paraValue);
@@ -372,6 +372,6 @@  discard block
 block discarded – undo
372 372
 
373 373
 	private function getClusterTag()
374 374
     {
375
-	    return substr($this->sdkVersion,0,11)."-cluster".substr($this->sdkVersion,11);
375
+	    return substr($this->sdkVersion, 0, 11)."-cluster".substr($this->sdkVersion, 11);
376 376
     }
377 377
 }
Please login to merge, or discard this patch.
src/service/taobao/bin/top/security/iCache.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
 	public function getCache($key);
9 9
 
10 10
 	//更新缓存
11
-	public function setCache($key,$var);
11
+	public function setCache($key, $var);
12 12
 
13 13
 }
14 14
 ?>
15 15
\ No newline at end of file
Please login to merge, or discard this patch.
src/service/taobao/bin/top/security/YacCache.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -15,21 +15,21 @@
 block discarded – undo
15 15
 	public function getCache($key)
16 16
 	{
17 17
 		$key = md5($key);
18
-		if($this->isEnable){
18
+		if ($this->isEnable) {
19 19
 			$yac = new Yac();
20 20
 			return $yac->get($key);
21
-		}else{
21
+		}else {
22 22
 			echo "yac is not enable ,skip getCache";
23 23
 		}
24 24
 	}
25 25
 
26
-	public function setCache($key,$var)
26
+	public function setCache($key, $var)
27 27
 	{
28 28
 		$key = md5($key);
29
-		if($this->isEnable){
29
+		if ($this->isEnable) {
30 30
 			$yac = new Yac();
31 31
 			$yac->set($key, $var);
32
-		}else{
32
+		}else {
33 33
 			echo "yac is not enable ,skip setCache";
34 34
 		}
35 35
 	}
Please login to merge, or discard this patch.
src/service/taobao/bin/top/security/MagicCrypt.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -20,12 +20,12 @@  discard block
 block discarded – undo
20 20
 
21 21
         public static function hmac_md5($input, $key) {
22 22
             $key = base64_decode($key);
23
-            return hash_hmac('md5', $input, $key,true);
23
+            return hash_hmac('md5', $input, $key, true);
24 24
         }
25 25
      
26
-        private static function pkcs5_pad ($text, $blocksize) {
27
-            $pad = $blocksize - (strlen($text) % $blocksize);
28
-            return $text . str_repeat(chr($pad), $pad);
26
+        private static function pkcs5_pad($text, $blocksize) {
27
+            $pad = $blocksize-(strlen($text)%$blocksize);
28
+            return $text.str_repeat(chr($pad), $pad);
29 29
         }
30 30
      
31 31
         public static function decrypt($sStr, $key) {
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 
43 43
             mcrypt_generic_deinit($module);
44 44
             mcrypt_module_close($module);
45
-            if(!$decrypted){
45
+            if (!$decrypted) {
46 46
                 throw new Exception("Decrypt Error,Please Check SecretKey");
47 47
             }
48 48
             return $decrypted;
Please login to merge, or discard this patch.
src/service/taobao/bin/top/security/SecurityUtil.php 1 patch
Spacing   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -11,17 +11,17 @@  discard block
 block discarded – undo
11 11
 
12 12
 		function __construct()
13 13
 		{
14
-			if(!defined("PHONE_SEPARATOR_CHAR"))
14
+			if (!defined("PHONE_SEPARATOR_CHAR"))
15 15
 			{
16
-				define('PHONE_SEPARATOR_CHAR','$');
16
+				define('PHONE_SEPARATOR_CHAR', '$');
17 17
 			}
18
-			if(!defined("NICK_SEPARATOR_CHAR"))
18
+			if (!defined("NICK_SEPARATOR_CHAR"))
19 19
 			{
20
-				define('NICK_SEPARATOR_CHAR','~');
20
+				define('NICK_SEPARATOR_CHAR', '~');
21 21
 			}
22
-			if(!defined("NORMAL_SEPARATOR_CHAR"))
22
+			if (!defined("NORMAL_SEPARATOR_CHAR"))
23 23
 			{
24
-				define('NORMAL_SEPARATOR_CHAR',chr(1));
24
+				define('NORMAL_SEPARATOR_CHAR', chr(1));
25 25
 			}
26 26
 
27 27
 			$this->SEPARATOR_CHAR_MAP['nick'] = NICK_SEPARATOR_CHAR;
@@ -39,9 +39,9 @@  discard block
 block discarded – undo
39 39
 		function isBase64Str($str)
40 40
 		{
41 41
 			$strLen = strlen($str);
42
-			for($i = 0; $i < $strLen ; $i++)
42
+			for ($i = 0; $i < $strLen; $i++)
43 43
 			{
44
-				if(!$this->isBase64Char($str[$i]))
44
+				if (!$this->isBase64Char($str[$i]))
45 45
 				{
46 46
 					return false;
47 47
 				}
@@ -54,46 +54,46 @@  discard block
 block discarded – undo
54 54
 		*/
55 55
 		function isBase64Char($char)
56 56
 		{
57
-			return strpos($this->BASE64_ARRAY,$char) !== false;
57
+			return strpos($this->BASE64_ARRAY, $char) !== false;
58 58
 		}
59 59
 
60 60
 		/*
61 61
 		* 使用sep字符进行trim
62 62
 		*/
63
-		function trimBySep($str,$sep)
63
+		function trimBySep($str, $sep)
64 64
 		{
65 65
 			$start = 0;
66 66
 			$end = strlen($str);
67
-			for($i = 0; $i < $end; $i++)
67
+			for ($i = 0; $i < $end; $i++)
68 68
 			{
69
-				if($str[$i] == $sep)
69
+				if ($str[$i] == $sep)
70 70
 				{
71
-					$start = $i + 1;
71
+					$start = $i+1;
72 72
 				}
73 73
 				else
74 74
 				{
75 75
 					break;
76 76
 				}
77 77
 			}
78
-			for($i = $end -1 ; $i >= 0; $i--)
78
+			for ($i = $end-1; $i >= 0; $i--)
79 79
 			{
80
-				if($str[$i] == $sep)
80
+				if ($str[$i] == $sep)
81 81
 				{
82
-					$end = $i - 1;
82
+					$end = $i-1;
83 83
 				}
84 84
 				else
85 85
 				{
86 86
 					break;
87 87
 				}
88 88
 			}
89
-			return substr($str,$start,$end);
89
+			return substr($str, $start, $end);
90 90
 		}
91 91
 
92 92
 		function checkEncryptData($dataArray)
93 93
 		{
94
-			if(count($dataArray) == 2){
94
+			if (count($dataArray) == 2) {
95 95
 				return  $this->isBase64Str($dataArray[0]);
96
-			}else{
96
+			}else {
97 97
 				return  $this->isBase64Str($dataArray[0]) && $this->isBase64Str($dataArray[1]);
98 98
 			}
99 99
 		}
@@ -101,10 +101,10 @@  discard block
 block discarded – undo
101 101
 		/*
102 102
 		* 判断是否是加密数据
103 103
 		*/
104
-		function isEncryptDataArray($array,$type)
104
+		function isEncryptDataArray($array, $type)
105 105
 		{
106 106
 			foreach ($array as $value) {
107
-				if(!$this->isEncryptData($value,$type)){
107
+				if (!$this->isEncryptData($value, $type)) {
108 108
 					return false;
109 109
 				}
110 110
 			}
@@ -114,11 +114,11 @@  discard block
 block discarded – undo
114 114
 		/**
115 115
 		* 判断是否是已加密的数据,数据必须是同一个类型
116 116
 		*/
117
-		function isPartEncryptData($array,$type)
117
+		function isPartEncryptData($array, $type)
118 118
 		{
119 119
 			$result = false;
120 120
 			foreach ($array as $value) {
121
-				if($this->isEncryptData($value,$type)){
121
+				if ($this->isEncryptData($value, $type)) {
122 122
 					$result = true;
123 123
 					break;
124 124
 				}
@@ -129,48 +129,48 @@  discard block
 block discarded – undo
129 129
 		/*
130 130
 		* 判断是否是加密数据
131 131
 		*/
132
-		function isEncryptData($data,$type)
132
+		function isEncryptData($data, $type)
133 133
 		{
134
-			if(!is_string($data) || strlen($data) < 4)
134
+			if (!is_string($data) || strlen($data) < 4)
135 135
 			{
136 136
 				return false;
137 137
 			}
138 138
 
139 139
 			$separator = $this->SEPARATOR_CHAR_MAP[$type];
140 140
 			$strlen = strlen($data);
141
-			if($data[0] != $separator || $data[$strlen -1] != $separator)
141
+			if ($data[0] != $separator || $data[$strlen-1] != $separator)
142 142
 			{
143 143
 				return false;
144 144
 			}
145 145
 
146
-			$dataArray = explode($separator,$this->trimBySep($data,$separator));
146
+			$dataArray = explode($separator, $this->trimBySep($data, $separator));
147 147
 			$arrayLength = count($dataArray);
148 148
 
149
-			if($separator == PHONE_SEPARATOR_CHAR)
149
+			if ($separator == PHONE_SEPARATOR_CHAR)
150 150
 			{
151
-				if($arrayLength != 3)
151
+				if ($arrayLength != 3)
152 152
 				{
153 153
 					return false;
154 154
 				}
155
-				if($data[$strlen - 2] == $separator)
155
+				if ($data[$strlen-2] == $separator)
156 156
 				{
157 157
 					return $this->checkEncryptData($dataArray);
158 158
 				} 
159 159
 				else
160 160
 				{
161
-					$version = $dataArray[$arrayLength -1];
162
-					if(is_numeric($version))
161
+					$version = $dataArray[$arrayLength-1];
162
+					if (is_numeric($version))
163 163
 					{
164
-						$base64Val = $dataArray[$arrayLength -2];
164
+						$base64Val = $dataArray[$arrayLength-2];
165 165
 						return $this->isBase64Str($base64Val);
166 166
 					}
167 167
 				}
168
-			}else{
169
-				if($data[strlen($data) - 2] == $separator && $arrayLength == 3)
168
+			}else {
169
+				if ($data[strlen($data)-2] == $separator && $arrayLength == 3)
170 170
 				{
171 171
 					return $this->checkEncryptData($dataArray);
172 172
 				}
173
-				else if($arrayLength == 2)
173
+				else if ($arrayLength == 2)
174 174
 				{
175 175
 					return $this->checkEncryptData($dataArray);
176 176
 				}
@@ -181,22 +181,22 @@  discard block
 block discarded – undo
181 181
 			}
182 182
 		}
183 183
 
184
-		function search($data, $type,$secretContext)
184
+		function search($data, $type, $secretContext)
185 185
 		{
186 186
 			$separator = $this->SEPARATOR_CHAR_MAP[$type];
187
-			if('phone' == $type) {
188
-		        if (strlen($data) != 4 ) {
187
+			if ('phone' == $type) {
188
+		        if (strlen($data) != 4) {
189 189
 		            throw new Exception("phoneNumber error");
190 190
 		        }
191 191
 		        return $separator.$this->hmacMD5EncryptToBase64($data, $secretContext->secret).$separator;
192
-			} else {
193
-				$compressLen = $this->getArrayValue($secretContext->appConfig,'encrypt_index_compress_len',3);
194
-				$slideSize = $this->getArrayValue($secretContext->appConfig,'encrypt_slide_size',4);
192
+			}else {
193
+				$compressLen = $this->getArrayValue($secretContext->appConfig, 'encrypt_index_compress_len', 3);
194
+				$slideSize = $this->getArrayValue($secretContext->appConfig, 'encrypt_slide_size', 4);
195 195
 
196 196
 				$slideList = $this->getSlideWindows($data, $slideSize);
197 197
 		        $builder = '';
198 198
 		        foreach ($slideList as $slide) {
199
-					$builder .= $this->hmacMD5EncryptToBase64($slide,$secretContext->secret,$compressLen);
199
+					$builder .= $this->hmacMD5EncryptToBase64($slide, $secretContext->secret, $compressLen);
200 200
 				}
201 201
 		        return $builder;
202 202
 			}
@@ -205,28 +205,28 @@  discard block
 block discarded – undo
205 205
 		/*
206 206
 		* 加密逻辑
207 207
 		*/
208
-		function encrypt($data,$type,$version,$secretContext)
208
+		function encrypt($data, $type, $version, $secretContext)
209 209
 		{
210
-			if(!is_string($data))
210
+			if (!is_string($data))
211 211
 			{
212 212
 				return false;
213 213
 			}
214 214
 
215 215
 			$separator = $this->SEPARATOR_CHAR_MAP[$type];
216
-			$isIndexEncrypt = $this->isIndexEncrypt($type,$version,$secretContext);
217
-			if($isIndexEncrypt || $type == "search"){
218
-				if('phone' == $type) {
219
-					return $this->encryptPhoneIndex($data,$separator,$secretContext);
220
-				} else {
221
-					$compressLen = $this->getArrayValue($secretContext->appConfig,'encrypt_index_compress_len',3);
222
-					$slideSize = $this->getArrayValue($secretContext->appConfig,'encrypt_slide_size',4);
223
-					return $this->encryptNormalIndex($data,$compressLen,$slideSize,$separator,$secretContext);
216
+			$isIndexEncrypt = $this->isIndexEncrypt($type, $version, $secretContext);
217
+			if ($isIndexEncrypt || $type == "search") {
218
+				if ('phone' == $type) {
219
+					return $this->encryptPhoneIndex($data, $separator, $secretContext);
220
+				}else {
221
+					$compressLen = $this->getArrayValue($secretContext->appConfig, 'encrypt_index_compress_len', 3);
222
+					$slideSize = $this->getArrayValue($secretContext->appConfig, 'encrypt_slide_size', 4);
223
+					return $this->encryptNormalIndex($data, $compressLen, $slideSize, $separator, $secretContext);
224 224
 				}
225
-			}else{
226
-				if('phone' == $type) {
227
-					return $this->encryptPhone($data,$separator,$secretContext);
228
-				} else {
229
-					return $this->encryptNormal($data,$separator,$secretContext);
225
+			}else {
226
+				if ('phone' == $type) {
227
+					return $this->encryptPhone($data, $separator, $secretContext);
228
+				}else {
229
+					return $this->encryptNormal($data, $separator, $secretContext);
230 230
 				}
231 231
 			}
232 232
 
@@ -235,35 +235,35 @@  discard block
 block discarded – undo
235 235
 		/*
236 236
 		* 加密逻辑,手机号码格式
237 237
 		*/
238
-		function encryptPhone($data,$separator,$secretContext)
238
+		function encryptPhone($data, $separator, $secretContext)
239 239
 		{
240 240
 			$len = strlen($data);
241
-			if($len < 11)
241
+			if ($len < 11)
242 242
 			{
243 243
 				return $data;
244 244
 			}
245
-			$prefixNumber = substr($data,0,$len -8);
246
-			$last8Number =  substr($data,$len -8,$len);
245
+			$prefixNumber = substr($data, 0, $len-8);
246
+			$last8Number = substr($data, $len-8, $len);
247 247
 
248
-			return $separator.$prefixNumber.$separator.Security::encrypt($last8Number,$secretContext->secret)
249
-				  .$separator.$secretContext->secretVersion.$separator ;
248
+			return $separator.$prefixNumber.$separator.Security::encrypt($last8Number, $secretContext->secret)
249
+				  .$separator.$secretContext->secretVersion.$separator;
250 250
 		}
251 251
 
252 252
 		/*
253 253
 		* 加密逻辑,非手机号码格式
254 254
 		*/
255
-		function encryptNormal($data,$separator,$secretContext)
255
+		function encryptNormal($data, $separator, $secretContext)
256 256
 		{
257
-			return $separator.Security::encrypt($data,$secretContext->secret)
257
+			return $separator.Security::encrypt($data, $secretContext->secret)
258 258
 							 .$separator.$secretContext->secretVersion.$separator;
259 259
 		}
260 260
 
261 261
 		/*
262 262
 		* 解密逻辑
263 263
 		*/
264
-		function decrypt($data,$type,$secretContext)
264
+		function decrypt($data, $type, $secretContext)
265 265
 		{			
266
-			if(!$this->isEncryptData($data,$type))
266
+			if (!$this->isEncryptData($data, $type))
267 267
 			{
268 268
 				throw new Exception("数据[".$data."]不是类型为[".$type."]的加密数据");
269 269
 			}
@@ -271,19 +271,19 @@  discard block
 block discarded – undo
271 271
 			$separator = $this->SEPARATOR_CHAR_MAP[$type];
272 272
 
273 273
 			$secretData = null;
274
-			if($data[$dataLen - 2] == $separator){
275
-				$secretData = $this->getIndexSecretData($data,$separator);
276
-			}else{
277
-				$secretData = $this->getSecretData($data,$separator);
274
+			if ($data[$dataLen-2] == $separator) {
275
+				$secretData = $this->getIndexSecretData($data, $separator);
276
+			}else {
277
+				$secretData = $this->getSecretData($data, $separator);
278 278
 			}
279 279
 			
280
-			if($secretData == null){
280
+			if ($secretData == null) {
281 281
 				return $data;
282 282
 			}
283 283
 
284
-			$result = Security::decrypt($secretData->originalBase64Value,$secretContext->secret);
284
+			$result = Security::decrypt($secretData->originalBase64Value, $secretContext->secret);
285 285
 
286
-			if($separator == PHONE_SEPARATOR_CHAR && !$secretData->search)
286
+			if ($separator == PHONE_SEPARATOR_CHAR && !$secretData->search)
287 287
 			{
288 288
 				return $secretData->originalValue.$result;
289 289
 			}
@@ -293,46 +293,46 @@  discard block
 block discarded – undo
293 293
 		/*
294 294
 		* 判断是否是公钥数据
295 295
 		*/
296
-		function isPublicData($data,$type)
296
+		function isPublicData($data, $type)
297 297
 		{
298
-			$secretData = $this->getSecretDataByType($data,$type);
299
-			if(empty($secretData)){
298
+			$secretData = $this->getSecretDataByType($data, $type);
299
+			if (empty($secretData)) {
300 300
 				return false;
301 301
 			}
302
-			if(intval($secretData->secretVersion) < 0){
302
+			if (intval($secretData->secretVersion) < 0) {
303 303
 				return true;
304 304
 			}
305 305
 			return false;
306 306
 		}
307 307
 
308
-		function getSecretDataByType($data,$type)
308
+		function getSecretDataByType($data, $type)
309 309
 		{
310 310
 			$separator = $this->SEPARATOR_CHAR_MAP[$type];
311 311
 			$dataLen = strlen($data);
312 312
 
313
-			if($data[$dataLen - 2] == $separator){
314
-				return $secretData = $this->getIndexSecretData($data,$separator);
315
-			}else{
316
-				return  $secretData = $this->getSecretData($data,$separator);
313
+			if ($data[$dataLen-2] == $separator) {
314
+				return $secretData = $this->getIndexSecretData($data, $separator);
315
+			}else {
316
+				return  $secretData = $this->getSecretData($data, $separator);
317 317
 			}
318 318
 		}
319 319
 
320 320
 		/*
321 321
 		* 分解密文
322 322
 		*/
323
-		function getSecretData($data,$separator)
323
+		function getSecretData($data, $separator)
324 324
 		{
325 325
 			$secretData = new SecretData;
326
-			$dataArray = explode($separator,$this->trimBySep($data,$separator));
326
+			$dataArray = explode($separator, $this->trimBySep($data, $separator));
327 327
 			$arrayLength = count($dataArray);
328 328
 
329
-			if($separator == PHONE_SEPARATOR_CHAR)
329
+			if ($separator == PHONE_SEPARATOR_CHAR)
330 330
 			{
331
-				if($arrayLength != 3){
331
+				if ($arrayLength != 3) {
332 332
 					return null;
333
-				}else{
333
+				}else {
334 334
 					$version = $dataArray[2];
335
-					if(is_numeric($version))
335
+					if (is_numeric($version))
336 336
 					{
337 337
 						$secretData->originalValue = $dataArray[0];
338 338
 						$secretData->originalBase64Value = $dataArray[1];
@@ -342,11 +342,11 @@  discard block
 block discarded – undo
342 342
 			}
343 343
 			else
344 344
 			{
345
-				if($arrayLength != 2){
345
+				if ($arrayLength != 2) {
346 346
 					return null;
347
-				}else{
347
+				}else {
348 348
 					$version = $dataArray[1];
349
-					if(is_numeric($version))
349
+					if (is_numeric($version))
350 350
 					{
351 351
 						$secretData->originalBase64Value = $dataArray[0];
352 352
 						$secretData->secretVersion = $version;
@@ -356,17 +356,17 @@  discard block
 block discarded – undo
356 356
 			return $secretData;
357 357
 		}
358 358
 
359
-		function getIndexSecretData($data,$separator) {
359
+		function getIndexSecretData($data, $separator) {
360 360
 			$secretData = new SecretData;
361
-			$dataArray = explode($separator,$this->trimBySep($data,$separator));
361
+			$dataArray = explode($separator, $this->trimBySep($data, $separator));
362 362
 			$arrayLength = count($dataArray);
363 363
 
364
-	        if($separator == PHONE_SEPARATOR_CHAR) {
364
+	        if ($separator == PHONE_SEPARATOR_CHAR) {
365 365
 	            if ($arrayLength != 3) {
366 366
 	                return null;
367
-	            }else{
367
+	            }else {
368 368
 					$version = $dataArray[2];
369
-					if(is_numeric($version))
369
+					if (is_numeric($version))
370 370
 					{
371 371
 						$secretData->originalValue = $dataArray[0];
372 372
 						$secretData->originalBase64Value = $dataArray[1];
@@ -374,12 +374,12 @@  discard block
 block discarded – undo
374 374
 					}
375 375
 	            }
376 376
 	            
377
-	        } else {
378
-	        	if($arrayLength != 3){
377
+	        }else {
378
+	        	if ($arrayLength != 3) {
379 379
 					return null;
380
-				} else {
380
+				}else {
381 381
 					$version = $dataArray[2];
382
-					if(is_numeric($version))
382
+					if (is_numeric($version))
383 383
 					{
384 384
 						$secretData->originalBase64Value = $dataArray[0];
385 385
 						$secretData->originalValue = $dataArray[1];
@@ -399,16 +399,16 @@  discard block
 block discarded – undo
399 399
 	     * @param version
400 400
 	     * @return
401 401
 	     */
402
-		function isIndexEncrypt($key,$version,$secretContext)
402
+		function isIndexEncrypt($key, $version, $secretContext)
403 403
 		{
404 404
 	        if ($version != null && $version < 0) {
405 405
 	            $key = "previous_".$key;
406
-	        } else {
406
+	        }else {
407 407
 	            $key = "current_".$key;
408 408
 	        }
409 409
 
410 410
 	        return $secretContext->appConfig != null && 
411
-	               array_key_exists($key,$secretContext->appConfig) && 
411
+	               array_key_exists($key, $secretContext->appConfig) && 
412 412
 	               $secretContext->appConfig[$key] == "2";
413 413
 		}
414 414
 
@@ -428,36 +428,36 @@  discard block
 block discarded – undo
428 428
 			return count($match[0]);
429 429
 		}
430 430
 
431
-		function utf8_substr($string,$start,$end) {
431
+		function utf8_substr($string, $start, $end) {
432 432
 			// 将字符串分解为单元
433 433
 			preg_match_all("/./us", $string, $match);
434 434
 			// 返回单元个数
435 435
 			$result = "";
436
-			for($i = $start; $i < $end; $i++){
436
+			for ($i = $start; $i < $end; $i++) {
437 437
 				$result .= $match[0][$i];
438 438
 			}
439 439
 			return $result;
440 440
 		}
441 441
 
442
-		function utf8_str_at($string,$index) {
442
+		function utf8_str_at($string, $index) {
443 443
 			// 将字符串分解为单元
444 444
 			preg_match_all("/./us", $string, $match);
445 445
 			// 返回单元个数
446 446
 			return $match[0][$index];
447 447
 		}
448 448
 
449
-		function compress($input,$toLength) {
450
-			if($toLength < 0) {
449
+		function compress($input, $toLength) {
450
+			if ($toLength < 0) {
451 451
 				return null;
452 452
 			}
453 453
 			$output = array();
454
-			for($i = 0; $i < $toLength; $i++) {
454
+			for ($i = 0; $i < $toLength; $i++) {
455 455
 				$output[$i] = chr(0);
456 456
 			}
457 457
 			$input = $this->getBytes($input);
458 458
 			$inputLength = count($input);
459 459
 			for ($i = 0; $i < $inputLength; $i++) {
460
-	            $index_output = $i % $toLength;
460
+	            $index_output = $i%$toLength;
461 461
 	            $output[$index_output] = $output[$index_output] ^ $input[$i];
462 462
 	        }
463 463
 	        return $output;
@@ -474,10 +474,10 @@  discard block
 block discarded – undo
474 474
 	     * @return
475 475
 	     * @throws Exception
476 476
 	     */
477
-		function hmacMD5EncryptToBase64($encryptText,$encryptKey,$compressLen = 0) {
478
-			$encryptResult = Security::hmac_md5($encryptText,$encryptKey);
479
-			if($compressLen != 0){
480
-				$encryptResult = $this->compress($encryptResult,$compressLen);
477
+		function hmacMD5EncryptToBase64($encryptText, $encryptKey, $compressLen = 0) {
478
+			$encryptResult = Security::hmac_md5($encryptText, $encryptKey);
479
+			if ($compressLen != 0) {
480
+				$encryptResult = $this->compress($encryptResult, $compressLen);
481 481
 			}
482 482
 			return base64_encode($this->toStr($encryptResult));
483 483
 		}
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
 	     * @param slideSize
491 491
 	     * @return
492 492
 	     */
493
-		function getSlideWindows($input,$slideSize = 4)
493
+		function getSlideWindows($input, $slideSize = 4)
494 494
 		{
495 495
 			$endIndex = 0;
496 496
 			$startIndex = 0;
@@ -498,70 +498,70 @@  discard block
 block discarded – undo
498 498
 			$currentWindow = null;
499 499
 			$dataLength = $this->utf8_strlen($input);
500 500
 			$windows = array();
501
-			while($endIndex < $dataLength || $currentWindowSize > $slideSize) 
501
+			while ($endIndex < $dataLength || $currentWindowSize > $slideSize) 
502 502
 			{
503 503
 				$startsWithLetterOrDigit = false;
504
-				if(!empty($currentWindow)){
505
-					$startsWithLetterOrDigit = $this->isLetterOrDigit($this->utf8_str_at($currentWindow,0));
504
+				if (!empty($currentWindow)) {
505
+					$startsWithLetterOrDigit = $this->isLetterOrDigit($this->utf8_str_at($currentWindow, 0));
506 506
 				}
507
-				if($endIndex == $dataLength && $startsWithLetterOrDigit == false){
507
+				if ($endIndex == $dataLength && $startsWithLetterOrDigit == false) {
508 508
 					break;
509 509
 				}
510
-				if($currentWindowSize == $slideSize && 
510
+				if ($currentWindowSize == $slideSize && 
511 511
 				   $startsWithLetterOrDigit == false && 
512
-				   $this->isLetterOrDigit($this->utf8_str_at($input,$endIndex))) {
513
-				   $endIndex ++;
514
-				   $currentWindow = $this->utf8_substr($input,$startIndex,$endIndex);
512
+				   $this->isLetterOrDigit($this->utf8_str_at($input, $endIndex))) {
513
+				   $endIndex++;
514
+				   $currentWindow = $this->utf8_substr($input, $startIndex, $endIndex);
515 515
 				   $currentWindowSize = 5;
516
-				} else {
517
-				    if($endIndex != 0){
518
-				    	if($startsWithLetterOrDigit){
516
+				}else {
517
+				    if ($endIndex != 0) {
518
+				    	if ($startsWithLetterOrDigit) {
519 519
 				    		$currentWindowSize -= 1;
520
-				    	}else{
520
+				    	}else {
521 521
 				    		$currentWindowSize -= 2;
522 522
 				    	}
523
-				    	$startIndex ++;
523
+				    	$startIndex++;
524 524
 				    }
525 525
 
526 526
 	                while ($currentWindowSize < $slideSize && $endIndex < $dataLength) {
527
-	                    $currentChar = $this->utf8_str_at($input,$endIndex);
527
+	                    $currentChar = $this->utf8_str_at($input, $endIndex);
528 528
 	                    if ($this->isLetterOrDigit($currentChar)) {
529 529
 	                        $currentWindowSize += 1;
530
-	                    } else {
530
+	                    }else {
531 531
 	                        $currentWindowSize += 2;
532 532
 	                    }
533 533
 	                    $endIndex++;
534 534
 	                }
535
-	                $currentWindow = $this->utf8_substr($input,$startIndex,$endIndex);
535
+	                $currentWindow = $this->utf8_substr($input, $startIndex, $endIndex);
536 536
 				}
537
-				array_push($windows,$currentWindow);
537
+				array_push($windows, $currentWindow);
538 538
 			}
539 539
 			return $windows;
540 540
 		}
541 541
 
542
-		function encryptPhoneIndex($data,$separator,$secretContext) {
542
+		function encryptPhoneIndex($data, $separator, $secretContext) {
543 543
 			$dataLength = strlen($data);
544
-			if($dataLength < 11) {
544
+			if ($dataLength < 11) {
545 545
 				return $data;
546 546
 			}
547
-			$last4Number = substr($data,$dataLength -4 ,$dataLength);
548
-			return $separator.$this->hmacMD5EncryptToBase64($last4Number,$secretContext->secret).$separator
549
-				   .Security::encrypt($data,$secretContext->secret).$separator.$secretContext->secretVersion
547
+			$last4Number = substr($data, $dataLength-4, $dataLength);
548
+			return $separator.$this->hmacMD5EncryptToBase64($last4Number, $secretContext->secret).$separator
549
+				   .Security::encrypt($data, $secretContext->secret).$separator.$secretContext->secretVersion
550 550
 				   .$separator.$separator;
551 551
 		}
552 552
 
553
-		function encryptNormalIndex($data,$compressLen,$slideSize,$separator,$secretContext) {
553
+		function encryptNormalIndex($data, $compressLen, $slideSize, $separator, $secretContext) {
554 554
 			$slideList = $this->getSlideWindows($data, $slideSize);
555 555
 			$builder = "";
556 556
 			foreach ($slideList as $slide) {
557
-				$builder .= $this->hmacMD5EncryptToBase64($slide,$secretContext->secret,$compressLen);
557
+				$builder .= $this->hmacMD5EncryptToBase64($slide, $secretContext->secret, $compressLen);
558 558
 			}
559
-			return $separator.Security::encrypt($data,$secretContext->secret).$separator.$builder.$separator
559
+			return $separator.Security::encrypt($data, $secretContext->secret).$separator.$builder.$separator
560 560
 				   .$secretContext->secretVersion.$separator.$separator;
561 561
 		}
562 562
 
563
-		function getArrayValue($array,$key,$default) {
564
-			if(array_key_exists($key, $array)){
563
+		function getArrayValue($array, $key, $default) {
564
+			if (array_key_exists($key, $array)) {
565 565
 				return $array[$key];
566 566
 			}
567 567
 			return $default;
@@ -569,18 +569,18 @@  discard block
 block discarded – undo
569 569
 
570 570
 		function getBytes($string) {  
571 571
 	        $bytes = array();  
572
-	        for($i = 0; $i < strlen($string); $i++){  
572
+	        for ($i = 0; $i < strlen($string); $i++) {  
573 573
 	             $bytes[] = ord($string[$i]);  
574 574
 	        }  
575 575
 	        return $bytes;  
576 576
 	    }  
577 577
 
578 578
 		function toStr($bytes) {
579
-			if(!is_array($bytes)){
579
+			if (!is_array($bytes)) {
580 580
 				return $bytes;
581 581
 			}
582 582
 	        $str = '';	        
583
-	        foreach($bytes as $ch) {
583
+	        foreach ($bytes as $ch) {
584 584
 	            $str .= chr($ch);
585 585
 	        }
586 586
 	        return $str;
Please login to merge, or discard this patch.