Completed
Push — master ( daa55e...283203 )
by lan tian
9s
created

SmsBaoAgent::sendTemplateSms()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 3
1
<?php
2
3
namespace Toplan\PhpSms;
4
5
/**
6
 * Class SmsBaoAgent
7
 *
8
 * @property string $username
9
 * @property string $password
10
 */
11
class SmsBaoAgent extends Agent implements ContentSms
12
{
13
    protected $resultArr = [
14
        '0'  => '发送成功',
15
        '-1' => '参数不全',
16
        '30' => '密码错误',
17
        '40' => '账号不存在',
18
        '41' => '余额不足',
19
        '42' => '帐户已过期',
20
        '43' => 'IP地址限制',
21
        '50' => '内容含有敏感词',
22
        '51' => '手机号码不正确',
23
    ];
24
25
    public function sendSms($to, $content, $tempId, array $data)
26
    {
27
        $this->sendContentSms($to, $content);
28
    }
29
30 View Code Duplication
    public function sendContentSms($to, $content)
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...
31
    {
32
        $url = 'http://api.smsbao.com/sms';
33
        $params = [
34
            'u' => $this->username,
35
            'p' => md5($this->password),
36
            'm' => $to,
37
            'c' => $content,
38
        ];
39
        $result = $this->curl($url, $params);
40
        $this->setResult($result);
41
    }
42
43 View Code Duplication
    public function voiceVerify($to, $code, $tempId, array $tempData)
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...
44
    {
45
        $url = 'http://api.smsbao.com/voice';
46
        $params = [
47
            'u' => $this->username,
48
            'p' => md5($this->password),
49
            'm' => $to,
50
            'c' => $code,
51
        ];
52
        $result = $this->curl($url, $params);
53
        $this->setResult($result);
54
    }
55
56
    protected function setResult($result)
57
    {
58
        if ($result['request']) {
59
            $result = $result['response'];
60
            $msg = array_key_exists($result, $this->resultArr) ? $this->resultArr[$result] : 'unknown error';
61
            $this->result(Agent::INFO, json_encode(['code' => $result, 'msg' => $msg]));
62
            $this->result(Agent::SUCCESS, $result === '0');
63
            $this->result(Agent::CODE, $result);
64
        } else {
65
            $this->result(Agent::INFO, 'request failed');
66
        }
67
    }
68
}
69