Completed
Push — master ( 9d4234...1ae964 )
by lan tian
8s
created

SubMailAgent::sendTemplateSms()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 3
1
<?php
2
3
namespace Toplan\PhpSms;
4
5
/**
6
 * Class SubMailAgent
7
 *
8
 * @property string $appid
9
 * @property string $signature
10
 */
11
class SubMailAgent extends Agent
12
{
13
    public function sendSms($to, $content, $tempId, array $data)
14
    {
15
        $this->sendTemplateSms($to, $tempId, $data);
16
    }
17
18 View Code Duplication
    public function sendTemplateSms($to, $tempId, array $data)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
    {
20
        $url = 'https://api.mysubmail.com/message/xsend.json';
21
        $params = [
22
            'appid'     => $this->appid,
23
            'project'   => $tempId,
24
            'to'        => $to,
25
            'signature' => $this->signature,
26
            'vars'      => json_encode($data),
27
        ];
28
        $result = $this->curl($url, $params, true);
29
        $this->setResult($result);
30
    }
31
32 View Code Duplication
    public function voiceVerify($to, $code, $tempId, array $data)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33
    {
34
        $url = 'https://api.mysubmail.com/voice/verify.json';
35
        $params = [
36
            'appid'     => $this->appid,
37
            'to'        => $to,
38
            'code'      => $code,
39
            'signature' => $this->signature,
40
        ];
41
        $result = $this->curl($url, $params, true);
42
        $this->setResult($result);
43
    }
44
45
    public function sendContentSms($to, $content)
46
    {
47
    }
48
49
    protected function setResult($result)
50
    {
51
        if ($result['request']) {
52
            $this->result(Agent::INFO, $result['response']);
53
            $result = json_decode($result['response'], true);
54
            if ($result['status'] === 'success') {
55
                $this->result(Agent::SUCCESS, true);
56
            } else {
57
                $this->result(Agent::INFO, $result['msg']);
58
                $this->result(Agent::CODE, $result['code']);
59
            }
60
        } else {
61
            $this->result(Agent::INFO, 'request failed');
62
        }
63
    }
64
}
65