Completed
Pull Request — master (#1277)
by
unknown
03:17
created

Client::getUserDetail3rd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 7
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\OpenWork\Corp;
13
14
use EasyWeChat\Kernel\BaseClient;
15
use EasyWeChat\Kernel\ServiceContainer;
16
17
/**
18
 * Client.
19
 *
20
 * @author xiaomin <[email protected]>
21
 */
22
class Client extends BaseClient
23
{
24
25
    public function __construct(ServiceContainer $app)
26
    {
27
        parent::__construct($app, $app['suite_access_token']);
28
    }
29
30
    /**
31
     * 企业微信应用授权 url.
32
     *
33
     * @param string $pre_auth_code
34
     * @param string $redirect_uri
35
     * @param string $state
36
     *
37
     * @return string
38
     *
39
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
40
     */
41
    public function getApp3rdInstallUrl(string $redirect_uri, string $state = '')
42
    {
43
        $params = [
44
            'suite_id'      => $this->app['config']['suite_id'],
45
            'redirect_uri'  => urlencode($redirect_uri),
46
            'pre_auth_code' => $this->getPreAuthCode()['pre_auth_code'],
47
            'state'         => $state || rand()
48
        ];
49
        return 'https://open.work.weixin.qq.com/3rdapp/install?' . http_build_query($params);
50
    }
51
52
53
    /**
54
     * 获取预授权码.
55
     *
56
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
57
     *
58
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
59
     */
60
    public function getPreAuthCode()
61
    {
62
        return $this->httpGet('cgi-bin/service/get_pre_auth_code');
63
    }
64
65
    /**
66
     * 设置授权配置.
67
     *
68
     * 该接口可对某次授权进行配置
69
     *
70
     * @param array $data
71
     *
72
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
73
     *
74
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
75
     */
76
    public function setSessionInfo(array $data)
77
    {
78
        return $this->httpPostJson('cgi-bin/service/set_session_info', compact('data'));
79
    }
80
81
    /**
82
     * 获取企业永久授权码.
83
     *
84
     * @param string $auth_code 临时授权码,会在授权成功时附加在redirect_uri中跳转回第三方服务商网站,或通过回调推送给服务商。长度为64至512个字节
85
     *
86
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
87
     *
88
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
89
     */
90
    public function getPermanentCode(string $auth_code)
91
    {
92
        $params = [
93
            'auth_code' => $auth_code
94
        ];
95
        return $this->httpPostJson('cgi-bin/service/set_session_info', $params);
96
    }
97
98
    /**
99
     * 获取企业授权信息.
100
     *
101
     * @param string $auth_corpid
102
     * @param string $permanent_code
103
     *
104
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
105
     *
106
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
107
     */
108
    public function getAuthInfo(string $auth_corpid, string $permanent_code)
109
    {
110
        $params = [
111
            'auth_corpid'    => $auth_corpid,
112
            'permanent_code' => $permanent_code
113
        ];
114
        return $this->httpPostJson('cgi-bin/service/get_auth_info', $params);
115
    }
116
117
    /**
118
     * 获取应用的管理员列表.
119
     *
120
     * @param string $auth_corpid
121
     * @param string $agentid
122
     *
123
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
124
     *
125
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
126
     */
127
    public function getAdminList(string $auth_corpid, string $agentid)
128
    {
129
        $params = [
130
            'auth_corpid' => $auth_corpid,
131
            'agentid'     => $agentid
132
        ];
133
        return $this->httpPostJson('cgi-bin/service/get_admin_lis', $params);
134
    }
135
136
    /**
137
     * 获取登录url.
138
     *
139
     * @param string      $redirect_uri
140
     * @param string      $scope
141
     * @param string|null $state
142
     *
143
     * @return string
144
     */
145
    public function getOauth2Uri(string $redirect_uri, string $scope = 'snsapi_userinfo', string $state = null)
146
    {
147
        $params = [
148
            'appid'         => $this->app['config']['suite_id'],
149
            'redirect_uri'  => urlencode($redirect_uri),
150
            'response_type' => 'code',
151
            'scope'         => $scope,
152
            'state'         => $state || rand()
153
        ];
154
        return 'https://open.weixin.qq.com/connect/oauth2/authorize?' . http_build_query($params) . '#wechat_redirect';
155
    }
156
157
    /**
158
     * 第三方根据code获取企业成员信息.
159
     *
160
     * @param string $code
161
     *
162
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
163
     *
164
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
165
     */
166
    public function getUserInfo3rd(string $code)
167
    {
168
        $params = [
169
            'code'         => $code,
170
            'access_token' => $this->app['suite_access_token']->getToken()['suite_access_token']
171
        ];
172
        return $this->httpPostJson('cgi-bin/service/getuserinfo3rd', $params);
173
    }
174
175
    /**
176
     * 第三方使用user_ticket获取成员详情.
177
     *
178
     * @param string $user_ticket
179
     *
180
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
181
     *
182
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
183
     */
184
    public function getUserDetail3rd(string $user_ticket)
185
    {
186
        $params = [
187
            'user_ticket'  => $user_ticket,
188
            'access_token' => $this->app['suite_access_token']->getToken()['suite_access_token']
189
        ];
190
        return $this->httpPostJson('cgi-bin/service/getuserdetail3rd', $params);
191
    }
192
193
}