|
6 | 6 | use Illuminate\Foundation\Application as LaravelApplication; |
7 | 7 | use Illuminate\Support\ServiceProvider as LaravelServiceProvider; |
8 | 8 | use Laravel\Lumen\Application as LumenApplication; |
| 9 | +use Overtrue\Socialite\User as SocialiteUser; |
9 | 10 |
|
10 | 11 | class ServiceProvider extends LaravelServiceProvider |
11 | 12 | { |
@@ -35,13 +36,20 @@ protected function setupConfig() |
35 | 36 | { |
36 | 37 | $source = realpath(__DIR__.'/config.php'); |
37 | 38 |
|
38 | | - if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) { |
39 | | - $this->publishes([ |
40 | | - $source => config_path('wechat.php'), |
41 | | - ]); |
| 39 | + if ($this->app instanceof LaravelApplication) { |
| 40 | + |
| 41 | + if ($this->app->runningInConsole()) { |
| 42 | + $this->publishes([ |
| 43 | + $source => config_path('wechat.php'), |
| 44 | + ]); |
| 45 | + } |
| 46 | + |
| 47 | + // 创建模拟授权 |
| 48 | + $this->setUpMockAuthUser(); |
42 | 49 | } elseif ($this->app instanceof LumenApplication) { |
43 | 50 | $this->app->configure('wechat'); |
44 | 51 | } |
| 52 | + |
45 | 53 | $this->mergeConfigFrom($source, 'wechat'); |
46 | 54 | } |
47 | 55 |
|
@@ -72,4 +80,24 @@ public function provides() |
72 | 80 | { |
73 | 81 | return ['wechat', 'EasyWeChat\\Foundation\\Application']; |
74 | 82 | } |
| 83 | + |
| 84 | + /** |
| 85 | + * 创建模拟登录 |
| 86 | + */ |
| 87 | + protected function setUpMockAuthUser() |
| 88 | + { |
| 89 | + $user = config('wechat.mock_user'); |
| 90 | + |
| 91 | + if (is_array($user) && !empty($user['openid']) && config('wechat.enable_mock')) { |
| 92 | + $user = new SocialiteUser([ |
| 93 | + 'id' => array_get($user, 'openid'), |
| 94 | + 'name' => array_get($user, 'nickname'), |
| 95 | + 'nickname' => array_get($user, 'nickname'), |
| 96 | + 'avatar' => array_get($user, 'headimgurl'), |
| 97 | + 'email' => null, |
| 98 | + ]); |
| 99 | + |
| 100 | + session(['wechat.oauth_user' => $user]); |
| 101 | + } |
| 102 | + } |
75 | 103 | } |
0 commit comments