Issues (2)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Provider.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 Provider extends AbstractProvider
17
{
18
    /**
19
     * Rest URL
20
     *
21
     * @var string
22
     */
23
    protected $restUrl = 'https://app.cloopen.com:8883';
24
25
    /**
26
     * 接口版本
27
     *
28
     * @var string
29
     */
30
    protected $softVersion = '2013-12-26';
31
32
    /**
33
     * 主账户 ID
34
     *
35
     * @var string
36
     */
37
    protected $accountSid;
38
39
    /**
40
     * 主账号授权令牌
41
     *
42
     * @var string
43
     */
44
    protected $authToken;
45
46
    /**
47
     * 应用 ID
48
     *
49
     * @var string
50
     */
51
    protected $appId;
52
53
    /**
54
     * 当前时间戳
55
     *
56
     * @var string
57
     */
58
    protected $timestamp;
59
60
    /**
61
     * 返回短信接口必须的参数
62
     * @param $key
63
     * @return array
64
     */
65 8 View Code Duplication
    protected function getRequiredOptions($key)
0 ignored issues
show
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...
66
    {
67 8
        if ($key == self::PROVIDER_OPTIONS) {
68
            return [
69 8
                'accountSid',
70 8
                'authToken',
71 8
                'appId',
72 8
            ];
73 4
        } elseif ($key == self::MESSAGE_OPTIONS) {
74
            return [
75 4
                'data',
76 4
                'recipients',
77 4
                'template_id',
78 4
            ];
79
        } else {
80
            return []; // @codeCoverageIgnore
81
        }
82
    }
83
84
    /**
85
     * 获取接收使用的时间戳
86
     *
87
     * 每次调用返回值是相同的
88
     *
89
     * @return string
90
     */
91 4
    public function getTimestamp()
92
    {
93 4
        if ($this->timestamp) {
94 4
            return $this->timestamp;
95
        } else {
96 4
            return $this->timestamp = date('YmdHis');
97
        }
98
    }
99
100
    /**
101
     * 返回请求链接
102
     *
103
     * @param Message $message
104
     * @return string
105
     * @throws \RuntimeException
106
     */
107 4
    protected function getUrl(Message $message)
108
    {
109 4
        return $this->restUrl.'/'.$this->softVersion
110 4
            .'/Accounts/'.$this->accountSid
111 4
            .'/SMS/TemplateSMS?sig='.md5($this->accountSid.$this->authToken.$this->getTimestamp());
112
    }
113
114
    /**
115
     * 返回请求的方法
116
     *
117
     * @return string HTTP 方法
118
     */
119 4
    protected function getRequestMethod()
120
    {
121 4
        return static::METHOD_POST;
122
    }
123
124
    /**
125
     * 返回请求短信接口时的 headers
126
     *
127
     * @return array
128
     */
129 4
    protected function getRequestHeaders()
130
    {
131
        return [
132 4
            'Accept' => 'application/json;',
133 4
            'Content-Type' => 'application/json;charset=utf-8;',
134 4
            'Authorization' => base64_encode($this->accountSid.':'.$this->getTimestamp()),
135 4
        ];
136
    }
137
138
    /**
139
     * 返回请求短信接口时的 payload
140
     *
141
     * @param Message $message
142
     * @return string
143
     * @throws \RuntimeException
144
     */
145 4
    protected function getRequestPayload(Message $message)
146
    {
147 4
        $recipients = implode(',', $message->getRecipients());
148 4
        $templateId = (string) $message->getTemplateId();
149 4
        $data = $message->getData();
150 4
        array_walk($data, function (&$item) {
151 4
            $item = (string) $item;
152 4
        });
153 4
        $data = array_values($data);
154
155 4
        return json_encode([
156 4
            'to' => $recipients,
157 4
            'appId' => $this->appId,
158 4
            'templateId' => $templateId,
159 4
            'datas' => $data,
160 4
        ]);
161
    }
162
163
    /**
164
     * 处理短信接口的返回结果
165
     *
166
     * @param ResponseInterface|GuzzleException $response
167
     * @return array
168
     * @throws ProviderException
169
     * @throws GuzzleException
170
     */
171 4
    protected function handleResponse($response)
172
    {
173 4
        if ($response instanceof GuzzleException) {
174
            throw $response;
175
        }
176 4
        $parsedResponse = self::parseJson($response->getBody());
177 4
        if ($parsedResponse['statusCode'] != '000000') {
178 2
            throw new ProviderException($parsedResponse['statusMsg'], $parsedResponse['statusCode'], $parsedResponse);
179
        }
180
181 2
        return $parsedResponse;
182
    }
183
184
    /**
185
     * 获取短信供应商名称
186
     *
187
     * @return string
188
     */
189 2
    public function getName()
190
    {
191 2
        return 'RongLian';
192
    }
193
}
194