From ad7a43e032d36010dcd5ed3750fcb8fac6a628c8 Mon Sep 17 00:00:00 2001 From: overtrue Date: Thu, 18 Apr 2024 16:17:41 +0800 Subject: [PATCH] fix: tests --- .php-cs-fixer.dist.php | 39 +-------- composer.json | 35 ++------ src/Contracts/GatewayInterface.php | 4 - src/Contracts/MessageInterface.php | 16 ++-- src/Contracts/StrategyInterface.php | 2 - src/EasySms.php | 55 +++++------- src/Exceptions/GatewayErrorException.php | 1 - .../NoGatewayAvailableException.php | 11 +-- src/Gateways/AliyunGateway.php | 20 ++--- src/Gateways/AliyunIntlGateway.php | 30 +++---- src/Gateways/AliyunrestGateway.php | 16 ++-- src/Gateways/BaiduGateway.php | 35 +++----- src/Gateways/ChuanglanGateway.php | 21 ++--- src/Gateways/Chuanglanv1Gateway.php | 25 ++---- src/Gateways/ErrorlogGateway.php | 4 - src/Gateways/Gateway.php | 15 +--- src/Gateways/HuaweiGateway.php | 16 ++-- src/Gateways/HuaxinGateway.php | 8 +- src/Gateways/HuyiGateway.php | 12 +-- src/Gateways/JuheGateway.php | 12 +-- src/Gateways/KingttoGateway.php | 8 +- src/Gateways/LuosimaoGateway.php | 12 +-- src/Gateways/MaapGateway.php | 14 ++-- src/Gateways/ModuyunGateway.php | 10 +-- src/Gateways/NowcnGateway.php | 7 +- src/Gateways/QcloudGateway.php | 50 +++++------ src/Gateways/QiniuGateway.php | 23 ++--- src/Gateways/RongcloudGateway.php | 21 ++--- src/Gateways/RongheyunGateway.php | 10 +-- src/Gateways/SendcloudGateway.php | 10 +-- src/Gateways/SmsbaoGateway.php | 16 ++-- src/Gateways/SubmailGateway.php | 14 ++-- src/Gateways/TianyiwuxianGateway.php | 18 ++-- src/Gateways/TiniyoGateway.php | 10 +-- src/Gateways/TinreeGateway.php | 15 ++-- src/Gateways/TwilioGateway.php | 8 +- src/Gateways/UcloudGateway.php | 14 +--- src/Gateways/Ue35Gateway.php | 12 +-- src/Gateways/VolcengineGateway.php | 49 ++++++----- src/Gateways/YidongmasblackGateway.php | 27 +++--- src/Gateways/YunpianGateway.php | 20 ++--- src/Gateways/YuntongxunGateway.php | 29 +++---- src/Gateways/YunxinGateway.php | 36 ++------ src/Gateways/YunzhixunGateway.php | 22 +---- src/Gateways/ZzyunGateway.php | 12 +-- src/Message.php | 23 +---- src/Messenger.php | 20 ++--- src/PhoneNumber.php | 4 +- src/Strategies/OrderStrategy.php | 2 - src/Strategies/RandomStrategy.php | 2 - src/Support/Config.php | 7 +- src/Traits/HasHttpRequest.php | 7 +- tests/Gateways/AliyunIntlGatewayTest.php | 8 +- tests/Gateways/AliyunrestGatewayTest.php | 8 +- tests/Gateways/JuheGatewayTest.php | 12 +-- tests/Gateways/MaapGatewayTest.php | 4 +- tests/Gateways/ModuyunGatewayTest.php | 6 +- tests/Gateways/NowcnGatewaysTest.php | 6 +- tests/Gateways/QcloudGatewayTest.php | 84 +++++++++---------- tests/Gateways/RongheyunGatewayTest.php | 8 +- tests/Gateways/SendcloudGatewayTest.php | 12 +-- tests/Gateways/SmsbaoGatewayTest.php | 15 ++-- tests/Gateways/SubmailGatewayTest.php | 2 +- tests/Gateways/TinreeGatewayTest.php | 12 +-- tests/Gateways/UcloudGatewayTest.php | 24 +++--- tests/Gateways/Ue35GatewayTest.php | 2 +- tests/Gateways/VolcengineGatewayTest.php | 11 ++- tests/Gateways/YidongmasblackGatewayTest.php | 14 ++-- tests/Gateways/YunpianGatewayTest.php | 12 +-- tests/Gateways/YuntongxunGatewayTest.php | 16 ++-- tests/Gateways/ZzyunGatewayTest.php | 6 +- tests/TestCase.php | 6 +- 72 files changed, 428 insertions(+), 749 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index e755e85..27db30d 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -2,44 +2,7 @@ return (new PhpCsFixer\Config()) ->setRules([ - '@PSR12' => true, - 'binary_operator_spaces' => true, - 'blank_line_after_opening_tag' => true, - 'compact_nullable_typehint' => true, - 'declare_equal_normalize' => true, - 'lowercase_cast' => true, - 'lowercase_static_reference' => true, - 'new_with_braces' => true, - 'no_blank_lines_after_class_opening' => true, - 'no_leading_import_slash' => true, - 'no_whitespace_in_blank_line' => true, - 'no_unused_imports' => true, - 'ordered_class_elements' => [ - 'order' => [ - 'use_trait', - ], - ], - 'ordered_imports' => [ - 'imports_order' => [ - 'class', - 'function', - 'const', - ], - 'sort_algorithm' => 'none', - ], - 'return_type_declaration' => true, - 'short_scalar_cast' => true, - 'single_blank_line_before_namespace' => true, - 'single_trait_insert_per_statement' => true, - 'ternary_operator_spaces' => true, - 'unary_operator_spaces' => true, - 'visibility_required' => [ - 'elements' => [ -// 'const', - 'method', - 'property', - ], - ], + '@Symfony' => true, ]) ->setFinder( PhpCsFixer\Finder::create() diff --git a/composer.json b/composer.json index 716c516..a80b812 100644 --- a/composer.json +++ b/composer.json @@ -10,8 +10,8 @@ "require-dev": { "phpunit/phpunit": "^5.7 || ^7.5 || ^8.5.19 || ^9.5.8", "mockery/mockery": "~1.3.3 || ^1.4.2", - "brainmaestro/composer-git-hooks": "^2.8", - "jetbrains/phpstorm-attributes": "^1.0" + "jetbrains/phpstorm-attributes": "^1.0", + "friendsofphp/php-cs-fixer": "^3.54" }, "autoload": { "psr-4": { @@ -24,34 +24,13 @@ } }, "license": "MIT", - "authors": [{ - "name": "overtrue", - "email": "i@overtrue.me" - }], - "extra": { - "hooks": { - "pre-commit": [ - "composer check-style", - "composer psalm", - "composer test" - ], - "pre-push": [ - "composer check-style" - ] + "authors": [ + { + "name": "overtrue", + "email": "i@overtrue.me" } - }, + ], "scripts": { - "post-update-cmd": [ - "cghooks remove", - "cghooks add --ignore-lock", - "cghooks update" - ], - "post-merge": "composer install", - "post-install-cmd": [ - "cghooks remove", - "cghooks add --ignore-lock", - "cghooks update" - ], "phpstan": "phpstan analyse", "check-style": "php-cs-fixer fix --using-cache=no --diff --config=.php-cs-fixer.dist.php --dry-run --allow-risky=yes --ansi", "fix-style": "php-cs-fixer fix --using-cache=no --config=.php-cs-fixer.dist.php --allow-risky=yes --ansi", diff --git a/src/Contracts/GatewayInterface.php b/src/Contracts/GatewayInterface.php index 3424677..a3e00f6 100644 --- a/src/Contracts/GatewayInterface.php +++ b/src/Contracts/GatewayInterface.php @@ -28,10 +28,6 @@ public function getName(); /** * Send a short message. * - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config); diff --git a/src/Contracts/MessageInterface.php b/src/Contracts/MessageInterface.php index 7c17f10..23b34cb 100644 --- a/src/Contracts/MessageInterface.php +++ b/src/Contracts/MessageInterface.php @@ -16,9 +16,9 @@ */ interface MessageInterface { - const TEXT_MESSAGE = 'text'; + public const TEXT_MESSAGE = 'text'; - const VOICE_MESSAGE = 'voice'; + public const VOICE_MESSAGE = 'voice'; /** * Return the message type. @@ -30,29 +30,23 @@ public function getMessageType(); /** * Return message content. * - * @param \Overtrue\EasySms\Contracts\GatewayInterface|null $gateway - * * @return string */ - public function getContent(GatewayInterface $gateway = null); + public function getContent(?GatewayInterface $gateway = null); /** * Return the template id of message. * - * @param \Overtrue\EasySms\Contracts\GatewayInterface|null $gateway - * * @return string */ - public function getTemplate(GatewayInterface $gateway = null); + public function getTemplate(?GatewayInterface $gateway = null); /** * Return the template data of message. * - * @param \Overtrue\EasySms\Contracts\GatewayInterface|null $gateway - * * @return array */ - public function getData(GatewayInterface $gateway = null); + public function getData(?GatewayInterface $gateway = null); /** * Return message supported gateways. diff --git a/src/Contracts/StrategyInterface.php b/src/Contracts/StrategyInterface.php index 1cda2c7..24b1d37 100644 --- a/src/Contracts/StrategyInterface.php +++ b/src/Contracts/StrategyInterface.php @@ -19,8 +19,6 @@ interface StrategyInterface /** * Apply the strategy and return result. * - * @param array $gateways - * * @return array */ public function apply(array $gateways); diff --git a/src/EasySms.php b/src/EasySms.php index 9fc68e7..d773164 100644 --- a/src/EasySms.php +++ b/src/EasySms.php @@ -27,7 +27,7 @@ class EasySms { /** - * @var \Overtrue\EasySms\Support\Config + * @var Config */ protected $config; @@ -47,7 +47,7 @@ class EasySms protected $gateways = []; /** - * @var \Overtrue\EasySms\Messenger + * @var Messenger */ protected $messenger; @@ -58,8 +58,6 @@ class EasySms /** * Constructor. - * - * @param array $config */ public function __construct(array $config) { @@ -69,14 +67,13 @@ public function __construct(array $config) /** * Send a message. * - * @param string|array $to - * @param \Overtrue\EasySms\Contracts\MessageInterface|array $message - * @param array $gateways + * @param string|array $to + * @param MessageInterface|array $message * * @return array * - * @throws \Overtrue\EasySms\Exceptions\InvalidArgumentException - * @throws \Overtrue\EasySms\Exceptions\NoGatewayAvailableException + * @throws InvalidArgumentException + * @throws Exceptions\NoGatewayAvailableException */ public function send($to, $message, array $gateways = []) { @@ -96,9 +93,9 @@ public function send($to, $message, array $gateways = []) * * @param string|null $name * - * @return \Overtrue\EasySms\Contracts\GatewayInterface + * @return GatewayInterface * - * @throws \Overtrue\EasySms\Exceptions\InvalidArgumentException + * @throws InvalidArgumentException */ public function gateway($name) { @@ -114,9 +111,9 @@ public function gateway($name) * * @param string|null $strategy * - * @return \Overtrue\EasySms\Contracts\StrategyInterface + * @return StrategyInterface * - * @throws \Overtrue\EasySms\Exceptions\InvalidArgumentException + * @throws InvalidArgumentException */ public function strategy($strategy = null) { @@ -142,12 +139,11 @@ public function strategy($strategy = null) /** * Register a custom driver creator Closure. * - * @param string $name - * @param \Closure $callback + * @param string $name * * @return $this */ - public function extend($name, Closure $callback) + public function extend($name, \Closure $callback) { $this->customCreators[$name] = $callback; @@ -155,7 +151,7 @@ public function extend($name, Closure $callback) } /** - * @return \Overtrue\EasySms\Support\Config + * @return Config */ public function getConfig() { @@ -163,7 +159,7 @@ public function getConfig() } /** - * @return \Overtrue\EasySms\Messenger + * @return Messenger */ public function getMessenger() { @@ -175,11 +171,10 @@ public function getMessenger() * * @param string $name * - * @throws \InvalidArgumentException - * * @return GatewayInterface * - * @throws \Overtrue\EasySms\Exceptions\InvalidArgumentException + * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ protected function createGateway($name) { @@ -211,9 +206,9 @@ protected function createGateway($name) * @param string $gateway * @param array $config * - * @return \Overtrue\EasySms\Contracts\GatewayInterface + * @return GatewayInterface * - * @throws \Overtrue\EasySms\Exceptions\InvalidArgumentException + * @throws InvalidArgumentException */ protected function makeGateway($gateway, $config) { @@ -247,8 +242,6 @@ protected function formatGatewayClassName($name) * * @param string $gateway * @param array $config - * - * @return mixed */ protected function callCustomCreator($gateway, $config) { @@ -256,9 +249,9 @@ protected function callCustomCreator($gateway, $config) } /** - * @param string|\Overtrue\EasySms\Contracts\PhoneNumberInterface $number + * @param string|PhoneNumberInterface $number * - * @return \Overtrue\EasySms\Contracts\PhoneNumberInterface|string + * @return PhoneNumberInterface|string */ protected function formatPhoneNumber($number) { @@ -270,9 +263,9 @@ protected function formatPhoneNumber($number) } /** - * @param array|string|\Overtrue\EasySms\Contracts\MessageInterface $message + * @param array|string|MessageInterface $message * - * @return \Overtrue\EasySms\Contracts\MessageInterface + * @return MessageInterface */ protected function formatMessage($message) { @@ -291,11 +284,9 @@ protected function formatMessage($message) } /** - * @param array $gateways - * * @return array * - * @throws \Overtrue\EasySms\Exceptions\InvalidArgumentException + * @throws InvalidArgumentException */ protected function formatGateways(array $gateways) { diff --git a/src/Exceptions/GatewayErrorException.php b/src/Exceptions/GatewayErrorException.php index e183def..084aec5 100644 --- a/src/Exceptions/GatewayErrorException.php +++ b/src/Exceptions/GatewayErrorException.php @@ -26,7 +26,6 @@ class GatewayErrorException extends Exception * * @param string $message * @param int $code - * @param array $raw */ public function __construct($message, $code, array $raw = []) { diff --git a/src/Exceptions/NoGatewayAvailableException.php b/src/Exceptions/NoGatewayAvailableException.php index 7c804d9..edc1622 100644 --- a/src/Exceptions/NoGatewayAvailableException.php +++ b/src/Exceptions/NoGatewayAvailableException.php @@ -11,8 +11,6 @@ namespace Overtrue\EasySms\Exceptions; -use Throwable; - /** * Class NoGatewayAvailableException. * @@ -33,11 +31,9 @@ class NoGatewayAvailableException extends Exception /** * NoGatewayAvailableException constructor. * - * @param array $results - * @param int $code - * @param \Throwable|null $previous + * @param int $code */ - public function __construct(array $results = [], $code = 0, Throwable $previous = null) + public function __construct(array $results = [], $code = 0, ?\Throwable $previous = null) { $this->results = $results; $this->exceptions = \array_column($results, 'exception', 'gateway'); @@ -71,9 +67,6 @@ public function getExceptions() return $this->exceptions; } - /** - * @return mixed - */ public function getLastException() { return end($this->exceptions); diff --git a/src/Gateways/AliyunGateway.php b/src/Gateways/AliyunGateway.php index c061dd2..cece11c 100644 --- a/src/Gateways/AliyunGateway.php +++ b/src/Gateways/AliyunGateway.php @@ -28,28 +28,24 @@ class AliyunGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_URL = 'http://dysmsapi.aliyuncs.com'; + public const ENDPOINT_URL = 'http://dysmsapi.aliyuncs.com'; - const ENDPOINT_METHOD = 'SendSms'; + public const ENDPOINT_METHOD = 'SendSms'; - const ENDPOINT_VERSION = '2017-05-25'; + public const ENDPOINT_VERSION = '2017-05-25'; - const ENDPOINT_FORMAT = 'JSON'; + public const ENDPOINT_FORMAT = 'JSON'; - const ENDPOINT_REGION_ID = 'cn-hangzhou'; + public const ENDPOINT_REGION_ID = 'cn-hangzhou'; - const ENDPOINT_SIGNATURE_METHOD = 'HMAC-SHA1'; + public const ENDPOINT_SIGNATURE_METHOD = 'HMAC-SHA1'; - const ENDPOINT_SIGNATURE_VERSION = '1.0'; + public const ENDPOINT_SIGNATURE_VERSION = '1.0'; /** - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array * - * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException ; + * @throws GatewayErrorException ; */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { diff --git a/src/Gateways/AliyunIntlGateway.php b/src/Gateways/AliyunIntlGateway.php index dcd7880..fd90eae 100644 --- a/src/Gateways/AliyunIntlGateway.php +++ b/src/Gateways/AliyunIntlGateway.php @@ -9,9 +9,7 @@ use Overtrue\EasySms\Traits\HasHttpRequest; /** - * Class AliyunIntlGateway - * - * @package \Overtrue\EasySms\Gateways + * Class AliyunIntlGateway. * * @see https://www.alibabacloud.com/help/zh/doc-detail/162279.htm */ @@ -19,30 +17,24 @@ class AliyunIntlGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_URL = 'https://dysmsapi.ap-southeast-1.aliyuncs.com'; - - const ENDPOINT_ACTION = 'SendMessageWithTemplate'; + public const ENDPOINT_URL = 'https://dysmsapi.ap-southeast-1.aliyuncs.com'; - const ENDPOINT_VERSION = '2018-05-01'; + public const ENDPOINT_ACTION = 'SendMessageWithTemplate'; - const ENDPOINT_FORMAT = 'JSON'; + public const ENDPOINT_VERSION = '2018-05-01'; - const ENDPOINT_REGION_ID = 'ap-southeast-1'; + public const ENDPOINT_FORMAT = 'JSON'; - const ENDPOINT_SIGNATURE_METHOD = 'HMAC-SHA1'; + public const ENDPOINT_REGION_ID = 'ap-southeast-1'; - const ENDPOINT_SIGNATURE_VERSION = '1.0'; + public const ENDPOINT_SIGNATURE_METHOD = 'HMAC-SHA1'; + public const ENDPOINT_SIGNATURE_VERSION = '1.0'; /** - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array * - * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException - * + * @throws GatewayErrorException */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { @@ -80,9 +72,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config } /** - * Generate sign - * - * @param array $params + * Generate sign. * * @return string */ diff --git a/src/Gateways/AliyunrestGateway.php b/src/Gateways/AliyunrestGateway.php index d4359d2..b4dfb6d 100644 --- a/src/Gateways/AliyunrestGateway.php +++ b/src/Gateways/AliyunrestGateway.php @@ -24,23 +24,19 @@ class AliyunrestGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_URL = 'http://gw.api.taobao.com/router/rest'; + public const ENDPOINT_URL = 'http://gw.api.taobao.com/router/rest'; - const ENDPOINT_VERSION = '2.0'; + public const ENDPOINT_VERSION = '2.0'; - const ENDPOINT_FORMAT = 'json'; + public const ENDPOINT_FORMAT = 'json'; - const ENDPOINT_METHOD = 'alibaba.aliqin.fc.sms.num.send'; + public const ENDPOINT_METHOD = 'alibaba.aliqin.fc.sms.num.send'; - const ENDPOINT_SIGNATURE_METHOD = 'md5'; + public const ENDPOINT_SIGNATURE_METHOD = 'md5'; - const ENDPOINT_PARTNER_ID = 'EasySms'; + public const ENDPOINT_PARTNER_ID = 'EasySms'; /** - * @param PhoneNumberInterface $to - * @param MessageInterface $message - * @param Config $config - * * @return array|void */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) diff --git a/src/Gateways/BaiduGateway.php b/src/Gateways/BaiduGateway.php index 5c26b0a..af7378a 100644 --- a/src/Gateways/BaiduGateway.php +++ b/src/Gateways/BaiduGateway.php @@ -26,26 +26,22 @@ class BaiduGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_HOST = 'smsv3.bj.baidubce.com'; + public const ENDPOINT_HOST = 'smsv3.bj.baidubce.com'; - const ENDPOINT_URI = '/api/v3/sendSms'; + public const ENDPOINT_URI = '/api/v3/sendSms'; - const BCE_AUTH_VERSION = 'bce-auth-v1'; + public const BCE_AUTH_VERSION = 'bce-auth-v1'; - const DEFAULT_EXPIRATION_IN_SECONDS = 1800; //签名有效期默认1800秒 + public const DEFAULT_EXPIRATION_IN_SECONDS = 1800; // 签名有效期默认1800秒 - const SUCCESS_CODE = 1000; + public const SUCCESS_CODE = 1000; /** * Send message. * - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array * - * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException ; + * @throws GatewayErrorException ; */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { @@ -56,12 +52,12 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config 'contentVar' => $message->getData($this), ]; if (!empty($params['contentVar']['custom'])) { - //用户自定义参数,格式为字符串,状态回调时会回传该值 + // 用户自定义参数,格式为字符串,状态回调时会回传该值 $params['custom'] = $params['contentVar']['custom']; unset($params['contentVar']['custom']); } if (!empty($params['contentVar']['userExtId'])) { - //通道自定义扩展码,上行回调时会回传该值,其格式为纯数字串。默认为不开通,请求时无需设置该参数。如需开通请联系客服申请 + // 通道自定义扩展码,上行回调时会回传该值,其格式为纯数字串。默认为不开通,请求时无需设置该参数。如需开通请联系客服申请 $params['userExtId'] = $params['contentVar']['userExtId']; unset($params['contentVar']['userExtId']); } @@ -73,7 +69,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config 'content-type' => 'application/json', 'x-bce-date' => $datetime, ]; - //获得需要签名的数据 + // 获得需要签名的数据 $signHeaders = $this->getHeadersToSign($headers, ['host', 'x-bce-date']); $headers['Authorization'] = $this->generateSign($signHeaders, $datetime, $config); @@ -90,8 +86,6 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config /** * Build endpoint url. * - * @param \Overtrue\EasySms\Support\Config $config - * * @return string */ protected function buildEndpoint(Config $config) @@ -102,9 +96,7 @@ protected function buildEndpoint(Config $config) /** * Generate Authorization header. * - * @param array $signHeaders - * @param int $datetime - * @param \Overtrue\EasySms\Support\Config $config + * @param int $datetime * * @return string */ @@ -142,15 +134,13 @@ protected function generateSign(array $signHeaders, $datetime, Config $config) /** * 生成标准化 http 请求头串. * - * @param array $headers - * * @return string */ protected function getCanonicalHeaders(array $headers) { $headerStrings = []; foreach ($headers as $name => $value) { - //trim后再encode,之后使用':'号连接起来 + // trim后再encode,之后使用':'号连接起来 $headerStrings[] = rawurlencode(strtolower(trim($name))).':'.rawurlencode(trim($value)); } @@ -162,9 +152,6 @@ protected function getCanonicalHeaders(array $headers) /** * 根据 指定的 keys 过滤应该参与签名的 header. * - * @param array $headers - * @param array $keys - * * @return array */ protected function getHeadersToSign(array $headers, array $keys) diff --git a/src/Gateways/ChuanglanGateway.php b/src/Gateways/ChuanglanGateway.php index f22839a..0a7fafb 100644 --- a/src/Gateways/ChuanglanGateway.php +++ b/src/Gateways/ChuanglanGateway.php @@ -30,28 +30,24 @@ class ChuanglanGateway extends Gateway /** * URL模板 */ - const ENDPOINT_URL_TEMPLATE = 'https://%s.253.com/msg/send/json'; + public const ENDPOINT_URL_TEMPLATE = 'https://%s.253.com/msg/send/json'; /** * 国际短信 */ - const INT_URL = 'http://intapi.253.com/send/json'; + public const INT_URL = 'http://intapi.253.com/send/json'; /** * 验证码渠道code. */ - const CHANNEL_VALIDATE_CODE = 'smsbj1'; + public const CHANNEL_VALIDATE_CODE = 'smsbj1'; /** * 会员营销渠道code. */ - const CHANNEL_PROMOTION_CODE = 'smssh1'; + public const CHANNEL_PROMOTION_CODE = 'smssh1'; /** - * @param PhoneNumberInterface $to - * @param MessageInterface $message - * @param Config $config - * * @return array * * @throws GatewayErrorException @@ -84,8 +80,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config } /** - * @param Config $config - * @param int $IDDCode + * @param int $IDDCode * * @return string * @@ -103,10 +98,7 @@ protected function buildEndpoint(Config $config, $IDDCode = 86) } /** - * @param Config $config - * @param int $IDDCode - * - * @return mixed + * @param int $IDDCode * * @throws InvalidArgumentException */ @@ -126,7 +118,6 @@ protected function getChannel(Config $config, $IDDCode) /** * @param string $content - * @param Config $config * @param int $IDDCode * * @return string|string diff --git a/src/Gateways/Chuanglanv1Gateway.php b/src/Gateways/Chuanglanv1Gateway.php index a81fb6a..a89bcf9 100644 --- a/src/Gateways/Chuanglanv1Gateway.php +++ b/src/Gateways/Chuanglanv1Gateway.php @@ -30,28 +30,24 @@ class Chuanglanv1Gateway extends Gateway /** * 国际短信 */ - const INT_URL = 'http://intapi.253.com/send/json'; + public const INT_URL = 'http://intapi.253.com/send/json'; /** * URL模板 */ - const ENDPOINT_URL_TEMPLATE = 'https://smssh1.253.com/msg/%s/json'; + public const ENDPOINT_URL_TEMPLATE = 'https://smssh1.253.com/msg/%s/json'; /** * 支持单发、群发短信 */ - const CHANNEL_NORMAL_CODE = 'v1/send'; + public const CHANNEL_NORMAL_CODE = 'v1/send'; /** - * 单号码对应单内容批量下发 + * 单号码对应单内容批量下发. */ - const CHANNEL_VARIABLE_CODE = 'variable'; + public const CHANNEL_VARIABLE_CODE = 'variable'; /** - * @param PhoneNumberInterface $to - * @param MessageInterface $message - * @param Config $config - * * @return array * * @throws GatewayErrorException @@ -64,11 +60,11 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $params = [ 'account' => $config->get('account'), 'password' => $config->get('password'), - 'report' => $config->get('needstatus') ?? false + 'report' => $config->get('needstatus') ?? false, ]; if (86 != $IDDCode) { - $params['mobile'] = $to->getIDDCode() . $to->getNumber(); + $params['mobile'] = $to->getIDDCode().$to->getNumber(); $params['account'] = $config->get('intel_account') ?: $config->get('account'); $params['password'] = $config->get('intel_password') ?: $config->get('password'); } @@ -91,7 +87,6 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config } /** - * @param Config $config * @param int $IDDCode * * @return string @@ -110,11 +105,8 @@ protected function buildEndpoint(Config $config, $IDDCode = 86) } /** - * @param Config $config * @param int $IDDCode * - * @return mixed - * * @throws InvalidArgumentException */ protected function getChannel(Config $config, $IDDCode) @@ -133,8 +125,7 @@ protected function getChannel(Config $config, $IDDCode) /** * @param string $content - * @param Config $config - * @param int $IDDCode + * @param int $IDDCode * * @return string|string * diff --git a/src/Gateways/ErrorlogGateway.php b/src/Gateways/ErrorlogGateway.php index d27b40d..bf005fb 100644 --- a/src/Gateways/ErrorlogGateway.php +++ b/src/Gateways/ErrorlogGateway.php @@ -21,10 +21,6 @@ class ErrorlogGateway extends Gateway { /** - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) diff --git a/src/Gateways/Gateway.php b/src/Gateways/Gateway.php index c6791fc..3c7ae90 100644 --- a/src/Gateways/Gateway.php +++ b/src/Gateways/Gateway.php @@ -19,10 +19,10 @@ */ abstract class Gateway implements GatewayInterface { - const DEFAULT_TIMEOUT = 5.0; + public const DEFAULT_TIMEOUT = 5.0; /** - * @var \Overtrue\EasySms\Support\Config + * @var Config */ protected $config; @@ -38,8 +38,6 @@ abstract class Gateway implements GatewayInterface /** * Gateway constructor. - * - * @param array $config */ public function __construct(array $config) { @@ -71,7 +69,7 @@ public function setTimeout($timeout) } /** - * @return \Overtrue\EasySms\Support\Config + * @return Config */ public function getConfig() { @@ -79,8 +77,6 @@ public function getConfig() } /** - * @param \Overtrue\EasySms\Support\Config $config - * * @return $this */ public function setConfig(Config $config) @@ -91,8 +87,6 @@ public function setConfig(Config $config) } /** - * @param $options - * * @return $this */ public function setGuzzleOptions($options) @@ -110,9 +104,6 @@ public function getGuzzleOptions() return $this->options ?: $this->config->get('options', []); } - /** - * {@inheritdoc} - */ public function getName() { return \strtolower(str_replace([__NAMESPACE__.'\\', 'Gateway'], '', \get_class($this))); diff --git a/src/Gateways/HuaweiGateway.php b/src/Gateways/HuaweiGateway.php index 16060ca..8132065 100644 --- a/src/Gateways/HuaweiGateway.php +++ b/src/Gateways/HuaweiGateway.php @@ -23,19 +23,15 @@ class HuaweiGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_HOST = 'https://api.rtc.huaweicloud.com:10443'; + public const ENDPOINT_HOST = 'https://api.rtc.huaweicloud.com:10443'; - const ENDPOINT_URI = '/sms/batchSendSms/v1'; + public const ENDPOINT_URI = '/sms/batchSendSms/v1'; - const SUCCESS_CODE = '000000'; + public const SUCCESS_CODE = '000000'; /** * 发送信息. * - * @param PhoneNumberInterface $to - * @param MessageInterface $message - * @param Config $config - * * @return array * * @throws GatewayErrorException @@ -78,7 +74,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $result = $this->request('post', $endpoint, [ 'headers' => $headers, 'form_params' => $params, - //为防止因HTTPS证书认证失败造成API调用失败,需要先忽略证书信任问题 + // 为防止因HTTPS证书认证失败造成API调用失败,需要先忽略证书信任问题 'verify' => false, ]); } catch (RequestException $e) { @@ -95,8 +91,6 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config /** * 构造 Endpoint. * - * @param Config $config - * * @return string */ protected function getEndpoint(Config $config) @@ -135,7 +129,7 @@ protected function buildWsseHeader($appKey, $appSecret) { $now = date('Y-m-d\TH:i:s\Z'); $nonce = uniqid(); - $passwordDigest = base64_encode(hash('sha256', ($nonce.$now.$appSecret))); + $passwordDigest = base64_encode(hash('sha256', $nonce.$now.$appSecret)); return sprintf( 'UsernameToken Username="%s",PasswordDigest="%s",Nonce="%s",Created="%s"', diff --git a/src/Gateways/HuaxinGateway.php b/src/Gateways/HuaxinGateway.php index 3e5c9fe..7e1ade1 100644 --- a/src/Gateways/HuaxinGateway.php +++ b/src/Gateways/HuaxinGateway.php @@ -26,16 +26,12 @@ class HuaxinGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_TEMPLATE = 'http://%s/smsJson.aspx'; + public const ENDPOINT_TEMPLATE = 'http://%s/smsJson.aspx'; /** - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array * - * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException ; + * @throws GatewayErrorException ; */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { diff --git a/src/Gateways/HuyiGateway.php b/src/Gateways/HuyiGateway.php index bcdb91b..f48e210 100644 --- a/src/Gateways/HuyiGateway.php +++ b/src/Gateways/HuyiGateway.php @@ -26,20 +26,16 @@ class HuyiGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_URL = 'http://106.ihuyi.com/webservice/sms.php?method=Submit'; + public const ENDPOINT_URL = 'http://106.ihuyi.com/webservice/sms.php?method=Submit'; - const ENDPOINT_FORMAT = 'json'; + public const ENDPOINT_FORMAT = 'json'; - const SUCCESS_CODE = 2; + public const SUCCESS_CODE = 2; /** - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array * - * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException ; + * @throws GatewayErrorException ; */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { diff --git a/src/Gateways/JuheGateway.php b/src/Gateways/JuheGateway.php index e94d707..fca717f 100644 --- a/src/Gateways/JuheGateway.php +++ b/src/Gateways/JuheGateway.php @@ -26,18 +26,14 @@ class JuheGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_URL = 'http://v.juhe.cn/sms/send'; + public const ENDPOINT_URL = 'http://v.juhe.cn/sms/send'; - const ENDPOINT_FORMAT = 'json'; + public const ENDPOINT_FORMAT = 'json'; /** - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array * - * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException ; + * @throws GatewayErrorException ; */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { @@ -59,8 +55,6 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config } /** - * @param array $vars - * * @return string */ protected function formatTemplateVars(array $vars) diff --git a/src/Gateways/KingttoGateway.php b/src/Gateways/KingttoGateway.php index c74795a..e0fa429 100644 --- a/src/Gateways/KingttoGateway.php +++ b/src/Gateways/KingttoGateway.php @@ -26,15 +26,11 @@ class KingttoGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_URL = 'http://101.201.41.194:9999/sms.aspx'; + public const ENDPOINT_URL = 'http://101.201.41.194:9999/sms.aspx'; - const ENDPOINT_METHOD = 'send'; + public const ENDPOINT_METHOD = 'send'; /** - * @param PhoneNumberInterface $to - * @param MessageInterface $message - * @param Config $config - * * @return \Psr\Http\Message\ResponseInterface|array|string * * @throws GatewayErrorException diff --git a/src/Gateways/LuosimaoGateway.php b/src/Gateways/LuosimaoGateway.php index 07ba2b7..9ce6693 100644 --- a/src/Gateways/LuosimaoGateway.php +++ b/src/Gateways/LuosimaoGateway.php @@ -26,20 +26,16 @@ class LuosimaoGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_TEMPLATE = 'https://%s.luosimao.com/%s/%s.%s'; + public const ENDPOINT_TEMPLATE = 'https://%s.luosimao.com/%s/%s.%s'; - const ENDPOINT_VERSION = 'v1'; + public const ENDPOINT_VERSION = 'v1'; - const ENDPOINT_FORMAT = 'json'; + public const ENDPOINT_FORMAT = 'json'; /** - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array * - * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException ; + * @throws GatewayErrorException ; */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { diff --git a/src/Gateways/MaapGateway.php b/src/Gateways/MaapGateway.php index 1ca44be..a00a921 100644 --- a/src/Gateways/MaapGateway.php +++ b/src/Gateways/MaapGateway.php @@ -26,17 +26,14 @@ class MaapGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_URL = 'http://rcsapi.wo.cn:8000/umcinterface/sendtempletmsg'; + public const ENDPOINT_URL = 'http://rcsapi.wo.cn:8000/umcinterface/sendtempletmsg'; /** * Send message. - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config * * @return array * - * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException + * @throws GatewayErrorException */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { @@ -61,12 +58,13 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config /** * Generate Sign. * - * @param array $params - * @param string $key 签名Key + * @param array $params + * @param string $key 签名Key + * * @return string */ protected function generateSign($params, $key) { - return md5($params['cpcode'] . $params['msg'] . $params['mobiles'] . $params['excode'] . $params['templetid'] . $key); + return md5($params['cpcode'].$params['msg'].$params['mobiles'].$params['excode'].$params['templetid'].$key); } } diff --git a/src/Gateways/ModuyunGateway.php b/src/Gateways/ModuyunGateway.php index 7a6d152..296fbf2 100644 --- a/src/Gateways/ModuyunGateway.php +++ b/src/Gateways/ModuyunGateway.php @@ -26,16 +26,12 @@ class ModuyunGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_URL = 'https://live.moduyun.com/sms/v2/sendsinglesms'; + public const ENDPOINT_URL = 'https://live.moduyun.com/sms/v2/sendsinglesms'; /** - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array * - * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException ; + * @throws GatewayErrorException ; */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { @@ -75,7 +71,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config */ protected function getEndpointUrl($params) { - return self::ENDPOINT_URL . '?' . http_build_query($params); + return self::ENDPOINT_URL.'?'.http_build_query($params); } /** diff --git a/src/Gateways/NowcnGateway.php b/src/Gateways/NowcnGateway.php index 0638ace..06041ba 100644 --- a/src/Gateways/NowcnGateway.php +++ b/src/Gateways/NowcnGateway.php @@ -12,14 +12,14 @@ class NowcnGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_URL = 'http://ad1200.now.net.cn:2003/sms/sendSMS'; + public const ENDPOINT_URL = 'http://ad1200.now.net.cn:2003/sms/sendSMS'; - const SUCCESS_CODE = 0; + public const SUCCESS_CODE = 0; public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { if (!$config->get('key')) { - throw new GatewayErrorException("key not found", -2, []); + throw new GatewayErrorException('key not found', -2, []); } $params = [ 'mobile' => $to->getNumber(), @@ -33,6 +33,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config if (self::SUCCESS_CODE != $result['code']) { throw new GatewayErrorException($result['msg'], $result['code'], $result); } + return $result; } } diff --git a/src/Gateways/QcloudGateway.php b/src/Gateways/QcloudGateway.php index 2aaad18..1edfa26 100644 --- a/src/Gateways/QcloudGateway.php +++ b/src/Gateways/QcloudGateway.php @@ -26,28 +26,24 @@ class QcloudGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_URL = 'https://sms.tencentcloudapi.com'; + public const ENDPOINT_URL = 'https://sms.tencentcloudapi.com'; - const ENDPOINT_HOST = 'sms.tencentcloudapi.com'; + public const ENDPOINT_HOST = 'sms.tencentcloudapi.com'; - const ENDPOINT_SERVICE = 'sms'; + public const ENDPOINT_SERVICE = 'sms'; - const ENDPOINT_METHOD = 'SendSms'; + public const ENDPOINT_METHOD = 'SendSms'; - const ENDPOINT_VERSION = '2021-01-11'; + public const ENDPOINT_VERSION = '2021-01-11'; - const ENDPOINT_REGION = 'ap-guangzhou'; + public const ENDPOINT_REGION = 'ap-guangzhou'; - const ENDPOINT_FORMAT = 'json'; + public const ENDPOINT_FORMAT = 'json'; /** - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array * - * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException ; + * @throws GatewayErrorException ; */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { @@ -60,7 +56,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $phone = !\is_null($to->getIDDCode()) ? strval($to->getUniversalNumber()) : $to->getNumber(); $params = [ 'PhoneNumberSet' => [ - $phone + $phone, ], 'SmsSdkAppId' => $this->config->get('sdk_app_id'), 'SignName' => $signName, @@ -89,7 +85,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config if (!empty($result['Response']['SendStatusSet'])) { foreach ($result['Response']['SendStatusSet'] as $group) { - if ($group['Code'] != 'Ok') { + if ('Ok' != $group['Code']) { throw new GatewayErrorException($group['Message'], 400, $result); } } @@ -101,37 +97,37 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config /** * Generate Sign. * - * @param array $params + * @param array $params * * @return string */ protected function generateSign($params, $timestamp) { - $date = gmdate("Y-m-d", $timestamp); + $date = gmdate('Y-m-d', $timestamp); $secretKey = $this->config->get('secret_key'); $secretId = $this->config->get('secret_id'); $canonicalRequest = 'POST'."\n". '/'."\n". - '' ."\n". + ''."\n". 'content-type:application/json; charset=utf-8'."\n". - 'host:' . self::ENDPOINT_HOST."\n"."\n". + 'host:'.self::ENDPOINT_HOST."\n\n". 'content-type;host'."\n". - hash("SHA256", json_encode($params)); + hash('SHA256', json_encode($params)); $stringToSign = 'TC3-HMAC-SHA256'."\n". $timestamp."\n". - $date . '/'. self::ENDPOINT_SERVICE .'/tc3_request'."\n". - hash("SHA256", $canonicalRequest); + $date.'/'.self::ENDPOINT_SERVICE.'/tc3_request'."\n". + hash('SHA256', $canonicalRequest); - $secretDate = hash_hmac("SHA256", $date, "TC3".$secretKey, true); - $secretService = hash_hmac("SHA256", self::ENDPOINT_SERVICE, $secretDate, true); - $secretSigning = hash_hmac("SHA256", "tc3_request", $secretService, true); - $signature = hash_hmac("SHA256", $stringToSign, $secretSigning); + $secretDate = hash_hmac('SHA256', $date, 'TC3'.$secretKey, true); + $secretService = hash_hmac('SHA256', self::ENDPOINT_SERVICE, $secretDate, true); + $secretSigning = hash_hmac('SHA256', 'tc3_request', $secretService, true); + $signature = hash_hmac('SHA256', $stringToSign, $secretSigning); return 'TC3-HMAC-SHA256' - ." Credential=". $secretId ."/". $date . '/'. self::ENDPOINT_SERVICE .'/tc3_request' - .", SignedHeaders=content-type;host, Signature=".$signature; + .' Credential='.$secretId.'/'.$date.'/'.self::ENDPOINT_SERVICE.'/tc3_request' + .', SignedHeaders=content-type;host, Signature='.$signature; } } diff --git a/src/Gateways/QiniuGateway.php b/src/Gateways/QiniuGateway.php index 9a9ad31..a59ac7a 100644 --- a/src/Gateways/QiniuGateway.php +++ b/src/Gateways/QiniuGateway.php @@ -26,18 +26,14 @@ class QiniuGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_TEMPLATE = 'https://%s.qiniuapi.com/%s/%s'; + public const ENDPOINT_TEMPLATE = 'https://%s.qiniuapi.com/%s/%s'; - const ENDPOINT_VERSION = 'v1'; + public const ENDPOINT_VERSION = 'v1'; /** - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array * - * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException ; + * @throws GatewayErrorException ; */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { @@ -89,7 +85,6 @@ protected function buildEndpoint($type, $function) * @param string $method * @param string $body * @param string $contentType - * @param Config $config * * @return string */ @@ -108,22 +103,22 @@ protected function generateSign($url, $method, $body, $contentType, Config $conf } else { $query = ''; } - //write request uri + // write request uri $toSignStr = $method.' '.$path; if (!empty($query)) { $toSignStr .= '?'.$query; } - //write host and port + // write host and port $toSignStr .= "\nHost: ".$host; if (!empty($port)) { $toSignStr .= ':'.$port; } - //write content type + // write content type if (!empty($contentType)) { $toSignStr .= "\nContent-Type: ".$contentType; } $toSignStr .= "\n\n"; - //write body + // write body if (!empty($body)) { $toSignStr .= $body; } @@ -140,8 +135,8 @@ protected function generateSign($url, $method, $body, $contentType, Config $conf */ protected function base64UrlSafeEncode($data) { - $find = array('+', '/'); - $replace = array('-', '_'); + $find = ['+', '/']; + $replace = ['-', '_']; return str_replace($find, $replace, base64_encode($data)); } diff --git a/src/Gateways/RongcloudGateway.php b/src/Gateways/RongcloudGateway.php index 8464a1c..f0c2648 100644 --- a/src/Gateways/RongcloudGateway.php +++ b/src/Gateways/RongcloudGateway.php @@ -29,24 +29,20 @@ class RongcloudGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_TEMPLATE = 'http://api.sms.ronghub.com/%s.%s'; + public const ENDPOINT_TEMPLATE = 'http://api.sms.ronghub.com/%s.%s'; - const ENDPOINT_ACTION = 'sendCode'; + public const ENDPOINT_ACTION = 'sendCode'; - const ENDPOINT_FORMAT = 'json'; + public const ENDPOINT_FORMAT = 'json'; - const ENDPOINT_REGION = '86'; // 中国区,目前只支持此国别 + public const ENDPOINT_REGION = '86'; // 中国区,目前只支持此国别 - const SUCCESS_CODE = 200; + public const SUCCESS_CODE = 200; /** - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array * - * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException ; + * @throws GatewayErrorException ; */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { @@ -86,7 +82,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config 'mobile' => $to->getNumber(), 'region' => self::ENDPOINT_REGION, 'templateId' => $message->getTemplate($this), - ]; + ]; $params = array_merge($params, $data); break; @@ -110,8 +106,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config /** * Generate Sign. * - * @param array $params - * @param \Overtrue\EasySms\Support\Config $config + * @param array $params * * @return string */ diff --git a/src/Gateways/RongheyunGateway.php b/src/Gateways/RongheyunGateway.php index aa63c65..c8a22f4 100644 --- a/src/Gateways/RongheyunGateway.php +++ b/src/Gateways/RongheyunGateway.php @@ -26,21 +26,17 @@ class RongheyunGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_URL = 'https://api.mix2.zthysms.com/v2/sendSmsTp'; + public const ENDPOINT_URL = 'https://api.mix2.zthysms.com/v2/sendSmsTp'; /** - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array * - * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException ; + * @throws GatewayErrorException ; */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { $tKey = time(); - $password = md5(md5($config->get('password')) . $tKey); + $password = md5(md5($config->get('password')).$tKey); $params = [ 'username' => $config->get('username', ''), 'password' => $password, diff --git a/src/Gateways/SendcloudGateway.php b/src/Gateways/SendcloudGateway.php index 5da3a4f..bce0e4c 100644 --- a/src/Gateways/SendcloudGateway.php +++ b/src/Gateways/SendcloudGateway.php @@ -26,18 +26,14 @@ class SendcloudGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_TEMPLATE = 'http://www.sendcloud.net/smsapi/%s'; + public const ENDPOINT_TEMPLATE = 'http://www.sendcloud.net/smsapi/%s'; /** * Send a short message. * - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array * - * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException + * @throws GatewayErrorException */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { @@ -65,8 +61,6 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config } /** - * @param array $vars - * * @return string */ protected function formatTemplateVars(array $vars) diff --git a/src/Gateways/SmsbaoGateway.php b/src/Gateways/SmsbaoGateway.php index b202d4c..ec22241 100644 --- a/src/Gateways/SmsbaoGateway.php +++ b/src/Gateways/SmsbaoGateway.php @@ -18,17 +18,19 @@ use Overtrue\EasySms\Traits\HasHttpRequest; /** - * Class SmsbaoGateway + * Class SmsbaoGateway. + * * @author iwindy <203962638@qq.com> + * * @see http://www.smsbao.com/openapi/ */ class SmsbaoGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_URL = 'http://api.smsbao.com/%s'; + public const ENDPOINT_URL = 'http://api.smsbao.com/%s'; - const SUCCESS_CODE = '0'; + public const SUCCESS_CODE = '0'; protected $errorStatuses = [ '0' => '短信发送成功', @@ -39,14 +41,14 @@ class SmsbaoGateway extends Gateway '41' => '余额不足', '42' => '帐户已过期', '43' => 'IP地址限制', - '50' => '内容含有敏感词' + '50' => '内容含有敏感词', ]; public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { $data = $message->getContent($this); - if (is_null($to->getIDDCode()) || $to->getIDDCode() == '86') { + if (is_null($to->getIDDCode()) || '86' == $to->getIDDCode()) { $number = $to->getNumber(); $action = 'sms'; } else { @@ -58,12 +60,12 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config 'u' => $config->get('user'), 'p' => md5($config->get('password')), 'm' => $number, - 'c' => $data + 'c' => $data, ]; $result = $this->get($this->buildEndpoint($action), $params); - if ($result !== self::SUCCESS_CODE) { + if (self::SUCCESS_CODE !== $result) { throw new GatewayErrorException($this->errorStatuses[$result], $result); } diff --git a/src/Gateways/SubmailGateway.php b/src/Gateways/SubmailGateway.php index d496175..94ca757 100644 --- a/src/Gateways/SubmailGateway.php +++ b/src/Gateways/SubmailGateway.php @@ -26,22 +26,18 @@ class SubmailGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_TEMPLATE = 'https://api.mysubmail.com/%s.%s'; + public const ENDPOINT_TEMPLATE = 'https://api.mysubmail.com/%s.%s'; - const ENDPOINT_FORMAT = 'json'; + public const ENDPOINT_FORMAT = 'json'; /** - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array * - * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException ; + * @throws GatewayErrorException ; */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { - $isContent = !!$message->getContent($this); + $isContent = (bool) $message->getContent($this); if ($isContent) { $endpoint = $this->buildEndpoint($this->inChineseMainland($to) ? 'sms/send' : 'internationalsms/send'); $params = [ @@ -87,7 +83,7 @@ protected function buildEndpoint($function) /** * Check if the phone number belongs to chinese mainland. * - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to + * @param PhoneNumberInterface $to * * @return bool */ diff --git a/src/Gateways/TianyiwuxianGateway.php b/src/Gateways/TianyiwuxianGateway.php index a30758c..201d797 100644 --- a/src/Gateways/TianyiwuxianGateway.php +++ b/src/Gateways/TianyiwuxianGateway.php @@ -26,26 +26,22 @@ class TianyiwuxianGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_TEMPLATE = 'http://jk.106api.cn/sms%s.aspx'; + public const ENDPOINT_TEMPLATE = 'http://jk.106api.cn/sms%s.aspx'; - const ENDPOINT_ENCODE = 'UTF8'; + public const ENDPOINT_ENCODE = 'UTF8'; - const ENDPOINT_TYPE = 'send'; + public const ENDPOINT_TYPE = 'send'; - const ENDPOINT_FORMAT = 'json'; + public const ENDPOINT_FORMAT = 'json'; - const SUCCESS_STATUS = 'success'; + public const SUCCESS_STATUS = 'success'; - const SUCCESS_CODE = '0'; + public const SUCCESS_CODE = '0'; /** - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array * - * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException ; + * @throws GatewayErrorException ; */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { diff --git a/src/Gateways/TiniyoGateway.php b/src/Gateways/TiniyoGateway.php index f3faff3..64c5476 100644 --- a/src/Gateways/TiniyoGateway.php +++ b/src/Gateways/TiniyoGateway.php @@ -26,9 +26,9 @@ class TiniyoGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_URL = 'https://api.tiniyo.com/v1/Account/%s/Message'; + public const ENDPOINT_URL = 'https://api.tiniyo.com/v1/Account/%s/Message'; - const SUCCESS_CODE = '000000'; + public const SUCCESS_CODE = '000000'; public function getName() { @@ -36,13 +36,9 @@ public function getName() } /** - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array * - * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException + * @throws GatewayErrorException */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { diff --git a/src/Gateways/TinreeGateway.php b/src/Gateways/TinreeGateway.php index 7a72dd9..e42643a 100644 --- a/src/Gateways/TinreeGateway.php +++ b/src/Gateways/TinreeGateway.php @@ -11,11 +11,11 @@ namespace Overtrue\EasySms\Gateways; -use Overtrue\EasySms\Support\Config; -use Overtrue\EasySms\Traits\HasHttpRequest; use Overtrue\EasySms\Contracts\MessageInterface; use Overtrue\EasySms\Contracts\PhoneNumberInterface; use Overtrue\EasySms\Exceptions\GatewayErrorException; +use Overtrue\EasySms\Support\Config; +use Overtrue\EasySms\Traits\HasHttpRequest; /** * Class TinreeGateway. @@ -26,16 +26,12 @@ class TinreeGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_URL = 'http://api.tinree.com/api/v2/single_send'; + public const ENDPOINT_URL = 'http://api.tinree.com/api/v2/single_send'; /** - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array * - * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException + * @throws GatewayErrorException */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { @@ -61,7 +57,6 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config * 构建发送内容 * 用 data 数据合成内容,或者直接使用 data 的值 * - * @param MessageInterface $message * @return string */ protected function buildContent(MessageInterface $message) @@ -69,7 +64,7 @@ protected function buildContent(MessageInterface $message) $data = $message->getData($this); if (is_array($data)) { - return implode("##", $data); + return implode('##', $data); } return $data; diff --git a/src/Gateways/TwilioGateway.php b/src/Gateways/TwilioGateway.php index 95e572c..226dca8 100644 --- a/src/Gateways/TwilioGateway.php +++ b/src/Gateways/TwilioGateway.php @@ -27,7 +27,7 @@ class TwilioGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_URL = 'https://api.twilio.com/2010-04-01/Accounts/%s/Messages.json'; + public const ENDPOINT_URL = 'https://api.twilio.com/2010-04-01/Accounts/%s/Messages.json'; protected $errorStatuses = [ 'failed', @@ -40,13 +40,9 @@ public function getName() } /** - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array * - * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException + * @throws GatewayErrorException */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { diff --git a/src/Gateways/UcloudGateway.php b/src/Gateways/UcloudGateway.php index fddfd3c..d48a3cf 100644 --- a/src/Gateways/UcloudGateway.php +++ b/src/Gateways/UcloudGateway.php @@ -24,19 +24,15 @@ class UcloudGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_URL = 'https://api.ucloud.cn'; + public const ENDPOINT_URL = 'https://api.ucloud.cn'; - const ENDPOINT_Action = 'SendUSMSMessage'; + public const ENDPOINT_Action = 'SendUSMSMessage'; - const SUCCESS_CODE = 0; + public const SUCCESS_CODE = 0; /** * Send Message. * - * @param PhoneNumberInterface $to - * @param MessageInterface $message - * @param Config $config - * * @return array * * @throws GatewayErrorException @@ -57,10 +53,6 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config /** * Build Params. * - * @param PhoneNumberInterface $to - * @param MessageInterface $message - * @param Config $config - * * @return array */ protected function buildParams(PhoneNumberInterface $to, MessageInterface $message, Config $config) diff --git a/src/Gateways/Ue35Gateway.php b/src/Gateways/Ue35Gateway.php index 9e05e1d..dd76d94 100644 --- a/src/Gateways/Ue35Gateway.php +++ b/src/Gateways/Ue35Gateway.php @@ -26,22 +26,18 @@ class Ue35Gateway extends Gateway { use HasHttpRequest; - const ENDPOINT_HOST = 'sms.ue35.cn'; + public const ENDPOINT_HOST = 'sms.ue35.cn'; - const ENDPOINT_URI = '/sms/interface/sendmess.htm'; + public const ENDPOINT_URI = '/sms/interface/sendmess.htm'; - const SUCCESS_CODE = 1; + public const SUCCESS_CODE = 1; /** * Send message. * - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array * - * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException ; + * @throws GatewayErrorException ; */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { diff --git a/src/Gateways/VolcengineGateway.php b/src/Gateways/VolcengineGateway.php index 536e7c5..eb01439 100644 --- a/src/Gateways/VolcengineGateway.php +++ b/src/Gateways/VolcengineGateway.php @@ -13,9 +13,9 @@ use GuzzleHttp\Exception\ClientException; use GuzzleHttp\HandlerStack; +use GuzzleHttp\Psr7; use GuzzleHttp\Psr7\Query; use GuzzleHttp\Psr7\Utils; -use GuzzleHttp\Psr7; use Overtrue\EasySms\Contracts\MessageInterface; use Overtrue\EasySms\Contracts\PhoneNumberInterface; use Overtrue\EasySms\Exceptions\GatewayErrorException; @@ -32,16 +32,16 @@ class VolcengineGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_ACTION = 'SendSms'; - const ENDPOINT_VERSION = '2020-01-01'; - const ENDPOINT_CONTENT_TYPE = 'application/json; charset=utf-8'; - const ENDPOINT_ACCEPT = 'application/json'; - const ENDPOINT_USER_AGENT = 'overtrue/easy-sms'; - const ENDPOINT_SERVICE = 'volcSMS'; + public const ENDPOINT_ACTION = 'SendSms'; + public const ENDPOINT_VERSION = '2020-01-01'; + public const ENDPOINT_CONTENT_TYPE = 'application/json; charset=utf-8'; + public const ENDPOINT_ACCEPT = 'application/json'; + public const ENDPOINT_USER_AGENT = 'overtrue/easy-sms'; + public const ENDPOINT_SERVICE = 'volcSMS'; - const Algorithm = 'HMAC-SHA256'; + public const Algorithm = 'HMAC-SHA256'; - const ENDPOINT_DEFAULT_REGION_ID = 'cn-north-1'; + public const ENDPOINT_DEFAULT_REGION_ID = 'cn-north-1'; public static $endpoints = [ 'cn-north-1' => 'https://sms.volcengineapi.com', @@ -51,7 +51,6 @@ class VolcengineGateway extends Gateway private $regionId = self::ENDPOINT_DEFAULT_REGION_ID; protected $requestDate; - public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { $data = $message->getData($this); @@ -85,7 +84,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config 'headers' => [ 'Content-Type' => self::ENDPOINT_CONTENT_TYPE, 'Accept' => self::ENDPOINT_ACCEPT, - 'User-Agent' => self::ENDPOINT_USER_AGENT + 'User-Agent' => self::ENDPOINT_USER_AGENT, ], 'timeout' => $this->getTimeout(), 'handler' => $stack, @@ -102,8 +101,9 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config if (isset($response['ResponseMetadata']['Error'])) { // 请求错误参数,如果请求没有错误,则不存在该参数返回 // 火山引擎错误码格式为:'ZJ'+ 5位数字,比如 ZJ20009,取出数字部分 preg_match('/\d+/', $response['ResponseMetadata']['Error']['Code'], $matches); - throw new GatewayErrorException($response['ResponseMetadata']['Error']['Code'].":".$response['ResponseMetadata']['Error']['Message'], $matches[0], $response); + throw new GatewayErrorException($response['ResponseMetadata']['Error']['Code'].':'.$response['ResponseMetadata']['Error']['Message'], $matches[0], $response); } + return $response; } catch (ClientException $exception) { $responseContent = $exception->getResponse()->getBody()->getContents(); @@ -111,7 +111,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config if (isset($response['ResponseMetadata']['Error']) && $error = $response['ResponseMetadata']['Error']) { // 请求错误参数,如果请求没有错误,则不存在该参数返回 // 火山引擎公共错误码Error与业务错误码略有不同,比如:"Error":{"CodeN":100004,"Code":"MissingRequestInfo","Message":"The request is missing timestamp information."} // 此处错误码直接取 CodeN - throw new GatewayErrorException($error["CodeN"].":".$error['Message'], $error["CodeN"], $response); + throw new GatewayErrorException($error['CodeN'].':'.$error['Message'], $error['CodeN'], $response); } throw new GatewayErrorException($responseContent, $exception->getCode(), ['content' => $responseContent]); } @@ -142,7 +142,7 @@ protected function signHandle() $parsed['headers']['Authorization'] = self::Algorithm. ' Credential='.$this->getAccessKeyId().'/'.$this->getCredentialScope().', SignedHeaders='.$signedHeaders.', Signature='.$signature; - $buildRequest = function () use ($request, $parsed) { + $buildRequest = function () use ($parsed) { if ($parsed['query']) { $parsed['uri'] = $parsed['uri']->withQuery(Query::build($parsed['query'])); } @@ -164,6 +164,7 @@ protected function signHandle() private function parseRequest(RequestInterface $request) { $uri = $request->getUri(); + return [ 'method' => $request->getMethod(), 'path' => $uri->getPath(), @@ -171,7 +172,7 @@ private function parseRequest(RequestInterface $request) 'uri' => $uri, 'headers' => $request->getHeaders(), 'body' => $request->getBody(), - 'version' => $request->getProtocolVersion() + 'version' => $request->getProtocolVersion(), ]; } @@ -195,6 +196,7 @@ public function getEndpoint() if (!in_array($regionId, array_keys(self::$endpoints))) { $regionId = self::ENDPOINT_DEFAULT_REGION_ID; } + return static::$endpoints[$regionId]; } @@ -203,9 +205,9 @@ public function getRequestDate() return $this->requestDate ?: gmdate('Ymd\THis\Z'); } - /** - * 指代信任状,格式为:YYYYMMDD/region/service/request + * 指代信任状,格式为:YYYYMMDD/region/service/request. + * * @return string */ public function getCredentialScope() @@ -222,20 +224,23 @@ public function getCredentialScope() * kService = HMAC(kRegion, Service) * kSigning = HMAC(kService, "request") * 其中Date精确到日,与RequestDate中YYYYMMDD部分相同。 + * * @return string */ protected function getSigningKey() { - $dateKey = hash_hmac('sha256', date("Ymd", strtotime($this->getRequestDate())), $this->getAccessKeySecret(), true); + $dateKey = hash_hmac('sha256', date('Ymd', strtotime($this->getRequestDate())), $this->getAccessKeySecret(), true); $regionKey = hash_hmac('sha256', $this->getRegionId(), $dateKey, true); $serviceKey = hash_hmac('sha256', self::ENDPOINT_SERVICE, $regionKey, true); + return hash_hmac('sha256', 'request', $serviceKey, true); } /** * 创建签名字符串 * 签名字符串主要包含请求以及正规化请求的元数据信息,由签名算法、请求日期、信任状和正规化请求哈希值连接组成,伪代码如下: - * StringToSign = Algorithm + '\n' + RequestDate + '\n' + CredentialScope + '\n' + HexEncode(Hash(CanonicalRequest)) + * StringToSign = Algorithm + '\n' + RequestDate + '\n' + CredentialScope + '\n' + HexEncode(Hash(CanonicalRequest)). + * * @return string */ public function getStringToSign($canonicalRequest) @@ -266,6 +271,7 @@ public function getAccessKeyId() * 其中CanonicalHeadersEntry = Lowercase(HeaderName) + ':' + Trimall(HeaderValue) + '\n' * Lowcase代表将Header的名称全部转化成小写,Trimall表示去掉Header的值的前后多余的空格。 * 特别注意:最后需要添加"\n"的换行符,header的顺序是以headerName的小写后ascii排序。 + * * @return array */ public function getCanonicalHeaders(RequestInterface $request) @@ -280,6 +286,7 @@ public function getCanonicalHeaders(RequestInterface $request) $signedHeaders[] = $lowerKey; } $signedHeadersString = implode(';', $signedHeaders); + return [$canonicalHeaders, $signedHeadersString]; } @@ -287,12 +294,14 @@ public function getCanonicalHeaders(RequestInterface $request) * urlencode(注:同RFC3986方法)每一个querystring参数名称和参数值。 * 按照ASCII字节顺序对参数名称严格排序,相同参数名的不同参数值需保持请求的原始顺序。 * 将排序好的参数名称和参数值用=连接,按照排序结果将“参数对”用&连接。 - * 例如:CanonicalQueryString = "Action=ListUsers&Version=2018-01-01" + * 例如:CanonicalQueryString = "Action=ListUsers&Version=2018-01-01". + * * @return string */ public function getCanonicalQueryString(array $query) { ksort($query); + return http_build_query($query); } diff --git a/src/Gateways/YidongmasblackGateway.php b/src/Gateways/YidongmasblackGateway.php index f8f2c00..c76f416 100644 --- a/src/Gateways/YidongmasblackGateway.php +++ b/src/Gateways/YidongmasblackGateway.php @@ -19,7 +19,8 @@ /** * Class YidongmasblackGateway. - * 移动MAS黑名单模式(免创建模板) + * 移动MAS黑名单模式(免创建模板). + * * @author houang * * @see https://mas.10086.cn @@ -28,27 +29,23 @@ class YidongmasblackGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_URL = 'http://112.35.1.155:1992/sms/norsubmit'; + public const ENDPOINT_URL = 'http://112.35.1.155:1992/sms/norsubmit'; - const ENDPOINT_METHOD = 'send'; + public const ENDPOINT_METHOD = 'send'; /** - * @param PhoneNumberInterface $to - * @param MessageInterface $message - * @param Config $config - * * @return \Psr\Http\Message\ResponseInterface|array|string * * @throws GatewayErrorException */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { - $params["ecName"] = $config->get('ecName'); - $params["apId"] = $config->get('apId'); - $params["sign"] = $config->get('sign'); - $params["addSerial"] = $config->get('addSerial'); - $params["mobiles"] = $to->getNumber(); - $params["content"] = $message->getContent(); + $params['ecName'] = $config->get('ecName'); + $params['apId'] = $config->get('apId'); + $params['sign'] = $config->get('sign'); + $params['addSerial'] = $config->get('addSerial'); + $params['mobiles'] = $to->getNumber(); + $params['content'] = $message->getContent(); $result = $this->postJson(self::ENDPOINT_URL, $this->generateContent($params)); if ('true' != $result['success']) { @@ -68,8 +65,8 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config protected function generateContent($params) { $secretKey = $this->config->get('secretKey'); - $params['mac'] = md5($params["ecName"].$params["apId"].$secretKey.$params["mobiles"].$params["content"].$params["sign"].$params["addSerial"]); - + $params['mac'] = md5($params['ecName'].$params['apId'].$secretKey.$params['mobiles'].$params['content'].$params['sign'].$params['addSerial']); + return base64_encode(json_encode($params)); } } diff --git a/src/Gateways/YunpianGateway.php b/src/Gateways/YunpianGateway.php index e60942f..dc93b59 100644 --- a/src/Gateways/YunpianGateway.php +++ b/src/Gateways/YunpianGateway.php @@ -26,20 +26,16 @@ class YunpianGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_TEMPLATE = 'https://%s.yunpian.com/%s/%s/%s.%s'; + public const ENDPOINT_TEMPLATE = 'https://%s.yunpian.com/%s/%s/%s.%s'; - const ENDPOINT_VERSION = 'v2'; + public const ENDPOINT_VERSION = 'v2'; - const ENDPOINT_FORMAT = 'json'; + public const ENDPOINT_FORMAT = 'json'; /** - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array * - * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException ; + * @throws GatewayErrorException ; */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { @@ -48,7 +44,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $option = [ 'form_params' => [ 'apikey' => $config->get('api_key'), - 'mobile' => $to->getUniversalNumber() + 'mobile' => $to->getUniversalNumber(), ], 'exceptions' => false, ]; @@ -60,18 +56,18 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $templateData = $message->getData($this); $templateData = isset($templateData) ? $templateData : []; foreach ($templateData as $key => $value) { - $data[] = urlencode('#'.$key.'#') . '=' . urlencode($value); + $data[] = urlencode('#'.$key.'#').'='.urlencode($value); } $option['form_params'] = array_merge($option['form_params'], [ 'tpl_id' => $template, - 'tpl_value' => implode('&', $data) + 'tpl_value' => implode('&', $data), ]); } else { $content = $message->getContent($this); $signature = $config->get('signature', ''); $option['form_params'] = array_merge($option['form_params'], [ - 'text' => 0 === \stripos($content, '【') ? $content : $signature.$content + 'text' => 0 === \stripos($content, '【') ? $content : $signature.$content, ]); } diff --git a/src/Gateways/YuntongxunGateway.php b/src/Gateways/YuntongxunGateway.php index 9554434..49511de 100644 --- a/src/Gateways/YuntongxunGateway.php +++ b/src/Gateways/YuntongxunGateway.php @@ -27,32 +27,28 @@ class YuntongxunGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_TEMPLATE = 'https://%s:%s/%s/%s/%s/%s/%s?sig=%s'; + public const ENDPOINT_TEMPLATE = 'https://%s:%s/%s/%s/%s/%s/%s?sig=%s'; - const SERVER_IP = 'app.cloopen.com'; + public const SERVER_IP = 'app.cloopen.com'; - const DEBUG_SERVER_IP = 'sandboxapp.cloopen.com'; + public const DEBUG_SERVER_IP = 'sandboxapp.cloopen.com'; - const DEBUG_TEMPLATE_ID = 1; + public const DEBUG_TEMPLATE_ID = 1; - const SERVER_PORT = '8883'; + public const SERVER_PORT = '8883'; - const SDK_VERSION = '2013-12-26'; + public const SDK_VERSION = '2013-12-26'; - const SDK_VERSION_INT = 'v2'; + public const SDK_VERSION_INT = 'v2'; - const SUCCESS_CODE = '000000'; + public const SUCCESS_CODE = '000000'; private $international = false; // if international SMS, default false means no. /** - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array * - * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException ; + * @throws GatewayErrorException ; */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { @@ -97,10 +93,9 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config /** * Build endpoint url. * - * @param string $type - * @param string $resource - * @param string $datetime - * @param \Overtrue\EasySms\Support\Config $config + * @param string $type + * @param string $resource + * @param string $datetime * * @return string */ diff --git a/src/Gateways/YunxinGateway.php b/src/Gateways/YunxinGateway.php index dd765fe..7da6001 100755 --- a/src/Gateways/YunxinGateway.php +++ b/src/Gateways/YunxinGateway.php @@ -28,19 +28,15 @@ class YunxinGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_TEMPLATE = 'https://api.netease.im/%s/%s.action'; + public const ENDPOINT_TEMPLATE = 'https://api.netease.im/%s/%s.action'; - const ENDPOINT_ACTION = 'sendCode'; + public const ENDPOINT_ACTION = 'sendCode'; - const SUCCESS_CODE = 200; + public const SUCCESS_CODE = 200; /** * Send a short message. * - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array * * @throws GatewayErrorException @@ -62,7 +58,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $params = $this->buildVerifyCodeParams($to, $message); break; - case "sendTemplate": + case 'sendTemplate': $params = $this->buildTemplateParams($to, $message, $config); break; @@ -89,9 +85,6 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config } /** - * @param $resource - * @param $function - * * @return string */ protected function buildEndpoint($resource, $function) @@ -102,8 +95,6 @@ protected function buildEndpoint($resource, $function) /** * Get the request headers. * - * @param Config $config - * * @return array */ protected function buildHeaders(Config $config) @@ -121,10 +112,6 @@ protected function buildHeaders(Config $config) } /** - * @param PhoneNumberInterface $to - * @param MessageInterface $message - * @param Config $config - * * @return array */ public function buildSendCodeParams(PhoneNumberInterface $to, MessageInterface $message, Config $config) @@ -143,9 +130,6 @@ public function buildSendCodeParams(PhoneNumberInterface $to, MessageInterface $ } /** - * @param PhoneNumberInterface $to - * @param MessageInterface $message - * * @return array * * @throws GatewayErrorException @@ -165,11 +149,7 @@ public function buildVerifyCodeParams(PhoneNumberInterface $to, MessageInterface } /** - * @param PhoneNumberInterface $to - * @param MessageInterface $message - * @param Config $config * @return array - * */ public function buildTemplateParams(PhoneNumberInterface $to, MessageInterface $message, Config $config) { @@ -178,10 +158,10 @@ public function buildTemplateParams(PhoneNumberInterface $to, MessageInterface $ $template = $message->getTemplate($this); return [ - 'templateid'=>$template, - 'mobiles'=>json_encode([$to->getUniversalNumber()]), - 'params'=>array_key_exists('params',$data) ? json_encode($data['params']) : '', - 'needUp'=>$config->get('need_up', false) + 'templateid' => $template, + 'mobiles' => json_encode([$to->getUniversalNumber()]), + 'params' => array_key_exists('params', $data) ? json_encode($data['params']) : '', + 'needUp' => $config->get('need_up', false), ]; } } diff --git a/src/Gateways/YunzhixunGateway.php b/src/Gateways/YunzhixunGateway.php index 0e213e4..1ae6774 100755 --- a/src/Gateways/YunzhixunGateway.php +++ b/src/Gateways/YunzhixunGateway.php @@ -28,21 +28,17 @@ class YunzhixunGateway extends Gateway { use HasHttpRequest; - const SUCCESS_CODE = '000000'; + public const SUCCESS_CODE = '000000'; - const FUNCTION_SEND_SMS = 'sendsms'; + public const FUNCTION_SEND_SMS = 'sendsms'; - const FUNCTION_BATCH_SEND_SMS = 'sendsms_batch'; + public const FUNCTION_BATCH_SEND_SMS = 'sendsms_batch'; - const ENDPOINT_TEMPLATE = 'https://open.ucpaas.com/ol/%s/%s'; + public const ENDPOINT_TEMPLATE = 'https://open.ucpaas.com/ol/%s/%s'; /** * Send a short message. * - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array * * @throws GatewayErrorException @@ -61,9 +57,6 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config } /** - * @param $resource - * @param $function - * * @return string */ protected function buildEndpoint($resource, $function) @@ -72,10 +65,6 @@ protected function buildEndpoint($resource, $function) } /** - * @param PhoneNumberInterface $to - * @param MessageInterface $message - * @param Config $config - * * @return array */ protected function buildParams(PhoneNumberInterface $to, MessageInterface $message, Config $config) @@ -94,9 +83,6 @@ protected function buildParams(PhoneNumberInterface $to, MessageInterface $messa } /** - * @param $endpoint - * @param $params - * * @return array * * @throws GatewayErrorException diff --git a/src/Gateways/ZzyunGateway.php b/src/Gateways/ZzyunGateway.php index 878a6a7..429daf5 100644 --- a/src/Gateways/ZzyunGateway.php +++ b/src/Gateways/ZzyunGateway.php @@ -26,27 +26,23 @@ class ZzyunGateway extends Gateway { use HasHttpRequest; - const ENDPOINT_URL = 'https://zzyun.com/api/sms/sendByTplCode'; + public const ENDPOINT_URL = 'https://zzyun.com/api/sms/sendByTplCode'; /** - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param \Overtrue\EasySms\Support\Config $config - * * @return array * - * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException ; + * @throws GatewayErrorException ; */ public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) { $time = time(); $user_id = $config->get('user_id'); - $token = md5($time . $user_id . $config->get('secret')); + $token = md5($time.$user_id.$config->get('secret')); $params = [ 'user_id' => $user_id, 'time' => $time, 'token' => $token, - 'mobiles' => $to->getNumber(),// 手机号码,多个英文逗号隔开 + 'mobiles' => $to->getNumber(), // 手机号码,多个英文逗号隔开 'tpl_code' => $message->getTemplate($this), 'tpl_params' => $message->getData($this), 'sign_name' => $config->get('sign_name'), diff --git a/src/Message.php b/src/Message.php index 7b76ca8..56ba105 100644 --- a/src/Message.php +++ b/src/Message.php @@ -47,7 +47,6 @@ class Message implements MessageInterface /** * Message constructor. * - * @param array $attributes * @param string $type */ public function __construct(array $attributes = [], $type = MessageInterface::TEXT_MESSAGE) @@ -74,11 +73,9 @@ public function getMessageType() /** * Return message content. * - * @param \Overtrue\EasySms\Contracts\GatewayInterface|null $gateway - * * @return string */ - public function getContent(GatewayInterface $gateway = null) + public function getContent(?GatewayInterface $gateway = null) { return is_callable($this->content) ? call_user_func($this->content, $gateway) : $this->content; } @@ -86,18 +83,14 @@ public function getContent(GatewayInterface $gateway = null) /** * Return the template id of message. * - * @param \Overtrue\EasySms\Contracts\GatewayInterface|null $gateway - * * @return string */ - public function getTemplate(GatewayInterface $gateway = null) + public function getTemplate(?GatewayInterface $gateway = null) { return is_callable($this->template) ? call_user_func($this->template, $gateway) : $this->template; } /** - * @param $type - * * @return $this */ public function setType($type) @@ -108,8 +101,6 @@ public function setType($type) } /** - * @param mixed $content - * * @return $this */ public function setContent($content) @@ -120,8 +111,6 @@ public function setContent($content) } /** - * @param mixed $template - * * @return $this */ public function setTemplate($template) @@ -132,11 +121,9 @@ public function setTemplate($template) } /** - * @param \Overtrue\EasySms\Contracts\GatewayInterface|null $gateway - * * @return array */ - public function getData(GatewayInterface $gateway = null) + public function getData(?GatewayInterface $gateway = null) { return is_callable($this->data) ? call_user_func($this->data, $gateway) : $this->data; } @@ -162,8 +149,6 @@ public function getGateways() } /** - * @param array $gateways - * * @return $this */ public function setGateways(array $gateways) @@ -174,8 +159,6 @@ public function setGateways(array $gateways) } /** - * @param $property - * * @return string */ public function __get($property) diff --git a/src/Messenger.php b/src/Messenger.php index 97b704c..abea0e2 100644 --- a/src/Messenger.php +++ b/src/Messenger.php @@ -20,19 +20,17 @@ */ class Messenger { - const STATUS_SUCCESS = 'success'; + public const STATUS_SUCCESS = 'success'; - const STATUS_FAILURE = 'failure'; + public const STATUS_FAILURE = 'failure'; /** - * @var \Overtrue\EasySms\EasySms + * @var EasySms */ protected $easySms; /** * Messenger constructor. - * - * @param \Overtrue\EasySms\EasySms $easySms */ public function __construct(EasySms $easySms) { @@ -42,13 +40,9 @@ public function __construct(EasySms $easySms) /** * Send a message. * - * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to - * @param \Overtrue\EasySms\Contracts\MessageInterface $message - * @param array $gateways - * * @return array * - * @throws \Overtrue\EasySms\Exceptions\NoGatewayAvailableException + * @throws NoGatewayAvailableException */ public function send(PhoneNumberInterface $to, MessageInterface $message, array $gateways = []) { @@ -60,7 +54,7 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, array $results[$gateway] = [ 'gateway' => $gateway, 'status' => self::STATUS_SUCCESS, - 'template' => $message->getTemplate($this->easySms->gateway($gateway)), + 'template' => $message->getTemplate($this->easySms->gateway($gateway)), 'result' => $this->easySms->gateway($gateway)->send($to, $message, $config), ]; $isSuccessful = true; @@ -70,14 +64,14 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, array $results[$gateway] = [ 'gateway' => $gateway, 'status' => self::STATUS_FAILURE, - 'template' => $message->getTemplate($this->easySms->gateway($gateway)), + 'template' => $message->getTemplate($this->easySms->gateway($gateway)), 'exception' => $e, ]; } catch (\Throwable $e) { $results[$gateway] = [ 'gateway' => $gateway, 'status' => self::STATUS_FAILURE, - 'template' => $message->getTemplate($this->easySms->gateway($gateway)), + 'template' => $message->getTemplate($this->easySms->gateway($gateway)), 'exception' => $e, ]; } diff --git a/src/PhoneNumber.php b/src/PhoneNumber.php index cde95f5..4c4dcee 100644 --- a/src/PhoneNumber.php +++ b/src/PhoneNumber.php @@ -16,7 +16,7 @@ * * @author overtrue */ -class PhoneNumber implements \Overtrue\EasySms\Contracts\PhoneNumberInterface +class PhoneNumber implements Contracts\PhoneNumberInterface { /** * @var int @@ -121,6 +121,6 @@ public function jsonSerialize() */ public function inChineseMainland() { - return empty($this->IDDCode) || $this->IDDCode === 86; + return empty($this->IDDCode) || 86 === $this->IDDCode; } } diff --git a/src/Strategies/OrderStrategy.php b/src/Strategies/OrderStrategy.php index f44b29e..e5ef583 100644 --- a/src/Strategies/OrderStrategy.php +++ b/src/Strategies/OrderStrategy.php @@ -21,8 +21,6 @@ class OrderStrategy implements StrategyInterface /** * Apply the strategy and return result. * - * @param array $gateways - * * @return array */ public function apply(array $gateways) diff --git a/src/Strategies/RandomStrategy.php b/src/Strategies/RandomStrategy.php index 605c5d9..373398f 100644 --- a/src/Strategies/RandomStrategy.php +++ b/src/Strategies/RandomStrategy.php @@ -19,8 +19,6 @@ class RandomStrategy implements StrategyInterface { /** - * @param array $gateways - * * @return array */ public function apply(array $gateways) diff --git a/src/Support/Config.php b/src/Support/Config.php index 3b91423..770726b 100644 --- a/src/Support/Config.php +++ b/src/Support/Config.php @@ -16,7 +16,7 @@ /** * Class Config. */ -class Config implements ArrayAccess +class Config implements \ArrayAccess { /** * @var array @@ -25,8 +25,6 @@ class Config implements ArrayAccess /** * Config constructor. - * - * @param array $config */ public function __construct(array $config = []) { @@ -37,9 +35,6 @@ public function __construct(array $config = []) * Get an item from an array using "dot" notation. * * @param string $key - * @param mixed $default - * - * @return mixed */ public function get($key, $default = null) { diff --git a/src/Traits/HasHttpRequest.php b/src/Traits/HasHttpRequest.php index d861ded..aaeef0d 100644 --- a/src/Traits/HasHttpRequest.php +++ b/src/Traits/HasHttpRequest.php @@ -56,7 +56,6 @@ protected function post($endpoint, $params = [], $headers = []) /** * Make a post request with json params. * - * @param $endpoint * @param array $params * @param array $headers * @@ -102,9 +101,7 @@ protected function getBaseOptions() /** * Return http client. * - * @param array $options - * - * @return \GuzzleHttp\Client + * @return Client * * @codeCoverageIgnore */ @@ -116,8 +113,6 @@ protected function getHttpClient(array $options = []) /** * Convert response contents to json. * - * @param \Psr\Http\Message\ResponseInterface $response - * * @return ResponseInterface|array|string */ protected function unwrapResponse(ResponseInterface $response) diff --git a/tests/Gateways/AliyunIntlGatewayTest.php b/tests/Gateways/AliyunIntlGatewayTest.php index 2ae70c7..8bb7859 100644 --- a/tests/Gateways/AliyunIntlGatewayTest.php +++ b/tests/Gateways/AliyunIntlGatewayTest.php @@ -3,21 +3,19 @@ namespace Overtrue\EasySms\Tests\Gateways; use Overtrue\EasySms\Exceptions\GatewayErrorException; +use Overtrue\EasySms\Gateways\AliyunIntlGateway; use Overtrue\EasySms\Message; use Overtrue\EasySms\PhoneNumber; use Overtrue\EasySms\Support\Config; use Overtrue\EasySms\Tests\TestCase; -use Overtrue\EasySms\Gateways\AliyunIntlGateway; /** - * Class AliyunIntlGatewayTest - * - * @package \Overtrue\EasySms\Tests\Gateways + * Class AliyunIntlGatewayTest. */ class AliyunIntlGatewayTest extends TestCase { /** @test */ - public function it_can_sen_sms_by_aliyun_intl_gateway() + public function itCanSenSmsByAliyunIntlGateway() { $config = [ 'access_key_id' => 'mock-api-key', diff --git a/tests/Gateways/AliyunrestGatewayTest.php b/tests/Gateways/AliyunrestGatewayTest.php index 44a9153..e27b38b 100644 --- a/tests/Gateways/AliyunrestGatewayTest.php +++ b/tests/Gateways/AliyunrestGatewayTest.php @@ -63,10 +63,10 @@ public function testSend() 'err_code' => '0', 'msg' => 'mock-result', 'success' => true, ], ], ], [ - 'error_response' => [ - 'code' => 15, - 'msg' => 'mock-err-msg', - ], ])->twice(); + 'error_response' => [ + 'code' => 15, + 'msg' => 'mock-err-msg', + ], ])->twice(); $message = new Message([ 'template' => 'mock-template-code', diff --git a/tests/Gateways/JuheGatewayTest.php b/tests/Gateways/JuheGatewayTest.php index a1062be..bd41ac3 100644 --- a/tests/Gateways/JuheGatewayTest.php +++ b/tests/Gateways/JuheGatewayTest.php @@ -44,12 +44,12 @@ public function testSend() ])->times(2); $message = new Message([ - 'content' => 'This is a huyi test message.', - 'template' => 'mock-tpl-id', - 'data' => [ - 'code' => 1234, - ], - ]); + 'content' => 'This is a huyi test message.', + 'template' => 'mock-tpl-id', + 'data' => [ + 'code' => 1234, + ], + ]); $config = new Config($config); diff --git a/tests/Gateways/MaapGatewayTest.php b/tests/Gateways/MaapGatewayTest.php index 27a3851..c63f123 100644 --- a/tests/Gateways/MaapGatewayTest.php +++ b/tests/Gateways/MaapGatewayTest.php @@ -28,7 +28,7 @@ public function testSend() 'excode' => 'mock-excode', ]; - $gateway = \Mockery::mock(MaapGateway::class . '[postJson]', [$config])->shouldAllowMockingProtectedMethods(); + $gateway = \Mockery::mock(MaapGateway::class.'[postJson]', [$config])->shouldAllowMockingProtectedMethods(); $params = [ 'cpcode' => 'mock-cpcode', @@ -37,7 +37,7 @@ public function testSend() 'excode' => 'mock-excode', 'templetid' => '123456', ]; - $params['sign'] = md5($params['cpcode'] . $params['msg'] . $params['mobiles'] . $params['excode'] . $params['templetid'] . $config['key']); + $params['sign'] = md5($params['cpcode'].$params['msg'].$params['mobiles'].$params['excode'].$params['templetid'].$config['key']); $gateway->shouldReceive('postJson') ->with(MaapGateway::ENDPOINT_URL, $params) diff --git a/tests/Gateways/ModuyunGatewayTest.php b/tests/Gateways/ModuyunGatewayTest.php index b10ef47..d4d1748 100644 --- a/tests/Gateways/ModuyunGatewayTest.php +++ b/tests/Gateways/ModuyunGatewayTest.php @@ -26,7 +26,7 @@ public function testSend() 'accesskey' => 'mock-accesskey', 'secretkey' => 'mock-secretkey', ]; - $gateway = \Mockery::mock(ModuyunGateway::class . '[request]', [$config])->shouldAllowMockingProtectedMethods(); + $gateway = \Mockery::mock(ModuyunGateway::class.'[request]', [$config])->shouldAllowMockingProtectedMethods(); $gateway->shouldReceive('request') ->andReturn( @@ -34,7 +34,7 @@ public function testSend() 'result' => 0, 'errmsg' => 'OK', 'ext' => '', - 'sid' => "mock-sid", + 'sid' => 'mock-sid', 'surplus' => 4, 'balance' => 0, ], @@ -57,7 +57,7 @@ public function testSend() 'result' => 0, 'errmsg' => 'OK', 'ext' => '', - 'sid' => "mock-sid", + 'sid' => 'mock-sid', 'surplus' => 4, 'balance' => 0, ], $gateway->send(new PhoneNumber(18888888888), $message, $config)); diff --git a/tests/Gateways/NowcnGatewaysTest.php b/tests/Gateways/NowcnGatewaysTest.php index 85e2cfb..1fe2ce8 100644 --- a/tests/Gateways/NowcnGatewaysTest.php +++ b/tests/Gateways/NowcnGatewaysTest.php @@ -19,7 +19,7 @@ public function testSend() 'api_type' => '3', ]; - $gateway = \Mockery::mock(NowcnGateway::class . '[request]', [$config])->shouldAllowMockingProtectedMethods(); + $gateway = \Mockery::mock(NowcnGateway::class.'[request]', [$config])->shouldAllowMockingProtectedMethods(); $gateway->shouldReceive('request')->with( 'get', \Mockery::on(function ($api) { @@ -28,10 +28,10 @@ public function testSend() \Mockery::on(function ($params) { return true; }) - ) ->andReturn([ + )->andReturn([ 'code' => NowcnGateway::SUCCESS_CODE, ], [ - 'code' => "-4", + 'code' => '-4', 'msg' => 'authorize failed', ])->times(2); diff --git a/tests/Gateways/QcloudGatewayTest.php b/tests/Gateways/QcloudGatewayTest.php index c460731..c3ebde8 100644 --- a/tests/Gateways/QcloudGatewayTest.php +++ b/tests/Gateways/QcloudGatewayTest.php @@ -26,7 +26,7 @@ public function testSend() 'sdk_app_id' => 'mock-sdk-app-id', 'secret_key' => 'mock-secret-key', 'secret_id' => 'mock-secret-id', - 'sign_name' => 'mock-api-sign-name' + 'sign_name' => 'mock-api-sign-name', ]; $gateway = \Mockery::mock(QcloudGateway::class.'[request]', [$config])->shouldAllowMockingProtectedMethods(); @@ -34,33 +34,33 @@ public function testSend() $gateway->shouldReceive('request') ->andReturn([ 'Response' => [ - "SendStatusSet" => [ + 'SendStatusSet' => [ [ - "SerialNo" => "2028:f825e6b16e23f73f4123", - "PhoneNumber" => "8618888888888", - "Fee" => 1, - "SessionContext" => "", - "Code" => "Ok", - "Message" => "send success", - "IsoCode" => "CN" - ] - ] + 'SerialNo' => '2028:f825e6b16e23f73f4123', + 'PhoneNumber' => '8618888888888', + 'Fee' => 1, + 'SessionContext' => '', + 'Code' => 'Ok', + 'Message' => 'send success', + 'IsoCode' => 'CN', + ], + ], ], - 'RequestId' => '0dc99542-c61a-4a16-9545-ec8ec202c543' + 'RequestId' => '0dc99542-c61a-4a16-9545-ec8ec202c543', ], [ 'Response' => [ - "Error" => [ - "Code" => "AuthFailure.SignatureFailure", - "Message" => "The provided credentials could not be validated. Please check your signature is correct.", - ] + 'Error' => [ + 'Code' => 'AuthFailure.SignatureFailure', + 'Message' => 'The provided credentials could not be validated. Please check your signature is correct.', + ], ], - 'RequestId' => '0dc99542-c61a-4a16-9545-2b967e2c980a' + 'RequestId' => '0dc99542-c61a-4a16-9545-2b967e2c980a', ])->twice(); $message = new Message([ 'template' => 'template-id', 'data' => [ - "888888", + '888888', ], ]); @@ -68,19 +68,19 @@ public function testSend() $this->assertSame([ 'Response' => [ - "SendStatusSet" => [ + 'SendStatusSet' => [ [ - "SerialNo" => "2028:f825e6b16e23f73f4123", - "PhoneNumber" => "8618888888888", - "Fee" => 1, - "SessionContext" => "", - "Code" => "Ok", - "Message" => "send success", - "IsoCode" => "CN" - ] - ] + 'SerialNo' => '2028:f825e6b16e23f73f4123', + 'PhoneNumber' => '8618888888888', + 'Fee' => 1, + 'SessionContext' => '', + 'Code' => 'Ok', + 'Message' => 'send success', + 'IsoCode' => 'CN', + ], + ], ], - 'RequestId' => '0dc99542-c61a-4a16-9545-ec8ec202c543' + 'RequestId' => '0dc99542-c61a-4a16-9545-ec8ec202c543', ], $gateway->send(new PhoneNumber(18888888888), $message, $config)); $this->expectException(GatewayErrorException::class); @@ -96,7 +96,7 @@ public function testSendWithPartialErrors() 'sdk_app_id' => 'mock-sdk-app-id', 'secret_key' => 'mock-secret-key', 'secret_id' => 'mock-secret-id', - 'sign_name' => 'mock-api-sign-name' + 'sign_name' => 'mock-api-sign-name', ]; $gateway = \Mockery::mock(QcloudGateway::class.'[request]', [$config])->shouldAllowMockingProtectedMethods(); @@ -104,25 +104,25 @@ public function testSendWithPartialErrors() $gateway->shouldReceive('request') ->andReturn([ 'Response' => [ - "SendStatusSet" => [ + 'SendStatusSet' => [ [ - "SerialNo" => "2028:f825e6b16e23f73f4123", - "PhoneNumber" => "8618888888888", - "Fee" => 1, - "SessionContext" => "", - "Code" => "InvalidParameterValue.TemplateParameterFormatError", - "Message" => "Verification code template parameter format error", - "IsoCode" => "CN" - ] - ] + 'SerialNo' => '2028:f825e6b16e23f73f4123', + 'PhoneNumber' => '8618888888888', + 'Fee' => 1, + 'SessionContext' => '', + 'Code' => 'InvalidParameterValue.TemplateParameterFormatError', + 'Message' => 'Verification code template parameter format error', + 'IsoCode' => 'CN', + ], + ], ], - 'RequestId' => '0dc99542-c61a-4a16-9545-ec8ec202c543' + 'RequestId' => '0dc99542-c61a-4a16-9545-ec8ec202c543', ])->once(); $message = new Message([ 'template' => 'template-id', 'data' => [ - "888888", + '888888', ], ]); diff --git a/tests/Gateways/RongheyunGatewayTest.php b/tests/Gateways/RongheyunGatewayTest.php index e7baaa2..0a02764 100644 --- a/tests/Gateways/RongheyunGatewayTest.php +++ b/tests/Gateways/RongheyunGatewayTest.php @@ -27,7 +27,7 @@ public function testSend() 'password' => 'mock-password', 'signature' => 'mock-signature', ]; - $gateway = \Mockery::mock(RongheyunGateway::class . '[request]', [$config])->shouldAllowMockingProtectedMethods(); + $gateway = \Mockery::mock(RongheyunGateway::class.'[request]', [$config])->shouldAllowMockingProtectedMethods(); $gateway->shouldReceive('request') ->andReturn( @@ -36,14 +36,14 @@ public function testSend() 'msg' => 'success', 'tpId' => '31874', 'msgId' => '161553136878837480961', - 'invalidList' => [] + 'invalidList' => [], ], [ 'code' => 4025, 'msg' => 'template records null', 'tpId' => '31874', 'msgId' => '161553131051357039361', - 'invalidList' => null + 'invalidList' => null, ] )->twice(); @@ -61,7 +61,7 @@ public function testSend() 'msg' => 'success', 'tpId' => '31874', 'msgId' => '161553136878837480961', - 'invalidList' => [] + 'invalidList' => [], ], $gateway->send(new PhoneNumber(18888888888), $message, $config)); $this->expectException(GatewayErrorException::class); diff --git a/tests/Gateways/SendcloudGatewayTest.php b/tests/Gateways/SendcloudGatewayTest.php index 2ba1f19..e2339c8 100644 --- a/tests/Gateways/SendcloudGatewayTest.php +++ b/tests/Gateways/SendcloudGatewayTest.php @@ -65,12 +65,12 @@ public function testSend() ])->times(2); $message = new Message([ - 'content' => 'This is a test message.', - 'template' => 'mock-tpl-id', - 'data' => [ - 'code' => 1234, - ], - ]); + 'content' => 'This is a test message.', + 'template' => 'mock-tpl-id', + 'data' => [ + 'code' => 1234, + ], + ]); $config = new Config($config); diff --git a/tests/Gateways/SmsbaoGatewayTest.php b/tests/Gateways/SmsbaoGatewayTest.php index dac0fdb..207556b 100644 --- a/tests/Gateways/SmsbaoGatewayTest.php +++ b/tests/Gateways/SmsbaoGatewayTest.php @@ -19,7 +19,8 @@ use Overtrue\EasySms\Tests\TestCase; /** - * Class SmsbaoGatewayTest + * Class SmsbaoGatewayTest. + * * @author iwindy <203962638@qq.com> */ class SmsbaoGatewayTest extends TestCase @@ -28,16 +29,16 @@ public function testSendWithSMS() { $config = [ 'user' => 'mock-user', - 'password' => 'mock-password' + 'password' => 'mock-password', ]; - $gateway = \Mockery::mock(SmsbaoGateway::class . '[get]', [$config])->shouldAllowMockingProtectedMethods(); + $gateway = \Mockery::mock(SmsbaoGateway::class.'[get]', [$config])->shouldAllowMockingProtectedMethods(); $params = [ 'u' => 'mock-user', 'p' => md5('mock-password'), 'm' => '18188888888', - 'c' => 'This is a test message.' + 'c' => 'This is a test message.', ]; $endpoint = sprintf(SmsbaoGateway::ENDPOINT_URL, 'sms'); @@ -63,16 +64,16 @@ public function testSendWithWSMS() { $config = [ 'user' => 'mock-user', - 'password' => 'mock-password' + 'password' => 'mock-password', ]; - $gateway = \Mockery::mock(SmsbaoGateway::class . '[get]', [$config])->shouldAllowMockingProtectedMethods(); + $gateway = \Mockery::mock(SmsbaoGateway::class.'[get]', [$config])->shouldAllowMockingProtectedMethods(); $params = [ 'u' => 'mock-user', 'p' => md5('mock-password'), 'm' => '+8518188888888', - 'c' => 'This is a test message.' + 'c' => 'This is a test message.', ]; $endpoint = sprintf(SmsbaoGateway::ENDPOINT_URL, 'wsms'); diff --git a/tests/Gateways/SubmailGatewayTest.php b/tests/Gateways/SubmailGatewayTest.php index e50cfbd..e07be6e 100644 --- a/tests/Gateways/SubmailGatewayTest.php +++ b/tests/Gateways/SubmailGatewayTest.php @@ -75,7 +75,7 @@ public function testContentSend() 'appid' => 'mock-app-id', 'signature' => 'mock-app-key', 'to' => new PhoneNumber(18188888888), - 'content' => '【easysms】 mock-app-content' + 'content' => '【easysms】 mock-app-content', ])->andReturn([ 'status' => 'success', 'send_id' => '093c0a7df143c087d6cba9cdf0cf3738', diff --git a/tests/Gateways/TinreeGatewayTest.php b/tests/Gateways/TinreeGatewayTest.php index a92d223..73e70b2 100644 --- a/tests/Gateways/TinreeGatewayTest.php +++ b/tests/Gateways/TinreeGatewayTest.php @@ -11,12 +11,12 @@ namespace Overtrue\EasySms\Tests\Gateways; +use Overtrue\EasySms\Exceptions\GatewayErrorException; +use Overtrue\EasySms\Gateways\TinreeGateway; use Overtrue\EasySms\Message; use Overtrue\EasySms\PhoneNumber; use Overtrue\EasySms\Support\Config; use Overtrue\EasySms\Tests\TestCase; -use Overtrue\EasySms\Gateways\TinreeGateway; -use Overtrue\EasySms\Exceptions\GatewayErrorException; class TinreeGatewayTest extends TestCase { @@ -28,7 +28,7 @@ public function testSend() 'sign' => 'mock-sign', ]; - $gateway = \Mockery::mock(TinreeGateway::class . '[post]', [$config])->shouldAllowMockingProtectedMethods(); + $gateway = \Mockery::mock(TinreeGateway::class.'[post]', [$config])->shouldAllowMockingProtectedMethods(); $params = [ 'accesskey' => $config['accesskey'], @@ -44,11 +44,11 @@ public function testSend() ->andReturn([ 'code' => '0', 'msg' => 'SUCCESS', - 'smUuid' => 'xxx' + 'smUuid' => 'xxx', ], [ 'code' => '9006', 'msg' => ' 用户accesskey不正确', - 'smUuid' => '' + 'smUuid' => '', ])->twice(); $message = new Message(['data' => ['1234', 5], 'template' => '123456']); @@ -57,7 +57,7 @@ public function testSend() [ 'code' => '0', 'msg' => 'SUCCESS', - 'smUuid' => 'xxx' + 'smUuid' => 'xxx', ], $gateway->send(new PhoneNumber(18888888888), $message, $config) ); diff --git a/tests/Gateways/UcloudGatewayTest.php b/tests/Gateways/UcloudGatewayTest.php index 2c00e81..361c3e0 100644 --- a/tests/Gateways/UcloudGatewayTest.php +++ b/tests/Gateways/UcloudGatewayTest.php @@ -11,10 +11,8 @@ namespace Overtrue\EasySms\Tests\Gateways; -use Overtrue\EasySms\EasySms; use Overtrue\EasySms\Exceptions\GatewayErrorException; use Overtrue\EasySms\Gateways\UcloudGateway; -use Overtrue\EasySms\Gateways\YunxinGateway; use Overtrue\EasySms\Message; use Overtrue\EasySms\PhoneNumber; use Overtrue\EasySms\Support\Config; @@ -28,10 +26,10 @@ class UcloudGatewayTest extends TestCase public function testSend() { $config = [ - 'private_key' => '', //私钥 - 'public_key' => '', //公钥 - 'sig_content' => '', //签名 - 'project_id' => '', //默认不填,子账号才需要填 + 'private_key' => '', // 私钥 + 'public_key' => '', // 公钥 + 'sig_content' => '', // 签名 + 'project_id' => '', // 默认不填,子账号才需要填 ]; $gateway = \Mockery::mock(UcloudGateway::class.'[request]', [$config])->shouldAllowMockingProtectedMethods(); @@ -56,7 +54,7 @@ public function testSend() 'template' => '', 'data' => [ 'code' => '', // 如果是多个参数可以用数组 - 'mobiles' => '', //同时发送多个手机也可以用数组来,[1111111,11111] + 'mobiles' => '', // 同时发送多个手机也可以用数组来,[1111111,11111] ], ]); $config = new Config($config); @@ -79,10 +77,10 @@ public function testSignContent() $dataSigContent = 'data_sig_content'; $config = [ - 'private_key' => '', //私钥 - 'public_key' => '', //公钥 - 'sig_content' => $defaultSigContent, //签名 - 'project_id' => '', //默认不填,子账号才需要填 + 'private_key' => '', // 私钥 + 'public_key' => '', // 公钥 + 'sig_content' => $defaultSigContent, // 签名 + 'project_id' => '', // 默认不填,子账号才需要填 ]; $gateway = \Mockery::mock(UcloudGateway::class.'[request]', [$config])->shouldAllowMockingProtectedMethods(); @@ -107,8 +105,8 @@ public function testSignContent() 'template' => '', 'data' => [ 'code' => '', // 如果是多个参数可以用数组 - 'mobiles' => '', //同时发送多个手机也可以用数组来,[1111111,11111] - 'sig_content' => $dataSigContent + 'mobiles' => '', // 同时发送多个手机也可以用数组来,[1111111,11111] + 'sig_content' => $dataSigContent, ], ]); $config = new Config($config); diff --git a/tests/Gateways/Ue35GatewayTest.php b/tests/Gateways/Ue35GatewayTest.php index 4b08391..06d7e95 100644 --- a/tests/Gateways/Ue35GatewayTest.php +++ b/tests/Gateways/Ue35GatewayTest.php @@ -50,7 +50,7 @@ public function testSend() $config = new Config($config); $this->assertSame([ - 'errorcode' => Ue35Gateway::SUCCESS_CODE, + 'errorcode' => Ue35Gateway::SUCCESS_CODE, ], $gateway->send(new PhoneNumber(18188888888), $message, $config)); $this->expectException(GatewayErrorException::class); diff --git a/tests/Gateways/VolcengineGatewayTest.php b/tests/Gateways/VolcengineGatewayTest.php index 19fbc72..e0403fd 100644 --- a/tests/Gateways/VolcengineGatewayTest.php +++ b/tests/Gateways/VolcengineGatewayTest.php @@ -43,10 +43,9 @@ public function testSend() 'Sign' => $config['sign_name'], 'TemplateID' => $templateId, 'TemplateParam' => json_encode($templateParam), - 'PhoneNumbers' => $phone + 'PhoneNumbers' => $phone, ]; - $successReturn = [ 'ResponseMetadata' => [ 'RequestId' => 'mock_request_id', @@ -56,8 +55,8 @@ public function testSend() 'Region' => VolcengineGateway::ENDPOINT_DEFAULT_REGION_ID, ], 'Result' => [ - "MessageID" => ["mock_message_id"], - ] + 'MessageID' => ['mock_message_id'], + ], ]; $failedReturn = [ @@ -68,10 +67,10 @@ public function testSend() 'Service' => VolcengineGateway::ENDPOINT_SERVICE, 'Region' => VolcengineGateway::ENDPOINT_DEFAULT_REGION_ID, 'Error' => [ - 'Code' => str_repeat("ZJ", rand(1, 3)).rand(10000, 30000), + 'Code' => str_repeat('ZJ', rand(1, 3)).rand(10000, 30000), 'Message' => 'mock_error_message', ], - ] + ], ]; $gateway = \Mockery::mock(VolcengineGateway::class.'[request]', [$config])->shouldAllowMockingProtectedMethods(); diff --git a/tests/Gateways/YidongmasblackGatewayTest.php b/tests/Gateways/YidongmasblackGatewayTest.php index 46520be..e502616 100644 --- a/tests/Gateways/YidongmasblackGatewayTest.php +++ b/tests/Gateways/YidongmasblackGatewayTest.php @@ -29,16 +29,16 @@ public function testSend() 'sign' => 'mock-sign', 'addSerial' => 'mock-add-serial', ]; - $gateway = \Mockery::mock(YidongmasblackGateway::class . '[postJson]', [$config])->shouldAllowMockingProtectedMethods(); + $gateway = \Mockery::mock(YidongmasblackGateway::class.'[postJson]', [$config])->shouldAllowMockingProtectedMethods(); $expected = [ - 'ecName' => "mock-ec-name", - 'apId' => "mock-ap-id", - 'sign' => "mock-sign", - 'addSerial' => "mock-add-serial", + 'ecName' => 'mock-ec-name', + 'apId' => 'mock-ap-id', + 'sign' => 'mock-sign', + 'addSerial' => 'mock-add-serial', 'mobiles' => 18888888888, - 'content' => "123456", - 'mac' => "316769171b5b29b13e1fa0a5250ff5e2", + 'content' => '123456', + 'mac' => '316769171b5b29b13e1fa0a5250ff5e2', ]; $gateway->shouldReceive('postJson') ->with(YidongmasblackGateway::ENDPOINT_URL, \Mockery::on(function ($params) use ($expected) { diff --git a/tests/Gateways/YunpianGatewayTest.php b/tests/Gateways/YunpianGatewayTest.php index eea8cdc..567b882 100644 --- a/tests/Gateways/YunpianGatewayTest.php +++ b/tests/Gateways/YunpianGatewayTest.php @@ -37,8 +37,8 @@ public function testSend() ])->andReturn([ 'code' => 0, 'msg' => '发送成功', - 'count' => 1, //成功发送的短信计费条数 - 'fee' => 0.05, //扣费条数,70个字一条,超出70个字时按每67字一条计 + 'count' => 1, // 成功发送的短信计费条数 + 'fee' => 0.05, // 扣费条数,70个字一条,超出70个字时按每67字一条计 'unit' => 'RMB', // 计费单位 'mobile' => '18188888888', // 发送手机号 'sid' => 3310228982, // 短信ID @@ -52,8 +52,8 @@ public function testSend() $this->assertSame([ 'code' => 0, 'msg' => '发送成功', - 'count' => 1, //成功发送的短信计费条数 - 'fee' => 0.05, //扣费条数,70个字一条,超出70个字时按每67字一条计 + 'count' => 1, // 成功发送的短信计费条数 + 'fee' => 0.05, // 扣费条数,70个字一条,超出70个字时按每67字一条计 'unit' => 'RMB', // 计费单位 'mobile' => '18188888888', // 发送手机号 'sid' => 3310228982, // 短信ID @@ -75,8 +75,8 @@ public function testDefaultSignature() $response = [ 'code' => 0, 'msg' => '发送成功', - 'count' => 1, //成功发送的短信计费条数 - 'fee' => 0.05, //扣费条数,70个字一条,超出70个字时按每67字一条计 + 'count' => 1, // 成功发送的短信计费条数 + 'fee' => 0.05, // 扣费条数,70个字一条,超出70个字时按每67字一条计 'unit' => 'RMB', // 计费单位 'mobile' => '18188888888', // 发送手机号 'sid' => 3310228982, // 短信ID diff --git a/tests/Gateways/YuntongxunGatewayTest.php b/tests/Gateways/YuntongxunGatewayTest.php index 172b707..522b2e8 100644 --- a/tests/Gateways/YuntongxunGatewayTest.php +++ b/tests/Gateways/YuntongxunGatewayTest.php @@ -38,11 +38,11 @@ public function testSend() }), \Mockery::on(function ($params) { return $params['json'] == [ - 'to' => '18188888888', - 'templateId' => 5589, - 'appId' => 'mock-app-id', - 'datas' => ['mock-data-1', 'mock-data-2'], - ] && 'application/json' == $params['headers']['Accept'] + 'to' => '18188888888', + 'templateId' => 5589, + 'appId' => 'mock-app-id', + 'datas' => ['mock-data-1', 'mock-data-2'], + ] && 'application/json' == $params['headers']['Accept'] && 'application/json;charset=utf-8' == $params['headers']['Content-Type']; }) ) @@ -56,8 +56,8 @@ public function testSend() $config = new Config($config); $this->assertSame([ - 'statusCode' => YuntongxunGateway::SUCCESS_CODE, - ], $gateway->send(new PhoneNumber(18188888888), $message, $config)); + 'statusCode' => YuntongxunGateway::SUCCESS_CODE, + ], $gateway->send(new PhoneNumber(18188888888), $message, $config)); $this->expectException(GatewayErrorException::class); $this->expectExceptionCode(100); @@ -76,7 +76,7 @@ public function testSendIntl() 'account_token' => 'mock-account-token', 'app_id' => 'mock-app-id', ]; - $gateway = \Mockery::mock(YuntongxunGateway::class . '[request]', [$config])->shouldAllowMockingProtectedMethods(); + $gateway = \Mockery::mock(YuntongxunGateway::class.'[request]', [$config])->shouldAllowMockingProtectedMethods(); $gateway->shouldReceive('request')->with( 'post', diff --git a/tests/Gateways/ZzyunGatewayTest.php b/tests/Gateways/ZzyunGatewayTest.php index b4192bb..e2f1c8f 100644 --- a/tests/Gateways/ZzyunGatewayTest.php +++ b/tests/Gateways/ZzyunGatewayTest.php @@ -27,7 +27,7 @@ public function testSend() 'secret' => 'mock-secret', 'sign_name' => 'mock-sign_name', ]; - $gateway = \Mockery::mock(ZzyunGateway::class . '[request]', [$config])->shouldAllowMockingProtectedMethods(); + $gateway = \Mockery::mock(ZzyunGateway::class.'[request]', [$config])->shouldAllowMockingProtectedMethods(); $gateway->shouldReceive('request') ->andReturn( @@ -36,7 +36,7 @@ public function testSend() 'Data' => [ 'fee_count' => 1, 'send_count' => 1, - 'biz_id' => '20210317143532-gtqlupiamu' + 'biz_id' => '20210317143532-gtqlupiamu', ], 'Message' => '', ], @@ -61,7 +61,7 @@ public function testSend() 'Data' => [ 'fee_count' => 1, 'send_count' => 1, - 'biz_id' => '20210317143532-gtqlupiamu' + 'biz_id' => '20210317143532-gtqlupiamu', ], 'Message' => '', ], $gateway->send(new PhoneNumber(18888888888), $message, $config)); diff --git a/tests/TestCase.php b/tests/TestCase.php index cbdc411..a001e48 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -11,8 +11,6 @@ namespace Overtrue\EasySms\Tests; -use Mockery; - class TestCase extends \PHPUnit\Framework\TestCase { /** @@ -20,7 +18,7 @@ class TestCase extends \PHPUnit\Framework\TestCase */ public function registerMockery() { - Mockery::globalHelpers(); + \Mockery::globalHelpers(); } /** @@ -28,6 +26,6 @@ public function registerMockery() */ public function closeMockery() { - Mockery::close(); + \Mockery::close(); } }