1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Toplan\PhpSms; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class YunPianAgent |
7
|
|
|
* |
8
|
|
|
* @property string $apikey |
9
|
|
|
*/ |
10
|
|
|
class YunPianAgent extends Agent implements ContentSms |
11
|
|
|
{ |
12
|
|
|
protected $headers = [ |
13
|
|
|
'Accept:application/json;charset=utf-8', |
14
|
|
|
'Content-Type:application/x-www-form-urlencoded;charset=utf-8', |
15
|
|
|
]; |
16
|
|
|
|
17
|
|
|
public function sendSms($to, $content, $tempId, array $data) |
18
|
|
|
{ |
19
|
|
|
$this->sendContentSms($to, $content); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
View Code Duplication |
public function sendContentSms($to, $content) |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
$url = 'https://sms.yunpian.com/v1/sms/send.json'; |
25
|
|
|
$params = [ |
26
|
|
|
'apikey' => $this->apikey, |
27
|
|
|
'mobile' => $to, |
28
|
|
|
'text' => $content, |
29
|
|
|
]; |
30
|
|
|
$result = $this->curl($url, true, [ |
|
|
|
|
31
|
|
|
CURLOPT_HTTPHEADER => $this->headers, |
32
|
|
|
CURLOPT_POSTFIELDS => http_build_query($params), |
33
|
|
|
]); |
34
|
|
|
$this->setResult($result); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
View Code Duplication |
public function voiceVerify($to, $code, $tempId, array $data) |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$url = 'https://voice.yunpian.com/v1/voice/send.json'; |
40
|
|
|
$params = [ |
41
|
|
|
'apikey' => $this->apikey, |
42
|
|
|
'mobile' => $to, |
43
|
|
|
'code' => $code, |
44
|
|
|
]; |
45
|
|
|
$result = $this->curl($url, true, [ |
|
|
|
|
46
|
|
|
CURLOPT_HTTPHEADER => $this->headers, |
47
|
|
|
CURLOPT_POSTFIELDS => http_build_query($params), |
48
|
|
|
]); |
49
|
|
|
$this->setResult($result); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
View Code Duplication |
protected function setResult($result) |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
if ($result['request']) { |
55
|
|
|
$this->result(Agent::INFO, $result['response']); |
56
|
|
|
$result = json_decode($result['response'], true); |
57
|
|
|
$this->result(Agent::SUCCESS, $result['code'] === 0); |
58
|
|
|
$this->result(Agent::CODE, $result['code']); |
59
|
|
|
} else { |
60
|
|
|
$this->result(Agent::INFO, 'request failed'); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
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.