1 | <?php |
||
5 | abstract class Agent |
||
6 | { |
||
7 | const SUCCESS = 'success'; |
||
8 | const INFO = 'info'; |
||
9 | const CODE = 'code'; |
||
10 | |||
11 | /** |
||
12 | * The configuration information. |
||
13 | * |
||
14 | * @var array |
||
15 | */ |
||
16 | protected $config = []; |
||
17 | |||
18 | /** |
||
19 | * The result data. |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $result = [ |
||
24 | self::SUCCESS => false, |
||
25 | self::INFO => null, |
||
26 | self::CODE => 0, |
||
27 | ]; |
||
28 | |||
29 | /** |
||
30 | * Constructor. |
||
31 | * |
||
32 | * @param array $config |
||
33 | */ |
||
34 | 30 | public function __construct(array $config = []) |
|
35 | { |
||
36 | 30 | $this->config($config); |
|
37 | 30 | } |
|
38 | |||
39 | /** |
||
40 | * Get or set the configuration information of agent. |
||
41 | * |
||
42 | * @param mixed $key |
||
43 | * @param mixed $value |
||
44 | * @param bool $override |
||
45 | * |
||
46 | * @return mixed |
||
47 | */ |
||
48 | 30 | public function config($key = null, $value = null, $override = false) |
|
49 | { |
||
50 | 30 | if (is_array($key) && is_bool($value)) { |
|
51 | 3 | $override = $value; |
|
52 | 3 | } |
|
53 | |||
54 | 30 | return Util::operateArray($this->config, $key, $value, null, null, $override); |
|
55 | } |
||
56 | |||
57 | /** |
||
58 | * SMS send process. |
||
59 | * |
||
60 | * @param $to |
||
61 | * @param $content |
||
62 | * @param $tempId |
||
63 | * @param array $tempData |
||
64 | */ |
||
65 | abstract public function sendSms($to, $content, $tempId, array $tempData); |
||
66 | |||
67 | /** |
||
68 | * Content SMS send process. |
||
69 | * |
||
70 | * @param $to |
||
71 | * @param $content |
||
72 | */ |
||
73 | abstract public function sendContentSms($to, $content); |
||
74 | |||
75 | /** |
||
76 | * Template SMS send process. |
||
77 | * |
||
78 | * @param $to |
||
79 | * @param $tempId |
||
80 | * @param array $tempData |
||
81 | */ |
||
82 | abstract public function sendTemplateSms($to, $tempId, array $tempData); |
||
83 | |||
84 | /** |
||
85 | * Voice verify send process. |
||
86 | * |
||
87 | * @param $to |
||
88 | * @param $code |
||
89 | * @param $tempId |
||
90 | * @param array $tempData |
||
91 | */ |
||
92 | abstract public function voiceVerify($to, $code, $tempId, array $tempData); |
||
93 | |||
94 | /** |
||
95 | * cURl |
||
96 | * |
||
97 | * @codeCoverageIgnore |
||
98 | * |
||
99 | * @param string $url [请求的URL地址] |
||
100 | * @param array $params [请求的参数] |
||
101 | * @param bool $post [是否采用POST形式] |
||
102 | * @param array $opts [curl设置项] |
||
103 | * |
||
104 | * @return array ['request', 'response'] |
||
105 | * request:是否请求成功 |
||
106 | * response:响应数据 |
||
107 | */ |
||
108 | public static function curl($url, $params = [], $post = false, array $opts = []) |
||
148 | |||
149 | /** |
||
150 | * Get or set the result data. |
||
151 | * |
||
152 | * @param $name |
||
153 | * @param $value |
||
154 | * |
||
155 | * @return mixed |
||
156 | */ |
||
157 | 36 | public function result($name = null, $value = null) |
|
169 | |||
170 | /** |
||
171 | * Overload object properties. |
||
172 | * |
||
173 | * @param $name |
||
174 | * |
||
175 | * @return mixed |
||
176 | */ |
||
177 | 12 | public function __get($name) |
|
181 | |||
182 | /** |
||
183 | * When using isset() or empty() on inaccessible object properties, |
||
184 | * the __isset() overloading method will be called. |
||
185 | * |
||
186 | * @param $name |
||
187 | * |
||
188 | * @return bool |
||
189 | */ |
||
190 | 3 | public function __isset($name) |
|
194 | } |
||
195 |