1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Toplan\PhpSms; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class SmsBaoAgent |
7
|
|
|
* |
8
|
|
|
* @property string $username |
9
|
|
|
* @property string $password |
10
|
|
|
*/ |
11
|
|
|
class SmsBaoAgent extends Agent implements ContentSms |
12
|
|
|
{ |
13
|
|
|
protected $resultArr = [ |
14
|
|
|
'0' => '发送成功', |
15
|
|
|
'-1' => '参数不全', |
16
|
|
|
'30' => '密码错误', |
17
|
|
|
'40' => '账号不存在', |
18
|
|
|
'41' => '余额不足', |
19
|
|
|
'42' => '帐户已过期', |
20
|
|
|
'43' => 'IP地址限制', |
21
|
|
|
'50' => '内容含有敏感词', |
22
|
|
|
'51' => '手机号码不正确', |
23
|
|
|
]; |
24
|
|
|
|
25
|
|
|
public function sendSms($to, $content, $tempId, array $data) |
26
|
|
|
{ |
27
|
|
|
$this->sendContentSms($to, $content); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
View Code Duplication |
public function sendContentSms($to, $content) |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
$url = 'http://api.smsbao.com/sms'; |
33
|
|
|
$params = [ |
34
|
|
|
'u' => $this->username, |
35
|
|
|
'p' => md5($this->password), |
36
|
|
|
'm' => $to, |
37
|
|
|
'c' => $content, |
38
|
|
|
]; |
39
|
|
|
$result = $this->curl($url, $params); |
40
|
|
|
$this->setResult($result); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
View Code Duplication |
public function voiceVerify($to, $code, $tempId, array $tempData) |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
$url = 'http://api.smsbao.com/voice'; |
46
|
|
|
$params = [ |
47
|
|
|
'u' => $this->username, |
48
|
|
|
'p' => md5($this->password), |
49
|
|
|
'm' => $to, |
50
|
|
|
'c' => $code, |
51
|
|
|
]; |
52
|
|
|
$result = $this->curl($url, $params); |
53
|
|
|
$this->setResult($result); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
protected function setResult($result) |
57
|
|
|
{ |
58
|
|
|
if ($result['request']) { |
59
|
|
|
$result = $result['response']; |
60
|
|
|
$msg = array_key_exists($result, $this->resultArr) ? $this->resultArr[$result] : 'unknown error'; |
61
|
|
|
$this->result(Agent::INFO, json_encode(['code' => $result, 'msg' => $msg])); |
62
|
|
|
$this->result(Agent::SUCCESS, $result === '0'); |
63
|
|
|
$this->result(Agent::CODE, $result); |
64
|
|
|
} else { |
65
|
|
|
$this->result(Agent::INFO, 'request failed'); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
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.