lin 6 years ago
parent
commit
392e9ba0c5
2 changed files with 21 additions and 16 deletions
  1. 4 4
      common/config/amqp-local.php
  2. 17 12
      components/Secret.php

+ 4 - 4
common/config/amqp-local.php

@@ -2,10 +2,10 @@
 
 return [
     'class' => 'components\service\Amqp',
-//    'host'	=> '192.168.3.10',
-    'host'	=> '127.0.0.1',
-//    'port'	=> '5672',
-    'port'	=> '5673',
+    //  'host'	=> '192.168.3.10',
+    //  'port'	=> '5672',
+     'host'	=> '127.0.0.1',
+     'port'	=> '5673',
     'user'	=> 'guest',
     'pass'	=> 'Guest',
 ];

+ 17 - 12
components/Secret.php

@@ -36,18 +36,21 @@ class Secret extends Component
 		$this->_clientSignature = $clientSignature;
 
 		$cone = $this->findOne($client_id);
-		if (!$cone)
-			static::throwError("client id avail.");
+		if (!$cone){
+            static::throwError("client id avail.");
+        }
 
 		$sKey = isset($cone->client_key) ? $cone->client_key : '';
 
 		$headers = Yii::$app->request->getHeaders();
-		if (!$headers)
-			static::throwError("headers format avail.");
+		if (!$headers){
+            static::throwError("headers format avail.");
+        }
 
 		$strVerb =  strtoupper($headers->get('verb'));
-		if (!$strVerb || !in_array(($strVerb), ['POST', 'GET']))
-			static::throwError("headers verb avail.");
+		if (!$strVerb || !in_array(($strVerb), ['POST', 'GET'])){
+            static::throwError("headers verb avail.");
+        }
 
 		$strMd5 = $headers->get('content-md5');
 		if (!$this->checkContentMd5($strVerb, $strMd5, Yii::$app->request->getBodyParams())){
@@ -66,20 +69,22 @@ class Secret extends Component
         }
 
 		$strSM = $headers->get('signature-method');
-		if (strtoupper($strSM) != strtoupper($this->_signatureMethod))
-			static::throwError("headers signature method avail.");
+		if (strtoupper($strSM) != strtoupper($this->_signatureMethod)){
+            static::throwError("headers signature method avail.");
+        }
 
 		$strSV = $headers->get('signature-version');
-		if ($strSV !== $this->_signatureVersion)
-			static::throwError("headers signature version avail.");
+		if ($strSV !== $this->_signatureVersion){
+            static::throwError("headers signature version avail.");
+        }
 
 		$str = "{$strVerb}\n\n{$strMd5}\n{$strContentType}\n{$strDate}\n{$strSM}\n{$strSV}\n\n{$sKey}\n";
 		$base_sha1 = base64_encode(hash_hmac("sha1", $str, $sKey . '&', true));
 
 		$this->_serverSignature = md5($base_sha1);
-		if ($this->_serverSignature != '' && $this->_serverSignature !== $this->_clientSignature)
+		if ($this->_serverSignature != '' && $this->_serverSignature !== $this->_clientSignature){
 //			static::throwError("Signature verification failed.");
-
+        }
 		return true;
 	}