Client   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 13
dl 0
loc 57
ccs 13
cts 13
cp 1
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getFastRegistrationUrl() 0 10 1
A register() 0 7 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\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 3
    public function __construct(ServiceContainer $app, Application $component)
37
    {
38 3
        parent::__construct($app);
39
40 3
        $this->component = $component;
41 3
    }
42
43
    /**
44
     * 从第三方平台跳转至微信公众平台授权注册页面, 授权注册小程序.
45
     *
46
     * @param string $callbackUrl
47
     * @param bool   $copyWxVerify
48
     *
49
     * @return string
50
     */
51 1
    public function getFastRegistrationUrl(string $callbackUrl, bool $copyWxVerify = true): string
52
    {
53
        $queries = [
54 1
            'copy_wx_verify' => $copyWxVerify,
55 1
            'component_appid' => $this->component['config']['app_id'],
56 1
            'appid' => $this->app['config']['app_id'],
57 1
            'redirect_uri' => $callbackUrl,
58
        ];
59
60 1
        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
     * @throws \GuzzleHttp\Exception\GuzzleException
72
     */
73 1
    public function register(string $ticket)
74
    {
75
        $params = [
76 1
            'ticket' => $ticket,
77
        ];
78
79 1
        return $this->httpPostJson('cgi-bin/account/fastregister', $params);
80
    }
81
}
82