2
2
3
3
namespace Overtrue \LaravelWechat ;
4
4
5
- use EasyWeChat \Foundation \Application as EasyWeChatApplication ;
5
+ use EasyWeChat \Foundation \Application as EasyWeChat ;
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 \LaravelWechat \Providers \ RouteServiceProvider ;
9
+ use Overtrue \LaravelWechat \Routing \ Router ;
10
10
use Overtrue \Socialite \User as SocialiteUser ;
11
11
12
12
class ServiceProvider extends LaravelServiceProvider
@@ -20,7 +20,9 @@ public function boot()
20
20
{
21
21
$ this ->setupConfig ();
22
22
23
- $ this ->app ->register (RouteServiceProvider::class);
23
+ if ($ this ->config ('route.enabled ' )) {
24
+ $ this ->registerRoutes ();
25
+ }
24
26
}
25
27
26
28
/**
@@ -55,18 +57,18 @@ protected function setupConfig()
55
57
*/
56
58
public function register ()
57
59
{
58
- $ this ->app ->singleton (EasyWeChatApplication ::class, function ($ laravelApp ) {
59
- $ app = new EasyWeChatApplication (config ('wechat ' ));
60
+ $ this ->app ->singleton (EasyWeChat ::class, function ($ app ) {
61
+ $ easywechat = new EasyWeChat (config ('wechat ' ));
60
62
if (config ('wechat.use_laravel_cache ' )) {
61
- $ app ->cache = new CacheBridge ();
63
+ $ easywechat ->cache = new CacheBridge ();
62
64
}
63
- $ app ->server ->setRequest ($ laravelApp ['request ' ]);
65
+ $ easywechat ->server ->setRequest ($ app ['request ' ]);
64
66
65
- return $ app ;
67
+ return $ easywechat ;
66
68
});
67
69
68
- $ this ->app ->alias (EasyWeChatApplication ::class, 'wechat ' );
69
- $ this ->app ->alias (EasyWeChatApplication ::class, 'easywechat ' );
70
+ $ this ->app ->alias (EasyWeChat ::class, 'wechat ' );
71
+ $ this ->app ->alias (EasyWeChat ::class, 'easywechat ' );
70
72
}
71
73
72
74
/**
@@ -89,4 +91,42 @@ protected function setUpMockAuthUser()
89
91
session (['wechat.oauth_user ' => $ user ]);
90
92
}
91
93
}
94
+
95
+ /**
96
+ * Register routes.
97
+ */
98
+ protected function registerRoutes ()
99
+ {
100
+ $ router = new Router ($ this ->app );
101
+
102
+ $ router ->group ($ this ->routeAttributes (), function () use ($ router ) {
103
+ $ router ->any ($ this ->config ('route.open_platform_serve_url ' ), 'OpenPlatformController@index ' );
104
+ });
105
+ }
106
+
107
+
108
+ /**
109
+ * Get Route attributes.
110
+ *
111
+ * @return array
112
+ */
113
+ public function routeAttributes ()
114
+ {
115
+ return array_merge ($ this ->config ('route.attributes ' , []), [
116
+ 'namespace ' => '\\Overtrue \\LaravelWechat \\Controllers ' ,
117
+ ]);
118
+ }
119
+
120
+ /**
121
+ * Get config value by key.
122
+ *
123
+ * @param string $key
124
+ * @param mixed|null $default
125
+ *
126
+ * @return mixed
127
+ */
128
+ private function config ($ key , $ default = null )
129
+ {
130
+ return $ this ->app ->make ('config ' )->get ("wechat. {$ key }" , $ default );
131
+ }
92
132
}
0 commit comments