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

LuosimaoAgent::LuosimaoCurl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 13
nc 1
nop 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A LuosimaoAgent::setResult() 11 11 2
A LuosimaoAgent::sendTemplateSms() 0 3 1
1
<?php
2
3
namespace Toplan\PhpSms;
4
5
/**
6
 * Class LuosimaoAgent
7
 *
8
 * @property string $apikey
9
 * @property string $voiceApikey
10
 */
11
class LuosimaoAgent extends Agent
12
{
13
    public function sendSms($to, $content, $tempId, array $data)
14
    {
15
        // 签名必须在最后面
16
        if ($content && !preg_match('/】$/', $content)) {
17
            preg_match('/【([0-9a-zA-Z\W]+)】/', $content, $matches);
18
            if (isset($matches[0])) {
19
                $content = str_replace($matches[0], '', $content) . $matches[0];
20
            }
21
        }
22
        $this->sendContentSms($to, $content);
23
    }
24
25 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...
26
    {
27
        $url = 'http://sms-api.luosimao.com/v1/send.json';
28
        $optData = [
29
            'mobile'  => $to,
30
            'message' => $content,
31
        ];
32
        $result = $this->curl($url, $optData, true, [
33
            CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
34
            CURLOPT_USERPWD  => "api:key-$this->apikey",
35
        ]);
36
        $this->setResult($result);
37
    }
38
39 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...
40
    {
41
        $url = 'http://voice-api.luosimao.com/v1/verify.json';
42
        $optData = [
43
            'mobile' => $to,
44
            'code'   => $code,
45
        ];
46
        $result = $this->curl($url, $optData, true, [
47
            CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
48
            CURLOPT_USERPWD  => "api:key-$this->voiceApikey",
49
        ]);
50
        $this->setResult($result);
51
    }
52
53 View Code Duplication
    protected function setResult($result)
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...
54
    {
55
        if ($result['request']) {
56
            $result = json_decode($result['response'], true);
57
            $this->result(Agent::INFO, $result);
58
            $this->result(Agent::SUCCESS, $result['error'] === 0);
59
            $this->result(Agent::CODE, $result['error']);
60
        } else {
61
            $this->result(Agent::INFO, '请求失败');
62
        }
63
    }
64
65
    public function sendTemplateSms($to, $tempId, array $data)
66
    {
67
    }
68
}
69