1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\GoSms; |
4
|
|
|
|
5
|
|
|
use Illuminate\Notifications\Notification; |
6
|
|
|
use NotificationChannels\GoSms\Exceptions\CouldNotSendNotification; |
7
|
|
|
|
8
|
|
|
class GoSmsChannel |
9
|
|
|
{ |
10
|
|
|
/** @var \NotificationChannels\GoSms\GoSmsApi */ |
11
|
|
|
protected $gosms; |
12
|
|
|
|
13
|
|
|
public function __construct(GoSmsApi $gosms) |
14
|
|
|
{ |
15
|
|
|
$this->gosms = $gosms; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Send the given notification. |
20
|
|
|
* |
21
|
|
|
* @param mixed $notifiable |
22
|
|
|
* @param \Illuminate\Notifications\Notification $notification |
23
|
|
|
* |
24
|
|
|
* @throws \NotificationChannels\GoSms\Exceptions\CouldNotSendNotification |
25
|
|
|
*/ |
26
|
|
|
public function send($notifiable, Notification $notification) |
27
|
|
|
{ |
28
|
|
|
$to = $notifiable->routeNotificationFor('gosms'); |
29
|
|
|
|
30
|
|
|
if (empty($to)) { |
31
|
|
|
throw CouldNotSendNotification::missingRecipient(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
$message = $notification->toGoSms($notifiable); |
|
|
|
|
35
|
|
|
|
36
|
|
|
if (is_string($message)) { |
37
|
|
|
$message = new GoSmsMessage($message); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$this->sendMessage($to, $message); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function sendMessage($recipient, GoSmsMessage $message) |
44
|
|
|
{ |
45
|
|
|
$message->content = html_entity_decode($message->content, ENT_QUOTES, 'utf-8'); |
46
|
|
|
$message->content = urlencode($message->content); |
47
|
|
|
|
48
|
|
|
//the sms format must start with 6 |
49
|
|
|
$valid_mobile = ''; |
50
|
|
|
|
51
|
|
|
if ($recipient[0] == '6') { |
52
|
|
|
$valid_mobile = $recipient; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
if ($recipient[0] == '0') { |
56
|
|
|
$valid_mobile = '6'.$recipient; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if ($recipient[0] == '+') { |
60
|
|
|
$valid_mobile = substr($recipient, 1); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$params = [ |
64
|
|
|
'hp' => $valid_mobile, |
65
|
|
|
'mesg' => $message->content, |
66
|
|
|
'sender' => $message->from, |
67
|
|
|
]; |
68
|
|
|
|
69
|
|
|
if ($message->sendAt instanceof \DateTimeInterface) { |
70
|
|
|
$params['time'] = '0'.$message->sendAt->getTimestamp(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$this->gosms->send($params); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.