|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of ibrand/laravel-sms. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) iBrand <https://www.ibrand.cc> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace iBrand\Sms\Messages; |
|
13
|
|
|
|
|
14
|
|
|
use Overtrue\EasySms\Contracts\GatewayInterface; |
|
15
|
|
|
use Overtrue\EasySms\Message; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class CodeMessage. |
|
19
|
|
|
*/ |
|
20
|
|
|
class CodeMessage extends Message |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $code; |
|
26
|
|
|
/** |
|
27
|
|
|
* @var |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $minutes; |
|
30
|
|
|
|
|
31
|
|
|
protected $data; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* CodeMessage constructor. |
|
35
|
|
|
* |
|
36
|
|
|
* @param $code |
|
37
|
|
|
* @param $minutes |
|
38
|
|
|
*/ |
|
39
|
26 |
|
public function __construct($code, $minutes, array $data = []) |
|
40
|
|
|
{ |
|
41
|
26 |
|
$this->code = $code; |
|
42
|
26 |
|
$this->minutes = $minutes; |
|
43
|
26 |
|
$this->data = $data; |
|
44
|
26 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* 定义直接使用内容发送平台的内容. |
|
48
|
|
|
* |
|
49
|
|
|
* @param GatewayInterface|null $gateway |
|
50
|
|
|
* |
|
51
|
|
|
* @return string |
|
52
|
|
|
*/ |
|
53
|
22 |
|
public function getContent(GatewayInterface $gateway = null) |
|
54
|
|
|
{ |
|
55
|
22 |
|
if (!empty($this->data) && isset($this->data['content'])) { |
|
56
|
4 |
|
$content = $this->data['content']; |
|
57
|
|
|
} else { |
|
58
|
18 |
|
$content = config('ibrand.sms.content'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
22 |
|
return vsprintf($content, [$this->code, $this->minutes]); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* 定义使用模板发送方式平台所需要的模板 ID. |
|
66
|
|
|
* |
|
67
|
|
|
* @param GatewayInterface|null $gateway |
|
68
|
|
|
* |
|
69
|
|
|
* @return mixed |
|
70
|
|
|
*/ |
|
71
|
22 |
|
public function getTemplate(GatewayInterface $gateway = null) |
|
72
|
|
|
{ |
|
73
|
22 |
|
$classname = get_class($gateway); |
|
74
|
|
|
|
|
75
|
22 |
|
if ($pos = strrpos($classname, '\\')) { |
|
76
|
22 |
|
$classname = substr($classname, $pos + 1); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
22 |
|
if ($classname) { |
|
80
|
22 |
|
$classname = strtolower(str_replace('Gateway', '', $classname)); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
22 |
|
if (!empty($this->data) && isset($this->data['template'])) { |
|
84
|
4 |
|
return $this->data['template']; |
|
85
|
|
|
} else { |
|
86
|
18 |
|
return config('ibrand.sms.easy_sms.gateways.' . $classname . '.code_template_id'); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param GatewayInterface|null $gateway |
|
92
|
|
|
* |
|
93
|
|
|
* @return array |
|
94
|
|
|
*/ |
|
95
|
22 |
|
public function getData(GatewayInterface $gateway = null) |
|
96
|
|
|
{ |
|
97
|
22 |
|
if (!empty($this->data) && isset($this->data['data']) && is_array($this->data['data'])) { |
|
98
|
4 |
|
$data = $this->data['data']; |
|
99
|
|
|
} else { |
|
100
|
18 |
|
$data = array_filter(config('ibrand.sms.data')); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
22 |
|
return array_merge($data, ['code' => $this->code]); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|