Completed
Push — master ( 13cabb...9cf391 )
by lan tian
6s
created

UcpaasAgent::setResult()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
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
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
            $this->result(Agent::INFO, '请求失败');
46
47
            return;
48
        }
49
        $this->result(Agent::SUCCESS, $result->resp->respCode === '000000');
50
        $this->result(Agent::CODE, $result->resp->respCode);
51
        $this->result(Agent::INFO, json_encode($result->resp));
52
    }
53
54
    public function sendContentSms($to, $content)
55
    {
56
    }
57
}
58