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