1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the overtrue/easy-sms. |
5
|
|
|
* |
6
|
|
|
* (c) overtrue <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Overtrue\EasySms\Gateways; |
13
|
|
|
|
14
|
|
|
use Overtrue\EasySms\Contracts\MessageInterface; |
15
|
|
|
use Overtrue\EasySms\Contracts\PhoneNumberInterface; |
16
|
|
|
use Overtrue\EasySms\Exceptions\GatewayErrorException; |
17
|
|
|
use Overtrue\EasySms\Support\Config; |
18
|
|
|
use Overtrue\EasySms\Traits\HasHttpRequest; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class KingttoGateWay. |
22
|
|
|
* |
23
|
|
|
* @see http://www.kingtto.cn/ |
24
|
|
|
*/ |
25
|
|
|
class KingttoGateway extends Gateway |
26
|
|
|
{ |
27
|
|
|
use HasHttpRequest; |
28
|
|
|
|
29
|
|
|
const ENDPOINT_URL = 'http://101.201.41.194:9999/sms.aspx'; |
30
|
|
|
|
31
|
|
|
const ENDPOINT_METHOD = 'send'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param PhoneNumberInterface $to |
35
|
|
|
* @param MessageInterface $message |
36
|
|
|
* @param Config $config |
37
|
|
|
* |
38
|
|
|
* @return \Psr\Http\Message\ResponseInterface|array|string |
39
|
|
|
* |
40
|
|
|
* @throws GatewayErrorException |
41
|
|
|
*/ |
42
|
|
|
public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config) |
43
|
|
|
{ |
44
|
|
|
$params = [ |
45
|
|
|
'action' => self::ENDPOINT_METHOD, |
46
|
|
|
'userid' => $config->get('userid'), |
47
|
|
|
'account' => $config->get('account'), |
48
|
|
|
'password' => $config->get('password'), |
49
|
|
|
'mobile' => $to->getNumber(), |
50
|
|
|
'content' => $message->getContent(), |
51
|
|
|
]; |
52
|
|
|
|
53
|
|
|
$result = $this->post(self::ENDPOINT_URL, $params); |
54
|
|
|
|
55
|
|
|
if ('Success' != $result['returnstatus']) { |
56
|
|
|
throw new GatewayErrorException($result['message'], $result['remainpoint'], $result); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $result; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|