VoiceProvider::getRequestPayload()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 0
cts 9
cp 0
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Huying\Sms\RongLian;
4
5
use GuzzleHttp\Exception\GuzzleException;
6
use Huying\Sms\AbstractProvider;
7
use Huying\Sms\Message;
8
use Huying\Sms\ProviderException;
9
use Psr\Http\Message\ResponseInterface;
10
11
/**
12
 * 容联短信平台接口实现
13
 *
14
 * Class Provider
15
 */
16
class VoiceProvider extends Provider
17
{
18
    /**
19
     * 返回短信接口必须的参数
20
     * @param $key
21
     * @return array
22
     */
23 View Code Duplication
    protected function getRequiredOptions($key)
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...
24
    {
25
        if ($key == self::PROVIDER_OPTIONS) {
26
            return [
27
                'accountSid',
28
                'authToken',
29
                'appId',
30
            ];
31
        } elseif ($key == self::MESSAGE_OPTIONS) {
32
            return [
33
                'recipients',
34
                'data',
35
            ];
36
        } else {
37
            return []; // @codeCoverageIgnore
38
        }
39
    }
40
41
    /**
42
     * 返回请求链接
43
     *
44
     * @param Message $message
45
     * @return string
46
     * @throws \RuntimeException
47
     */
48
    protected function getUrl(Message $message)
49
    {
50
        return $this->restUrl.'/'.$this->softVersion
51
            .'/Accounts/'.$this->accountSid
52
            .'/Calls/VoiceVerify?sig='.strtoupper(md5($this->accountSid.$this->authToken.$this->getTimestamp()));
53
    }
54
55
    /**
56
     * 返回请求短信接口时的 payload
57
     *
58
     * @param Message $message
59
     * @return string
60
     * @throws \RuntimeException
61
     */
62
    protected function getRequestPayload(Message $message)
63
    {
64
        $recipients = implode(',', $message->getRecipients());
65
        $data = $message->getData();
66
67
        return json_encode([
68
            'to' => $recipients,
69
            'appId' => $this->appId,
70
        ] + $data);
71
    }
72
73
    /**
74
     * 获取短信供应商名称
75
     *
76
     * @return string
77
     */
78
    public function getName()
79
    {
80
        return 'RongLian';
81
    }
82
}
83