1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Toplan\PhpSms; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class SubMailAgent |
7
|
|
|
* |
8
|
|
|
* @property string $appid |
9
|
|
|
* @property string $signature |
10
|
|
|
*/ |
11
|
|
|
class SubMailAgent extends Agent implements TemplateSms |
12
|
|
|
{ |
13
|
|
|
public function sendSms($to, $content, $tempId, array $data) |
14
|
|
|
{ |
15
|
|
|
$this->sendTemplateSms($to, $tempId, $data); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
View Code Duplication |
public function sendTemplateSms($to, $tempId, array $data) |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
$url = 'https://api.mysubmail.com/message/xsend.json'; |
21
|
|
|
$params = [ |
22
|
|
|
'appid' => $this->appid, |
23
|
|
|
'project' => $tempId, |
24
|
|
|
'to' => $to, |
25
|
|
|
'signature' => $this->signature, |
26
|
|
|
'vars' => json_encode($data), |
27
|
|
|
]; |
28
|
|
|
$result = $this->curl($url, $params, true); |
29
|
|
|
$this->setResult($result); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
View Code Duplication |
public function voiceVerify($to, $code, $tempId, array $data) |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
$url = 'https://api.mysubmail.com/voice/verify.json'; |
35
|
|
|
$params = [ |
36
|
|
|
'appid' => $this->appid, |
37
|
|
|
'to' => $to, |
38
|
|
|
'code' => $code, |
39
|
|
|
'signature' => $this->signature, |
40
|
|
|
]; |
41
|
|
|
$result = $this->curl($url, $params, true); |
42
|
|
|
$this->setResult($result); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
protected function setResult($result) |
46
|
|
|
{ |
47
|
|
|
if ($result['request']) { |
48
|
|
|
$this->result(Agent::INFO, $result['response']); |
49
|
|
|
$result = json_decode($result['response'], true); |
50
|
|
|
if ($result['status'] === 'success') { |
51
|
|
|
$this->result(Agent::SUCCESS, true); |
52
|
|
|
} else { |
53
|
|
|
$this->result(Agent::INFO, $result['msg']); |
54
|
|
|
$this->result(Agent::CODE, $result['code']); |
55
|
|
|
} |
56
|
|
|
} else { |
57
|
|
|
$this->result(Agent::INFO, 'request failed'); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.