Passed
Pull Request — master (#1388)
by
unknown
02:20
created

Client::updateAvatar()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 5
dl 0
loc 13
rs 10
c 0
b 0
f 0
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\OpenPlatform\Authorizer\MiniProgram\Setting;
13
14
use EasyWeChat\Kernel\BaseClient;
15
16
/**
17
 * Class Client.
18
 *
19
 * @author ClouderSky <[email protected]>
20
 */
21
class Client extends BaseClient
22
{
23
    /**
24
     * 获取账号基本信息.
25
     */
26
    public function getBasicInfo()
27
    {
28
        return $this->httpPostJson('cgi-bin/account/getaccountbasicinfo');
29
    }
30
31
    /**
32
     * 修改头像.
33
     *
34
     * @param string $mediaId 头像素材mediaId
35
     * @param int    $left    剪裁框左上角x坐标(取值范围:[0, 1])
36
     * @param int    $top     剪裁框左上角y坐标(取值范围:[0, 1])
37
     * @param int    $right   剪裁框右下角x坐标(取值范围:[0, 1])
38
     * @param int    $bottom  剪裁框右下角y坐标(取值范围:[0, 1])
39
     */
40
    public function updateAvatar(
41
        string $mediaId,
42
        float $left = 0,
43
        float $top = 0,
44
        float $right = 1,
45
        float $bottom = 1
46
    ) {
47
        $params = [
48
            'head_img_media_id' => $mediaId,
49
            'x1' => $left, 'y1' => $top, 'x2' => $right, 'y2' => $bottom,
50
        ];
51
52
        return $this->httpPostJson('cgi-bin/account/modifyheadimage', $params);
53
    }
54
55
    /**
56
     * 修改功能介绍.
57
     *
58
     * @param string $signature 功能介绍(简介)
59
     */
60
    public function updateSignature(string $signature)
61
    {
62
        $params = ['signature' => $signature];
63
64
        return $this->httpPostJson('cgi-bin/account/modifysignature', $params);
65
    }
66
67
    /**
68
     * 获取账号可以设置的所有类目.
69
     */
70
    public function getAllCategories()
71
    {
72
        return $this->httpPostJson('cgi-bin/wxopen/getallcategories');
73
    }
74
75
    /**
76
     * 添加类目.
77
     *
78
     * @param array $categories 类目数组
79
     */
80
    public function addCategories(array $categories)
81
    {
82
        $params = ['categories' => $categories];
83
84
        return $this->httpPostJson('cgi-bin/wxopen/addcategory', $params);
85
    }
86
87
    /**
88
     * 删除类目.
89
     *
90
     * @param int $firstId  一级类目ID
91
     * @param int $secondId 二级类目ID
92
     */
93
    public function deleteCategories(int $firstId, int $secondId)
94
    {
95
        $params = ['first' => $firstId, 'second' => $secondId];
96
97
        return $this->httpPostJson('cgi-bin/wxopen/deletecategory', $params);
98
    }
99
100
    /**
101
     * 获取账号已经设置的所有类目.
102
     */
103
    public function getCategories()
104
    {
105
        return $this->httpPostJson('cgi-bin/wxopen/getcategory');
106
    }
107
108
    /**
109
     * 修改类目.
110
     *
111
     * @param array $category 单个类目
112
     */
113
    public function updateCategory(array $category)
114
    {
115
        return $this->httpPostJson('cgi-bin/wxopen/modifycategory', $category);
116
    }
117
118
    /**
119
     * 小程序名称设置及改名.
120
     *
121
     * @param string $nickname       昵称
122
     * @param string $idCardMediaId  身份证照片素材ID
123
     * @param string $licenseMediaId 组织机构代码证或营业执照素材ID
124
     * @param string $otherStuffs    其他证明材料素材ID
125
     */
126
    public function setNickname(
127
        string $nickname,
128
        string $idCardMediaId = '',
129
        string $licenseMediaId = '',
130
        array $otherStuffs = []
131
    ) {
132
        $params = [
133
            'nick_name' => $nickname,
134
            'id_card' => $idCardMediaId,
135
            'license' => $licenseMediaId,
136
        ];
137
138
        for ($i = 0; $i < \count($otherStuffs); ++$i) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
139
            $params['naming_other_stuff_'.($i + 1)] = $otherStuffs[$i];
140
        }
141
142
        return $this->httpPostJson('wxa/setnickname', $params);
143
    }
144
145
    /**
146
     * 小程序改名审核状态查询.
147
     *
148
     * @param int $auditId 审核单id
149
     */
150
    public function getNicknameAuditStatus($auditId)
151
    {
152
        $params = ['audit_id' => $auditId];
153
154
        return $this->httpPostJson('wxa/api_wxa_querynickname', $params);
155
    }
156
157
    /**
158
     * 微信认证名称检测.
159
     *
160
     * @param string $nickname 名称(昵称)
161
     */
162
    public function isAvailableNickname($nickname)
163
    {
164
        $params = ['nick_name' => $nickname];
165
166
        return $this->httpPostJson(
167
            'cgi-bin/wxverify/checkwxverifynickname', $params);
168
    }
169
}
170