forked from overtrue/easy-sms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 凯信通短信发送支持 1. 增加 gateway 2. 修改 readme * 样式修复 * Update KingttoGateway.php * Update KingttoGateway.php
- Loading branch information
1 parent
b3c16de
commit bf0a537
Showing
3 changed files
with
156 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/easy-sms. | ||
* | ||
* (c) overtrue <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Overtrue\EasySms\Gateways; | ||
|
||
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 KingttoGateWay. | ||
* | ||
* @see http://www.kingtto.cn/ | ||
*/ | ||
class KingttoGateway extends Gateway | ||
{ | ||
use HasHttpRequest; | ||
|
||
const ENDPOINT_URL = 'http://101.201.41.194:9999/sms.aspx'; | ||
|
||
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 = [ | ||
'action' => self::ENDPOINT_METHOD, | ||
'userid' => $config->get('userid'), | ||
'account' => $config->get('account'), | ||
'password' => $config->get('password'), | ||
'mobile' => $to->getNumber(), | ||
'content' => $message->getContent(), | ||
]; | ||
|
||
$result = $this->post(self::ENDPOINT_URL, $params); | ||
|
||
if ('Success' != $result['returnstatus']) { | ||
throw new GatewayErrorException($result['message'], $result['remainpoint'], $result); | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the overtrue/easy-sms. | ||
* | ||
* (c) overtrue <[email protected]> | ||
* | ||
* 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\KingttoGateway; | ||
use Overtrue\EasySms\Message; | ||
use Overtrue\EasySms\PhoneNumber; | ||
use Overtrue\EasySms\Support\Config; | ||
use Overtrue\EasySms\Tests\TestCase; | ||
|
||
class KingttoGatewayTest extends TestCase | ||
{ | ||
public function testSend() | ||
{ | ||
$config = [ | ||
'userid' => 'mock-id', | ||
'account' => 'mock-account', | ||
'password' => 'mock-password', | ||
]; | ||
|
||
$gateway = \Mockery::mock(KingttoGateway::class.'[post]', [$config])->shouldAllowMockingProtectedMethods(); | ||
|
||
$params = [ | ||
'action' => KingttoGateway::ENDPOINT_METHOD, | ||
'userid' => 'mock-id', | ||
'account' => 'mock-account', | ||
'password' => 'mock-password', | ||
'mobile' => '18888888888', | ||
'content' => '【molin】This is a test message.', | ||
]; | ||
|
||
$gateway->shouldReceive('post')->with(KingttoGateway::ENDPOINT_URL, $params) | ||
->andReturn([ | ||
'returnstatus' => 'Success', | ||
'message' => 'ok', | ||
'remainpoint' => '56832', | ||
'taskID' => '106470408', | ||
'successCounts' => '1', | ||
], [ | ||
'returnstatus' => 'Faild', | ||
'message' => 'mock-message', | ||
'remainpoint' => '0', | ||
'taskID' => '0', | ||
'successCounts' => '0', | ||
])->times(2); | ||
|
||
$this->assertSame([ | ||
'returnstatus' => 'Success', | ||
'message' => 'ok', | ||
'remainpoint' => '56832', | ||
'taskID' => '106470408', | ||
'successCounts' => '1', | ||
], $gateway->send(new PhoneNumber('18888888888'), new Message([ | ||
'content' => '【molin】This is a test message.', | ||
]), new Config($config))); | ||
|
||
$this->expectException(GatewayErrorException::class); | ||
$this->expectExceptionCode(0); | ||
$this->expectExceptionMessage('mock-message'); | ||
|
||
$gateway->send(new PhoneNumber('18888888888'), new Message([ | ||
'content' => '【molin】This is a test message.', | ||
]), new Config($config)); | ||
} | ||
} |