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
|
|
|
* @property string $displayNum |
19
|
|
|
*/ |
20
|
|
|
class YunTongXunAgent extends Agent |
21
|
|
|
{ |
22
|
|
|
public function sendSms($to, $content, $tempId, array $data) |
23
|
|
|
{ |
24
|
|
|
$this->sendTemplateSms($to, $tempId, $data); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function sendTemplateSms($to, $tempId, array $data) |
28
|
|
|
{ |
29
|
|
|
$data = array_values($data); |
30
|
|
|
$result = $this->rest()->sendTemplateSMS($to, $data, $tempId); |
31
|
|
|
$this->setResult($result); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function voiceVerify($to, $code, $tempId, array $data) |
35
|
|
|
{ |
36
|
|
|
$playTimes = intval($this->playTimes ?: 3); |
37
|
|
|
$displayNum = $this->displayNum ?: null; |
38
|
|
|
$lang = $this->voiceLang ?: 'zh'; |
39
|
|
|
$result = $this->rest()->voiceVerify($code, $playTimes, $to, $displayNum, null, $lang); |
40
|
|
|
$this->setResult($result); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function rest() |
44
|
|
|
{ |
45
|
|
|
$rest = new REST($this->serverIP, $this->serverPort, $this->softVersion, 'json'); |
46
|
|
|
$rest->setAccount($this->accountSid, $this->accountToken); |
47
|
|
|
$rest->setAppId($this->appId); |
48
|
|
|
|
49
|
|
|
return $rest; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function setResult($result) |
53
|
|
|
{ |
54
|
|
|
if (!$result) { |
55
|
|
|
return; |
56
|
|
|
} |
57
|
|
|
$code = $info = (string) $result->statusCode; |
58
|
|
|
$success = $code === '000000'; |
59
|
|
|
if (!$success) { |
60
|
|
|
$info = (string) $result->statusMsg; |
61
|
|
|
} else { |
62
|
|
|
if (isset($result->TemplateSMS)) { |
63
|
|
|
$info = 'smsSid:' . $result->TemplateSMS->smsMessageSid; |
64
|
|
|
} elseif (isset($result->VoiceVerify)) { |
65
|
|
|
$info = 'callSid:' . $result->VoiceVerify->callSid; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
$this->result(Agent::SUCCESS, $success); |
69
|
|
|
$this->result(Agent::CODE, $code); |
70
|
|
|
$this->result(Agent::INFO, $info); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function sendContentSms($to, $content) |
74
|
|
|
{ |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|