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 $accountSid |
13
|
|
|
* @property string $accountToken |
14
|
|
|
* @property string $appId |
15
|
|
|
* @property int $playTimes |
16
|
|
|
* @property string $displayNum |
17
|
|
|
*/ |
18
|
|
|
class YunTongXunAgent extends Agent implements TemplateSms, VoiceCode |
19
|
|
|
{ |
20
|
|
|
public function sendTemplateSms($to, $tempId, array $data) |
21
|
|
|
{ |
22
|
|
|
$data = array_values($data); |
23
|
|
|
$result = $this->rest()->sendTemplateSMS($to, $data, $tempId); |
|
|
|
|
24
|
|
|
$this->setResult($result); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function sendVoiceCode($to, $code) |
28
|
|
|
{ |
29
|
|
|
$playTimes = intval($this->playTimes ?: 3); |
30
|
|
|
$displayNum = $this->displayNum ?: null; |
31
|
|
|
$lang = $this->params('lang') ?: 'zh'; |
32
|
|
|
$respUrl = $this->params('respUrl'); |
33
|
|
|
$userData = $this->params('userData'); |
34
|
|
|
$welcomePrompt = $this->params('welcomePrompt'); |
35
|
|
|
$result = $this->rest()->voiceVerify($code, $playTimes, $to, $displayNum, $respUrl, $lang, $userData, $welcomePrompt); |
36
|
|
|
$this->setResult($result); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
protected function rest() |
40
|
|
|
{ |
41
|
|
|
$rest = new REST($this->serverIP, $this->serverPort, '2013-12-26', 'json'); |
42
|
|
|
$rest->setAccount($this->accountSid, $this->accountToken); |
43
|
|
|
$rest->setAppId($this->appId); |
44
|
|
|
|
45
|
|
|
return $rest; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
protected function setResult($result) |
49
|
|
|
{ |
50
|
|
|
if (!$result) { |
51
|
|
|
return; |
52
|
|
|
} |
53
|
|
|
$code = $info = (string) $result->statusCode; |
54
|
|
|
$success = $code === '000000'; |
55
|
|
|
if (isset($result->statusMsg)) { |
56
|
|
|
$info = (string) $result->statusMsg; |
57
|
|
|
} elseif (isset($result->TemplateSMS)) { |
58
|
|
|
$info = 'smsSid:' . $result->TemplateSMS->smsMessageSid; |
59
|
|
|
} elseif (isset($result->VoiceVerify)) { |
60
|
|
|
$info = 'callSid:' . $result->VoiceVerify->callSid; |
61
|
|
|
} |
62
|
|
|
$this->result(Agent::SUCCESS, $success); |
63
|
|
|
$this->result(Agent::CODE, $code); |
64
|
|
|
$this->result(Agent::INFO, $info); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.