|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Zing\LaravelSms\Gateways; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Arr; |
|
6
|
|
|
use Overtrue\EasySms\Contracts\MessageInterface; |
|
7
|
|
|
use Overtrue\EasySms\Contracts\PhoneNumberInterface; |
|
8
|
|
|
use Overtrue\EasySms\Gateways\Gateway; |
|
9
|
|
|
use Overtrue\EasySms\Support\Config; |
|
10
|
|
|
use Overtrue\EasySms\Traits\HasHttpRequest; |
|
11
|
|
|
use Zing\LaravelSms\Exceptions\CouldNotSendNotification; |
|
12
|
|
|
|
|
13
|
|
|
class MeilianGateway extends Gateway |
|
14
|
|
|
{ |
|
15
|
|
|
use HasHttpRequest; |
|
16
|
|
|
|
|
17
|
|
|
public const ENDPOINT_URL = 'http://m.5c.com.cn/api/send/index.php'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $number |
|
21
|
|
|
* @param \Overtrue\EasySms\Contracts\MessageInterface $message |
|
22
|
|
|
* @param \Overtrue\EasySms\Support\Config $config |
|
23
|
|
|
* |
|
24
|
|
|
* @return string |
|
25
|
|
|
* |
|
26
|
|
|
* @throws \Zing\LaravelSms\Exceptions\CouldNotSendNotification |
|
27
|
|
|
*/ |
|
28
|
4 |
|
public function send(PhoneNumberInterface $number, MessageInterface $message, Config $config) |
|
29
|
|
|
{ |
|
30
|
4 |
|
$endpoint = self::ENDPOINT_URL; |
|
31
|
|
|
|
|
32
|
4 |
|
$signature = $this->config->get('signature', ''); |
|
33
|
|
|
|
|
34
|
4 |
|
$content = $message->getContent($this); |
|
35
|
4 |
|
$result = $this->post( |
|
36
|
4 |
|
$endpoint, |
|
37
|
|
|
[ |
|
38
|
4 |
|
'username' => $this->config->get('username'), |
|
39
|
4 |
|
'password' => $this->config->get('password'), |
|
40
|
4 |
|
'apikey' => $this->config->get('api_key'), |
|
41
|
4 |
|
'mobile' => $number->getUniversalNumber(), |
|
42
|
4 |
|
'content' => strpos($content, '【') === 0 ? $content : $signature . $content, |
|
43
|
|
|
] |
|
44
|
|
|
); |
|
45
|
4 |
|
if (! is_string($result)) { |
|
|
|
|
|
|
46
|
1 |
|
throw new CouldNotSendNotification('meilian response does only seem to accept string.'); |
|
47
|
|
|
} |
|
48
|
3 |
|
if (strpos($result, 'error') !== false) { |
|
49
|
1 |
|
throw new CouldNotSendNotification($result, 1, Arr::wrap($result)); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
3 |
|
return $result; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|