QrcodeApi::show()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 9

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 18
loc 18
rs 9.4285
cc 2
eloc 9
nc 2
nop 1
1
<?php
2
namespace Wechat\API;
3
4
use Wechat\Api;
5
6
/**
7
 * 微信二维码相关接口.
8
 *
9
 * @author Tian.
10
 */
11
class QrcodeApi extends BaseApi
12
{
13
    /**
14
     * 创建临时二维码 - 场景值ID(Int)
15
     *
16
     * @param  integer $scene_id       [场景值ID]
17
     * @param  integer $expire_seconds [该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒]
18
     *
19
     * @return bool|array  $res
20
     */
21
    public function create($scene_id = 0, $expire_seconds = 30)
22
    {
23 View Code Duplication
        if (!is_numeric($scene_id) || $scene_id < 0 || $scene_id > 4294967295) {
0 ignored issues
show
Duplication introduced by
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...
24
            $this->setError('scene_id 必须为整数,且 不能 小于 0 大于 4294967295');
25
26
            return false;
27
        }
28
29
        if (!is_numeric($expire_seconds) || $expire_seconds < 0 || $expire_seconds > 2592000) {
30
            $this->setError('expire_seconds 必须为整数,且 不能 小于 0 大于 2592000');
31
32
            return false;
33
        }
34
35
        $queryStr = [
36
            'expire_seconds' => $expire_seconds,
37
            'action_name'    => 'QR_SCENE',
38
            'action_info'    => [
39
                'scene' => [
40
                    'scene_id' => $scene_id,
41
                ],
42
            ],
43
        ];
44
45
        $res = $this->_post('create', $queryStr);
46
47
        return $res;
48
    }
49
50
    /**
51
     * 创建永久二维码 - 场景值ID(Int)
52
     *
53
     * @param  integer $scene_id [场景值ID]
54
     *
55
     * @return bool|array  $res
56
     */
57
    public function createLimitInt($scene_id = 0)
58
    {
59 View Code Duplication
        if (!is_numeric($scene_id) || $scene_id < 0 || $scene_id > 4294967295) {
0 ignored issues
show
Duplication introduced by
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
            $this->setError('scene_id 必须为整数,且 不能 小于 0 大于 4294967295');
61
62
            return false;
63
        }
64
65
        $queryStr = [
66
            'action_name' => 'QR_LIMIT_SCENE',
67
            'action_info' => [
68
                'scene' => [
69
                    'scene_id' => $scene_id,
70
                ],
71
            ],
72
        ];
73
74
        $res = $this->_post('create', $queryStr);
75
76
        return $res;
77
    }
78
79
    /**
80
     * 创建永久二维码 - 场景值Str(Str)
81
     *
82
     * @param  integer $scene_id [场景值ID]
0 ignored issues
show
Bug introduced by
There is no parameter named $scene_id. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
83
     *
84
     * @return bool|array  $res
85
     */
86
    public function createLimitStr($scene_str = '')
87
    {
88
        if (!is_string($scene_str) || is_numeric($scene_str)) {
89
            $this->setError('scene_str 必须为字符串');
90
91
            return false;
92
        }
93
94
        $queryStr = [
95
            'action_name' => 'QR_LIMIT_STR_SCENE',
96
            'action_info' => [
97
                'scene' => [
98
                    'scene_str' => $scene_str,
99
                ],
100
            ],
101
        ];
102
103
        $res = $this->_post('create', $queryStr);
104
105
        return $res;
106
    }
107
108
    /**
109
     * 通过ticket换取二维码
110
     *
111
     * @param  string $ticket [获取的二维码ticket,凭借此ticket可以在有效时间内换取二维码。]
112
     *
113
     * @return string        [是一张图片,可以直接展示或者下载]
114
     */
115 View Code Duplication
    public function show($ticket = '')
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...
116
    {
117
        Api::setApiUrl('https://mp.weixin.qq.com/');
118
119
        $this->module = 'showqrcode';
120
121
        $queryStr = ['ticket' => $ticket];
122
123
        $res = $this->_get('', $queryStr);
124
125
        if (!$res) {
126
            $this->setError('二维码获取失败');
127
128
            return false;
129
        }
130
131
        return $res;
132
    }
133
}
134