Passed
Pull Request — master (#1688)
by Carlos
03:50
created

Client::checkImage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the overtrue/wechat.
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 EasyWeChat\BasicService\ContentSecurity;
13
14
use EasyWeChat\Kernel\BaseClient;
15
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
16
17
/**
18
 * Class Client.
19
 *
20
 * @author tianyong90 <[email protected]>
21
 */
22
class Client extends BaseClient
23
{
24
    /**
25
     * @var string
26
     */
27
    protected $baseUri = 'https://api.weixin.qq.com/wxa/';
28
29
    /**
30
     * Text content security check.
31
     *
32
     * @param string $text
33
     *
34
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
35
     *
36
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
37
     * @throws \GuzzleHttp\Exception\GuzzleException
38
     */
39 1
    public function checkText(string $text)
40
    {
41
        $params = [
42 1
            'content' => $text,
43
        ];
44
45 1
        return $this->httpPostJson('msg_sec_check', $params);
46
    }
47
48
    /**
49
     * Image security check.
50
     *
51
     * @param string $path
52
     *
53
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
54
     *
55
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
56
     * @throws \GuzzleHttp\Exception\GuzzleException
57
     */
58 1
    public function checkImage(string $path)
59
    {
60 1
        return $this->httpUpload('img_sec_check', ['media' => $path]);
61
    }
62
63
    /**
64
     * Media security check.
65
     *
66
     * @param string $mediaUrl
67
     * @param int    $mediaType
68
     *
69
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
70
     *
71
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
72
     * @throws \GuzzleHttp\Exception\GuzzleException
73
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
74
     */
75
    public function checkMediaAsync(string $mediaUrl, int $mediaType)
76
    {
77
        /*
78
         * 1:音频;2:图片
79
         */
80
        $mediaTypes = [1, 2];
81
        
82
        if (!in_array($mediaType, $mediaTypes)) {
83
            throw new InvalidArgumentException('media type must be 1 or 2');
84
        }
85
86
        $params = [
87
            'media_url' => $mediaUrl,
88
            'media_type' => $mediaType,
89
        ];
90
91
        return $this->httpPostJson('media_check_async', $params);
92
    }
93
94
    /**
95
     * Image security check async.
96
     *
97
     * @param string $mediaUrl
98
     *
99
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
100
     *
101
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
102
     * @throws \GuzzleHttp\Exception\GuzzleException
103
     */
104
    public function checkImageAsync(string $mediaUrl)
105
    {
106
        return $this->checkMediaAsync($mediaUrl, 2);
107
    }
108
109
    /**
110
     * Audio security check async.
111
     *
112
     * @param string $mediaUrl
113
     *
114
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
115
     *
116
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
117
     * @throws \GuzzleHttp\Exception\GuzzleException
118
     */
119
    public function checkAudioAsync(string $mediaUrl)
120
    {
121
        return $this->checkMediaAsync($mediaUrl, 1);
122
    }
123
}
124