From 77f4fc4e37a724ef9994b73fac655b1b1381e437 Mon Sep 17 00:00:00 2001 From: Qazink Date: Thu, 17 Jul 2025 10:26:26 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20=E5=BE=AE=E8=B6=A3?= =?UTF-8?q?=E4=BA=91=20=E7=9F=AD=E4=BF=A1=E5=8F=91=E9=80=81=E6=B8=A0?= =?UTF-8?q?=E9=81=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + src/Gateways/WeiqucloudGateway.php | 38 ++++++++++++++ tests/Gateways/WeiqucloudGatewayTest.php | 63 ++++++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 src/Gateways/WeiqucloudGateway.php create mode 100644 tests/Gateways/WeiqucloudGatewayTest.php diff --git a/README.md b/README.md index c9650ed..1ee14f0 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ - [火山引擎](https://console.volcengine.com/sms/) - [移动云MAS(黑名单模式)](https://mas.10086.cn) - [电信天翼云](https://www.ctyun.cn/document/10020426/10021544) +- [微趣云](https://sms.weiqucloud.com/) ## 环境需求 diff --git a/src/Gateways/WeiqucloudGateway.php b/src/Gateways/WeiqucloudGateway.php new file mode 100644 index 0000000..44dc277 --- /dev/null +++ b/src/Gateways/WeiqucloudGateway.php @@ -0,0 +1,38 @@ + $config->get('userId'), + "account" => $config->get('account'), + "password" => $config->get('password'), + "mobile" => $to->getNumber(), + "content" => $message->getContent($this), + "sendTime" => "", + "action" => "sendhy", + ]; + $result = $this->postJson(self::ENDPOINT_URL, $data); + if ($result < 0) { + throw new GatewayErrorException('短信发送失败', $result, []); + } + return $result; + } + +} diff --git a/tests/Gateways/WeiqucloudGatewayTest.php b/tests/Gateways/WeiqucloudGatewayTest.php new file mode 100644 index 0000000..0e83316 --- /dev/null +++ b/tests/Gateways/WeiqucloudGatewayTest.php @@ -0,0 +1,63 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Overtrue\EasySms\Tests\Gateways; + +use Overtrue\EasySms\Exceptions\GatewayErrorException; +use Overtrue\EasySms\Gateways\WeiqucloudGateway; +use Overtrue\EasySms\Message; +use Overtrue\EasySms\PhoneNumber; +use Overtrue\EasySms\Support\Config; +use Overtrue\EasySms\Tests\TestCase; + +class WeiqucloudGatewayTest extends TestCase +{ + public function testSend() + { + $config = [ + 'userId' => 'mock-user-id', + 'account' => 'mock-account', + 'password' => 'mock-password', + ]; + $gateway = \Mockery::mock(WeiqucloudGateway::class.'[postJson]', [$config])->shouldAllowMockingProtectedMethods(); + + $expected = [ + 'userId' => 'mock-user-id', + 'account' => 'mock-account', + 'password' => 'mock-password', + 'mobile' => '18188888888', + 'content' => 'This is a test message.', + 'sendTime' => '', + 'action' => 'sendhy', + ]; + + $gateway->shouldReceive('postJson') + ->with(WeiqucloudGateway::ENDPOINT_URL, $expected) + ->andReturn( + 1, // 成功返回正数 + -1 // 失败返回负数 + ) + ->twice(); + + $message = new Message(['content' => 'This is a test message.']); + $config = new Config($config); + + // 测试成功发送 + $this->assertSame(1, $gateway->send(new PhoneNumber(18188888888), $message, $config)); + + // 测试发送失败抛出异常 + $this->expectException(GatewayErrorException::class); + $this->expectExceptionCode(-1); + $this->expectExceptionMessage('短信发送失败'); + + $gateway->send(new PhoneNumber(18188888888), $message, $config); + } +} \ No newline at end of file From 46469ac6744dfe9fa45fe4468c29f79f9ad62989 Mon Sep 17 00:00:00 2001 From: Qazink Date: Thu, 17 Jul 2025 14:25:42 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=20=E5=AE=8C=E5=96=84=20=E5=BE=AE=E8=B6=A3?= =?UTF-8?q?=E4=BA=91=20=E6=B8=A0=E9=81=93=E4=BD=BF=E7=94=A8=E8=AF=B4?= =?UTF-8?q?=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 1ee14f0..c99f1ea 100644 --- a/README.md +++ b/README.md @@ -1039,6 +1039,26 @@ $easySms->send(18888888888, [ ]); ``` +### [微趣云](https://sms.weiqucloud.com/) + +短信使用 `content` + +```php + 'weiqucloud' => [ + 'userId' => '', // 服务商会提供 + 'account' => '', //服务商会提供 + 'password' => '', // 服务商会提供, + ], +``` + +发送示例: + +```php +$easySms->send(18888888888, [ + 'content' =>"【已备案签名】您的验证码是 xx。", +]); +``` + ## :heart: 支持我 [![Sponsor me](https://github.com/overtrue/overtrue/blob/master/sponsor-me.svg?raw=true)](https://github.com/sponsors/overtrue) From ced38478e949108723acef83e8257e22658c2b52 Mon Sep 17 00:00:00 2001 From: Qazink Date: Thu, 17 Jul 2025 15:54:59 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=20=E5=AE=8C=E5=96=84=20=E5=BE=AE=E8=B6=A3?= =?UTF-8?q?=E4=BA=91=20=E6=B8=A0=E9=81=93=E4=BD=BF=E7=94=A8=E8=AF=B4?= =?UTF-8?q?=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Gateways/WeiqucloudGateway.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Gateways/WeiqucloudGateway.php b/src/Gateways/WeiqucloudGateway.php index 44dc277..3746fbc 100644 --- a/src/Gateways/WeiqucloudGateway.php +++ b/src/Gateways/WeiqucloudGateway.php @@ -29,10 +29,9 @@ public function send(PhoneNumberInterface $to, MessageInterface $message, Config "action" => "sendhy", ]; $result = $this->postJson(self::ENDPOINT_URL, $data); - if ($result < 0) { - throw new GatewayErrorException('短信发送失败', $result, []); + if ($result['code'] === 200 && $result['data']['status'] === 'Success') { + return $result; } - return $result; + throw new GatewayErrorException("短信发送失败: {$result['data']['message']}, remainPoint: {$result['data']['remainPoint']}, taskID:{$result['data']['taskID']}", 500, $result); } - } From a35bb571ce89291ebb4c7050467aa88550f452a3 Mon Sep 17 00:00:00 2001 From: Qazink Date: Thu, 17 Jul 2025 16:07:04 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=AE=8C=E5=96=84=20=E5=BE=AE=E8=B6=A3?= =?UTF-8?q?=E4=BA=91=20=E6=B8=A0=E9=81=93=E5=8F=91=E9=80=81=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Gateways/WeiqucloudGatewayTest.php | 34 +++++++++++++++++++----- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/tests/Gateways/WeiqucloudGatewayTest.php b/tests/Gateways/WeiqucloudGatewayTest.php index 0e83316..501eaf3 100644 --- a/tests/Gateways/WeiqucloudGatewayTest.php +++ b/tests/Gateways/WeiqucloudGatewayTest.php @@ -39,24 +39,44 @@ public function testSend() 'action' => 'sendhy', ]; + // 成功响应的数据结构 + $successResponse = [ + 'code' => 200, + 'data' => [ + 'status' => 'Success', + 'taskID' => 'mock-task-id', + 'remainPoint' => 100, + 'message' => '发送成功' + ] + ]; + + // 失败响应的数据结构 + $failureResponse = [ + 'code' => 500, + 'data' => [ + 'status' => 'Failed', + 'message' => '账户余额不足', + 'remainPoint' => 0, + 'taskID' => 'mock-task-id-failed' + ] + ]; + $gateway->shouldReceive('postJson') ->with(WeiqucloudGateway::ENDPOINT_URL, $expected) - ->andReturn( - 1, // 成功返回正数 - -1 // 失败返回负数 - ) + ->andReturn($successResponse, $failureResponse) ->twice(); $message = new Message(['content' => 'This is a test message.']); $config = new Config($config); // 测试成功发送 - $this->assertSame(1, $gateway->send(new PhoneNumber(18188888888), $message, $config)); + $result = $gateway->send(new PhoneNumber(18188888888), $message, $config); + $this->assertSame($successResponse, $result); // 测试发送失败抛出异常 $this->expectException(GatewayErrorException::class); - $this->expectExceptionCode(-1); - $this->expectExceptionMessage('短信发送失败'); + $this->expectExceptionCode(500); + $this->expectExceptionMessage('短信发送失败: 账户余额不足, remainPoint: 0, taskID:mock-task-id-failed'); $gateway->send(new PhoneNumber(18188888888), $message, $config); }