-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from hedeqiang/analysis-z9M0E9
Apply fixes from StyleCI
- Loading branch information
Showing
6 changed files
with
82 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,16 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the hedeqiang/ten-im. | ||
* | ||
* (c) hedeqiang<[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Hedeqiang\TenIM; | ||
|
||
use ArrayAccess; | ||
use InvalidArgumentException; | ||
|
||
|
@@ -47,6 +57,7 @@ public function get($key, $default = null) | |
} | ||
$config = $config[$segment]; | ||
} | ||
|
||
return $config; | ||
} | ||
|
||
|
@@ -73,6 +84,7 @@ public function set($key, $value) | |
$config = &$config[$key]; | ||
} | ||
$config[array_shift($keys)] = $value; | ||
|
||
return $config; | ||
} | ||
|
||
|
@@ -161,4 +173,4 @@ public function offsetUnset($offset) | |
{ | ||
$this->set($offset, null); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the hedeqiang/ten-im. | ||
* | ||
* (c) hedeqiang<[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Hedeqiang\TenIM\Exceptions; | ||
|
||
class Exception extends \Exception | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the hedeqiang/ten-im. | ||
* | ||
* (c) hedeqiang<[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Hedeqiang\TenIM\Exceptions; | ||
|
||
class HttpException extends Exception | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the hedeqiang/ten-im. | ||
* | ||
* (c) hedeqiang<[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Hedeqiang\TenIM\Exceptions; | ||
|
||
class InvalidArgumentException extends Exception | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,14 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the hedeqiang/ten-im. | ||
* | ||
* (c) hedeqiang<[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Hedeqiang\TenIM; | ||
|
||
use Hedeqiang\TenIM\Exceptions\Exception; | ||
|
@@ -26,12 +36,14 @@ public function __construct(array $config) | |
/** | ||
* @param string $servername | ||
* @param string $command | ||
* @param array $params | ||
* @param array $params | ||
* | ||
* @return array | ||
* | ||
* @throws Exception | ||
* @throws HttpException | ||
*/ | ||
public function send($servername,$command,array $params = []) | ||
public function send($servername, $command, array $params = []) | ||
{ | ||
try { | ||
$result = $this->postJson($this->buildEndpoint($servername, $command), $params); | ||
|
@@ -42,15 +54,18 @@ public function send($servername,$command,array $params = []) | |
if (0 === $result['ErrorCode'] && 'OK' === $result['ActionStatus']) { | ||
return $result; | ||
} | ||
throw new Exception('Tim REST API error: '. json_encode($result)); | ||
|
||
throw new Exception('Tim REST API error: '.json_encode($result)); | ||
} | ||
|
||
/** | ||
* Build endpoint url. | ||
* | ||
* @param string $servername | ||
* @param string $command | ||
* | ||
* @return string | ||
* | ||
* @throws \Exception | ||
*/ | ||
protected function buildEndpoint(string $servername, string $command): string | ||
|
@@ -62,21 +77,24 @@ protected function buildEndpoint(string $servername, string $command): string | |
'random' => mt_rand(0, 4294967295), | ||
'contenttype' => self::ENDPOINT_FORMAT, | ||
]); | ||
return \sprintf(self::ENDPOINT_TEMPLATE,self::ENDPOINT_VERSION, $servername, $command, $query); | ||
|
||
return \sprintf(self::ENDPOINT_TEMPLATE, self::ENDPOINT_VERSION, $servername, $command, $query); | ||
} | ||
|
||
/** | ||
* Generate Sign. | ||
* | ||
* @param string $identifier | ||
* @param int $expires | ||
* @param int $expires | ||
* | ||
* @return string | ||
* | ||
* @throws \Exception | ||
*/ | ||
protected function generateSign(string $identifier, int $expires = 15552000): string | ||
{ | ||
$api = new TLSSigAPIv2($this->config->get('sdk_app_id'), $this->config->get('secret_key')); | ||
return $api->genSig($identifier,$expires); | ||
} | ||
|
||
} | ||
return $api->genSig($identifier, $expires); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,16 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the hedeqiang/ten-im. | ||
* | ||
* (c) hedeqiang<[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Hedeqiang\TenIM\Traits; | ||
|
||
use GuzzleHttp\Client; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
|
@@ -85,6 +95,7 @@ protected function getBaseOptions() | |
'base_uri' => method_exists($this, 'getBaseUri') ? $this->getBaseUri() : '', | ||
'timeout' => method_exists($this, 'getTimeout') ? $this->getTimeout() : 10.0, | ||
]; | ||
|
||
return $options; | ||
} | ||
|
||
|
@@ -118,7 +129,7 @@ protected function unwrapResponse(ResponseInterface $response) | |
} elseif (false !== stripos($contentType, 'xml')) { | ||
return json_decode(json_encode(simplexml_load_string($contents)), true); | ||
} | ||
|
||
return $contents; | ||
} | ||
|
||
} | ||
} |