From 81d4deec69bbb6de6e5fdd7ab90cc933bd3e3046 Mon Sep 17 00:00:00 2001 From: suguer <1980841508@qq.com> Date: Mon, 7 Aug 2023 15:51:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0:=20=E6=97=B6=E4=BB=A3?= =?UTF-8?q?=E4=BA=92=E8=81=94=E7=9A=84=E7=9F=AD=E4=BF=A1=E7=BD=91=E5=85=B3?= =?UTF-8?q?API=20https://www.now.cn=20(#347)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add: 时代互联的短信网关API https://www.now.cn * ### 补充时代互联文档说明 --------- Co-authored-by: dsuzejian Co-authored-by: 安正超 --- README.md | 20 +++++++++++ src/Gateways/NowcnGateway.php | 34 ++++++++++++++++++ tests/Gateways/NowcnGatewaysTest.php | 52 ++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 src/Gateways/NowcnGateway.php create mode 100644 tests/Gateways/NowcnGatewaysTest.php 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