Completed
Push — master ( bb559d...95b064 )
by Carlos
02:29
created

Client::register()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 7
rs 9.4285
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\OfficialAccount\Account;
13
14
use EasyWeChat\Kernel\ServiceContainer;
15
use EasyWeChat\OpenPlatform\Application;
16
use EasyWeChat\OpenPlatform\Authorizer\Aggregate\Account\Client as BaseClient;
17
18
/**
19
 * Class Client.
20
 *
21
 * @author Keal <[email protected]>
22
 */
23
class Client extends BaseClient
24
{
25
    /**
26
     * @var \EasyWeChat\OpenPlatform\Application
27
     */
28
    protected $component;
29
30
    /**
31
     * Client constructor.
32
     *
33
     * @param \EasyWeChat\Kernel\ServiceContainer  $app
34
     * @param \EasyWeChat\OpenPlatform\Application $component
35
     */
36
    public function __construct(ServiceContainer $app, Application $component)
37
    {
38
        parent::__construct($app);
39
40
        $this->component = $component;
41
    }
42
43
    /**
44
     * 从第三方平台跳转至微信公众平台授权注册页面, 授权注册小程序.
45
     *
46
     * @param string $callbackUrl
47
     * @param bool   $copyWxVerify
48
     *
49
     * @return string
50
     */
51
    public function getFastRegistrationUrl(string $callbackUrl, bool $copyWxVerify = true): string
52
    {
53
        $queries = [
54
            'copy_wx_verify' => $copyWxVerify,
55
            'component_appid' => $this->component['config']['app_id'],
56
            'appid' => $this->app['config']['app_id'],
57
            'redirect_uri' => $callbackUrl,
58
        ];
59
60
        return 'https://mp.weixin.qq.com/cgi-bin/fastregisterauth?'.http_build_query($queries);
61
    }
62
63
    /**
64
     * 小程序快速注册.
65
     *
66
     * @param string $ticket
67
     *
68
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
69
     *
70
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
71
     */
72
    public function register(string $ticket)
73
    {
74
        $params = [
75
            'ticket' => $ticket,
76
        ];
77
78
        return $this->httpPostJson('cgi-bin/account/fastregister', $params);
79
    }
80
}
81