Passed
Pull Request — master (#1688)
by
unknown
03:58
created

Client::checkAudioAsync()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 8
ccs 0
cts 4
cp 0
crap 2
rs 10
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 string $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 checkMedia(string $mediaUrl, int $mediaType)
76
    {
77
        /*
78
         * 1:音频;2:图片
79
         */
80
        $mediaTypes = [1, 2];
81
        if (!in_array($mediaType, $mediaTypes)) {
82
            throw new InvalidArgumentException('media type must be 1 or 2');
83
        }
84
85
        $params = [
86
            'media_url' => $mediaUrl,
87
            'media_type' => $mediaType,
88
        ];
89
90
        return $this->httpPostJson('media_check_async', $params);
91
    }
92
93
    /**
94
     * Image security check async.
95
     *
96
     * @param string $mediaUrl
97
     *
98
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
99
     *
100
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
101
     * @throws \GuzzleHttp\Exception\GuzzleException
102
     */
103
    public function checkImageAsync(string $mediaUrl)
104
    {
105
        $params = [
106
            'media_url' => $mediaUrl,
107
            'media_type' => 2,
108
        ];
109
110
        return $this->httpPostJson('media_check_async', $params);
111
    }
112
113
    /**
114
     * Audio security check async.
115
     *
116
     * @param string $mediaUrl
117
     *
118
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
119
     *
120
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
121
     * @throws \GuzzleHttp\Exception\GuzzleException
122
     */
123
    public function checkAudioAsync(string $mediaUrl)
124
    {
125
        $params = [
126
            'media_url' => $mediaUrl,
127
            'media_type' => 1,
128
        ];
129
130
        return $this->httpPostJson('media_check_async', $params);
131
    }
132
133
134
}
135