Completed
Pull Request — master (#88)
by lan tian
03:16 queued 01:23
created

SmsBaoAgent::voiceVerify()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 4
1
<?php
2
3
namespace Toplan\PhpSms;
4
5
/**
6
 * Class SmsBaoAgent
7
 *
8
 * @property string $smsUser
9
 * @property string $smsPassword
10
 */
11 View Code Duplication
class SmsBaoAgent extends Agent
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type Toplan\PhpSms\SmsBaoAgent has been defined more than once; this definition is ignored, only the first definition in src/phpsms/agents/SmsbaoAgent.php (L11-84) is considered.

This check looks for classes that have been defined more than once.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
Duplication introduced by
This class 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...
Duplication introduced by
This class 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...
12
{
13
    protected $resultArr = [
14
        '0'  => '发送成功',
15
        '-1' => '参数不全',
16
        '-2' => '服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!',
17
        '30' => '密码错误',
18
        '40' => '账号不存在',
19
        '41' => '余额不足',
20
        '42' => '帐户已过期',
21
        '43' => 'IP地址限制',
22
        '50' => '内容含有敏感词',
23
        '51' => '手机号码不正确',
24
    ];
25
26
    public function sendSms($to, $content, $tempId, array $data)
27
    {
28
        $this->sendContentSms($to, $content);
29
    }
30
31
    /**
32
     * Content SMS send process.
33
     *
34
     * @param $to
35
     * @param $content
36
     */
37
    public function sendContentSms($to, $content)
38
    {
39
        $url = 'http://api.smsbao.com/sms';
40
        $username = $this->smsUser;
41
        $password = md5($this->smsPassword);
42
        $content = urlencode($content);
43
        $postString = "u=$username&p=$password&m=$to&c=$content";
44
        $response = $this->sockPost($url, $postString);
45
        $this->setResult($response);
46
    }
47
48
    /**
49
     * Template SMS send process.
50
     *
51
     * @param       $to
52
     * @param       $tempId
53
     * @param array $tempData
54
     */
55
    public function sendTemplateSms($to, $tempId, array $tempData)
56
    {
57
    }
58
59
    /**
60
     * Voice verify send process.
61
     *
62
     * @param       $to
63
     * @param       $code
64
     * @param       $tempId
65
     * @param array $tempData
66
     */
67
    public function voiceVerify($to, $code, $tempId, array $tempData)
68
    {
69
        $url = 'http://api.smsbao.com/voice';
70
        $username = $this->smsUser;
71
        $password = md5($this->smsPassword);
72
        $postString = "u=$username&p=$password&m=$to&c=$code";
73
        $response = $this->sockPost($url, $postString);
74
        $this->setResult($response);
75
    }
76
77
    protected function setResult($result)
78
    {
79
        $msg = array_key_exists($result, $this->resultArr) ? $this->resultArr[$result] : '未知错误';
80
        $this->result(Agent::INFO, json_encode(['code' => $result, 'msg' => $msg]));
81
        $this->result(Agent::SUCCESS, $result === '0');
82
        $this->result(Agent::CODE, $result);
83
    }
84
}
85