|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Toplan\PhpSms; |
|
4
|
|
|
|
|
5
|
|
|
use REST; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class YunTongXunAgent |
|
9
|
|
|
* |
|
10
|
|
|
* @property string $serverIP |
|
11
|
|
|
* @property string $serverPort |
|
12
|
|
|
* @property string $softVersion |
|
13
|
|
|
* @property string $accountSid |
|
14
|
|
|
* @property string $accountToken |
|
15
|
|
|
* @property string $appId |
|
16
|
|
|
* @property int $playTimes |
|
17
|
|
|
* @property string $voiceLang |
|
18
|
|
|
*/ |
|
19
|
|
|
class YunTongXunAgent extends Agent |
|
20
|
|
|
{ |
|
21
|
|
|
public function sendSms($tempId, $to, array $data, $content) |
|
22
|
|
|
{ |
|
23
|
|
|
$this->sendTemplateSms($tempId, $to, $data); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function sendTemplateSms($tempId, $to, array $data) |
|
27
|
|
|
{ |
|
28
|
|
|
// 初始化REST SDK |
|
29
|
|
|
$rest = new REST( |
|
30
|
|
|
$this->serverIP, |
|
31
|
|
|
$this->serverPort, |
|
32
|
|
|
$this->softVersion |
|
33
|
|
|
); |
|
34
|
|
|
$rest->setAccount($this->accountSid, $this->accountToken); |
|
35
|
|
|
$rest->setAppId($this->appId); |
|
36
|
|
|
// 发送模板短信 |
|
37
|
|
|
$data = array_values($data); |
|
38
|
|
|
$result = $rest->sendTemplateSMS($to, $data, $tempId); |
|
39
|
|
View Code Duplication |
if ($result) { |
|
|
|
|
|
|
40
|
|
|
$code = (String) $result->statusCode; |
|
41
|
|
|
if ($code === '000000') { |
|
42
|
|
|
$this->result['success'] = true; |
|
43
|
|
|
$this->result['code'] = $code; |
|
44
|
|
|
$this->result['info'] = 'smsSid:' . $result->TemplateSms->smsMessageSid; |
|
45
|
|
|
} else { |
|
46
|
|
|
$this->result['code'] = $code; |
|
47
|
|
|
$this->result['info'] = (String) $result->statusMsg; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function sendContentSms($to, $content) |
|
53
|
|
|
{ |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function voiceVerify($to, $code) |
|
57
|
|
|
{ |
|
58
|
|
|
// 初始化REST SDK |
|
59
|
|
|
$rest = new REST( |
|
60
|
|
|
$this->serverIP, |
|
61
|
|
|
$this->serverPort, |
|
62
|
|
|
$this->softVersion |
|
63
|
|
|
); |
|
64
|
|
|
$rest->setAccount($this->accountSid, $this->accountToken); |
|
65
|
|
|
$rest->setAppId($this->appId); |
|
66
|
|
|
|
|
67
|
|
|
// 调用语音验证码接口 |
|
68
|
|
|
$playTimes = intval($this->playTimes ?: 3); |
|
69
|
|
|
$lang = $this->voiceLang ?: 'zh'; |
|
70
|
|
|
$userData = $respUrl = null; |
|
71
|
|
|
$result = $rest->voiceVerify($code, $playTimes, $to, null, $respUrl, $lang, $userData, null, null); |
|
72
|
|
View Code Duplication |
if ($result) { |
|
|
|
|
|
|
73
|
|
|
$code = (String) $result->statusCode; |
|
74
|
|
|
if ($code === '000000') { |
|
75
|
|
|
$this->result['success'] = true; |
|
76
|
|
|
$this->result['code'] = $code; |
|
77
|
|
|
$this->result['info'] = 'callSid:' . $result->VoiceVerify->callSid; |
|
78
|
|
|
} else { |
|
79
|
|
|
$this->result['code'] = $code; |
|
80
|
|
|
$this->result['info'] = (String) $result->statusMsg; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
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.