|
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\Auth; |
|
13
|
|
|
|
|
14
|
|
|
use EasyWeChat\Kernel\BaseClient; |
|
15
|
|
|
use EasyWeChat\Kernel\ServiceContainer; |
|
16
|
|
|
use EasyWeChat\OpenPlatform\Application; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class Client. |
|
20
|
|
|
* |
|
21
|
|
|
* @author mingyoung <[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
|
2 |
|
public function __construct(ServiceContainer $app, Application $component) |
|
37
|
|
|
{ |
|
38
|
2 |
|
parent::__construct($app); |
|
39
|
|
|
|
|
40
|
2 |
|
$this->component = $component; |
|
41
|
2 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Get session info by code. |
|
45
|
|
|
* |
|
46
|
|
|
* @param string $code |
|
47
|
|
|
* |
|
48
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|
49
|
|
|
* |
|
50
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
51
|
|
|
*/ |
|
52
|
1 |
|
public function session(string $code) |
|
53
|
|
|
{ |
|
54
|
|
|
$params = [ |
|
55
|
1 |
|
'appid' => $this->app['config']['app_id'], |
|
56
|
1 |
|
'js_code' => $code, |
|
57
|
1 |
|
'grant_type' => 'authorization_code', |
|
58
|
1 |
|
'component_appid' => $this->component['config']['app_id'], |
|
59
|
1 |
|
'component_access_token' => $this->component['access_token']->getToken()['component_access_token'], |
|
60
|
|
|
]; |
|
61
|
|
|
|
|
62
|
1 |
|
return $this->httpGet('sns/component/jscode2session', $params); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|