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
|
|
|
/** |
13
|
|
|
* OpenPlatform.php. |
14
|
|
|
* |
15
|
|
|
* Part of Overtrue\WeChat. |
16
|
|
|
* |
17
|
|
|
* For the full copyright and license information, please view the LICENSE |
18
|
|
|
* file that was distributed with this source code. |
19
|
|
|
* |
20
|
|
|
* @author mingyoung <[email protected]> |
21
|
|
|
* @copyright 2016 |
22
|
|
|
* |
23
|
|
|
* @see https://github.com/overtrue |
24
|
|
|
* @see http://overtrue.me |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
namespace EasyWeChat\OpenPlatform; |
28
|
|
|
|
29
|
|
|
use EasyWeChat\Support\Traits\PrefixedContainer; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Class OpenPlatform. |
33
|
|
|
* |
34
|
|
|
* @property \EasyWeChat\OpenPlatform\Api\BaseApi $api |
35
|
|
|
* @property \EasyWeChat\OpenPlatform\Api\PreAuthorization $pre_auth |
36
|
|
|
* @property \EasyWeChat\OpenPlatform\Guard $server |
37
|
|
|
* @property \EasyWeChat\OpenPlatform\AccessToken $access_token |
38
|
|
|
* |
39
|
|
|
* @method \EasyWeChat\Support\Collection getAuthorizationInfo($authCode = null) |
40
|
|
|
* @method \EasyWeChat\Support\Collection getAuthorizerToken($appId, $refreshToken) |
41
|
|
|
* @method \EasyWeChat\Support\Collection getAuthorizerInfo($authorizerAppId) |
42
|
|
|
* @method \EasyWeChat\Support\Collection getAuthorizerOption($authorizerAppId, $optionName) |
43
|
|
|
* @method \EasyWeChat\Support\Collection setAuthorizerOption($authorizerAppId, $optionName, $optionValue) |
44
|
|
|
*/ |
45
|
|
|
class OpenPlatform |
46
|
|
|
{ |
47
|
|
|
use PrefixedContainer; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Create an instance of the EasyWeChat for the given authorizer. |
51
|
|
|
* |
52
|
|
|
* @param string $appId Authorizer AppId |
53
|
|
|
* @param string $refreshToken Authorizer refresh-token |
54
|
|
|
* |
55
|
|
|
* @return \EasyWeChat\Foundation\Application |
56
|
|
|
*/ |
57
|
1 |
|
public function createAuthorizer($appId, $refreshToken) |
58
|
|
|
{ |
59
|
1 |
|
$this->fetch('authorization') |
60
|
1 |
|
->setAuthorizerAppId($appId) |
61
|
1 |
|
->setAuthorizerRefreshToken($refreshToken); |
62
|
|
|
|
63
|
1 |
|
$application = $this->fetch('app'); |
64
|
1 |
|
$application['access_token'] = $this->fetch('authorizer_access_token'); |
65
|
1 |
|
$application['oauth'] = $this->fetch('oauth'); |
66
|
|
|
|
67
|
1 |
|
return $application; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Quick access to the base-api. |
72
|
|
|
* |
73
|
|
|
* @param string $method |
74
|
|
|
* @param array $args |
75
|
|
|
* |
76
|
|
|
* @return mixed |
77
|
|
|
*/ |
78
|
|
|
public function __call($method, $args) |
79
|
|
|
{ |
80
|
|
|
return call_user_func_array([$this->api, $method], $args); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|