|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Toplan\PhpSms; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class UcpaasAgent |
|
7
|
|
|
* |
|
8
|
|
|
* @property string $accountSid |
|
9
|
|
|
* @property string $accountToken |
|
10
|
|
|
* @property string $appId |
|
11
|
|
|
*/ |
|
12
|
|
|
class UcpaasAgent extends Agent implements TemplateSms |
|
13
|
|
|
{ |
|
14
|
|
|
public function sendSms($to, $content, $tempId, array $data) |
|
15
|
|
|
{ |
|
16
|
|
|
$this->sendTemplateSms($to, $tempId, $data); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function sendTemplateSms($to, $tempId, array $data) |
|
20
|
|
|
{ |
|
21
|
|
|
$response = $this->ucpass()->templateSMS($this->appId, $to, $tempId, implode(',', $data)); |
|
22
|
|
|
$this->setResult($response); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function voiceVerify($to, $code, $tempId, array $data) |
|
26
|
|
|
{ |
|
27
|
|
|
$response = $this->ucpass()->voiceCode($this->appId, $code, $to); |
|
28
|
|
|
$this->result($response); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
protected function ucpass() |
|
32
|
|
|
{ |
|
33
|
|
|
$config = [ |
|
34
|
|
|
'accountsid' => $this->accountSid, |
|
35
|
|
|
'token' => $this->accountToken, |
|
36
|
|
|
]; |
|
37
|
|
|
|
|
38
|
|
|
return new \Ucpaas($config); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
protected function setResult($result) |
|
42
|
|
|
{ |
|
43
|
|
|
$result = json_decode($result); |
|
44
|
|
|
if (!$result) { |
|
45
|
|
|
return $this->result(Agent::INFO, 'request failed'); |
|
46
|
|
|
} |
|
47
|
|
|
$this->result(Agent::SUCCESS, $result->resp->respCode === '000000'); |
|
48
|
|
|
$this->result(Agent::CODE, $result->resp->respCode); |
|
49
|
|
|
$this->result(Agent::INFO, json_encode($result->resp)); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|