GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 078abd...25e8ec )
by Carlos
04:34 queued 01:48
created

src/Gateways/HuyiGateway.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
/*
4
 * This file is part of the overtrue/easy-sms.
5
 *
6
 * (c) overtrue <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Overtrue\EasySms\Gateways;
13
14
use Overtrue\EasySms\Contracts\MessageInterface;
15
use Overtrue\EasySms\Contracts\PhoneNumberInterface;
16
use Overtrue\EasySms\Exceptions\GatewayErrorException;
17
use Overtrue\EasySms\Support\Config;
18
use Overtrue\EasySms\Traits\HasHttpRequest;
19
20
/**
21
 * Class HuyiGateway.
22
 *
23
 * @see http://www.ihuyi.com/api/sms.html
24
 */
25
class HuyiGateway extends Gateway
26
{
27
    use HasHttpRequest;
28
29
    const ENDPOINT_URL = 'http://106.ihuyi.com/webservice/sms.php?method=Submit';
30
31
    const ENDPOINT_FORMAT = 'json';
32
33
    const SUCCESS_CODE = 2;
34
35
    /**
36
     * @param \Overtrue\EasySms\Contracts\PhoneNumberInterface $to
37
     * @param \Overtrue\EasySms\Contracts\MessageInterface     $message
38
     * @param \Overtrue\EasySms\Support\Config                 $config
39
     *
40
     * @return array
41
     *
42
     * @throws \Overtrue\EasySms\Exceptions\GatewayErrorException ;
43
     */
44 1
    public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config)
45
    {
46
        $params = [
47 1
            'account' => $config->get('api_id'),
48 1
            'mobile' => $to->getIDDCode() ? \sprintf('%s %s', $to->getIDDCode(), $to->getNumber()) : $to->getNumber(),
49 1
            'content' => $message->getContent($this),
50 1
            'time' => time(),
51 1
            'format' => self::ENDPOINT_FORMAT,
52 1
            'sign' => $config->get('signature'),
53 1
        ];
54
55 1
        $params['password'] = $this->generateSign($params);
56
57 1
        $result = $this->post(self::ENDPOINT_URL, $params);
58
59 1 View Code Duplication
        if (self::SUCCESS_CODE != $result['code']) {
0 ignored issues
show
This code seems to be duplicated across 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...
60 1
            throw new GatewayErrorException($result['msg'], $result['code'], $result);
61
        }
62
63 1
        return $result;
64
    }
65
66
    /**
67
     * Generate Sign.
68
     *
69
     * @param array $params
70
     *
71
     * @return string
72
     */
73 1
    protected function generateSign($params)
74
    {
75 1
        return md5($params['account'].$this->config->get('api_key').$params['mobile'].$params['content'].$params['time']);
76
    }
77
}
78