diff --git a/README.md b/README.md index 5a50cf5..052ca09 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ - [蜘蛛云](https://zzyun.com/) - [融合云信](https://maap.wo.cn/) - [天瑞云](http://cms.tinree.com/) +- [时代互联](https://www.now.cn/) - [火山引擎](https://console.volcengine.com/sms/) ## 环境需求 @@ -925,6 +926,25 @@ $easySms->send(18888888888, [ ]); ``` +### [时代互联](https://www.now.cn/) + +短信使用 `content` + +```php + 'nowcn' => [ + 'key' => '', //用户ID + 'secret' => '', //开发密钥 + 'api_type' => '', // 短信通道, + ], +``` + +发送示例: +```php +$easySms->send(18888888888, [ + 'content' => '您的验证码为: 6379', +]); +``` + ### [火山引擎](https://console.volcengine.com/sms/) 短信内容使用 `template` + `data` diff --git a/src/Gateways/NowcnGateway.php b/src/Gateways/NowcnGateway.php new file mode 100644 index 0000000..f138675 --- /dev/null +++ b/src/Gateways/NowcnGateway.php @@ -0,0 +1,34 @@ + $to->getNumber(), + 'content' => $message->getContent($this), + 'userId' => $config->get('key'), + 'password' => $config->get('secret'), + 'apiType' => $config->get('api_type'), + ]; + $result = $this->get(self::ENDPOINT_URL, $params); + if (self::SUCCESS_CODE != $result['code']) { + throw new GatewayErrorException($result['msg'], $result['code'], $result); + } + return $result; + } +} \ No newline at end of file diff --git a/tests/Gateways/NowcnGatewaysTest.php b/tests/Gateways/NowcnGatewaysTest.php new file mode 100644 index 0000000..7f20809 --- /dev/null +++ b/tests/Gateways/NowcnGatewaysTest.php @@ -0,0 +1,52 @@ + '1', + 'secret' => '1', + 'api_type' => '3', + ]; + + $gateway = \Mockery::mock(NowcnGateway::class . '[request]', [$config])->shouldAllowMockingProtectedMethods(); + $gateway->shouldReceive('request')->with( + 'get', + \Mockery::on(function ($api) { + return 0 === strpos($api, NowcnGateway::ENDPOINT_URL); + }), + \Mockery::on(function ($params) { + return true; + }) + ) ->andReturn([ + 'code' => NowcnGateway::SUCCESS_CODE, + ], [ + 'code' => "-4", + 'msg' => 'authorize failed', + ])->times(2); + + $message = new Message([ + 'content' => 'mock-content', + ]); + $config = new Config($config); + $this->assertSame([ + 'code' => NowcnGateway::SUCCESS_CODE, + ], $gateway->send(new PhoneNumber(18888888888), $message, $config)); + + $this->expectException(GatewayErrorException::class); + $this->expectExceptionCode(-4); + $this->expectExceptionMessage('authorize failed'); + $gateway->send(new PhoneNumber(18888888888), $message, $config); + + } +} \ No newline at end of file