File tree Expand file tree Collapse file tree 7 files changed +200
-0
lines changed Expand file tree Collapse file tree 7 files changed +200
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Overtrue \LaravelWechat \Controllers ;
4+
5+ use EasyWeChat \Foundation \Application ;
6+ use EasyWeChat \Support \Arr ;
7+ use Illuminate \Support \Facades \Event ;
8+ use App \Http \Controllers \Controller as LaravelController ;
9+ use Overtrue \LaravelWechat \Events \OpenPlatform as Events ;
10+
11+ class EasyWeChatController extends LaravelController
12+ {
13+ /**
14+ * Events.
15+ *
16+ * @var array
17+ */
18+ protected $ events = [
19+ 'authorized ' => Events \Authorized::class,
20+ 'unauthorized ' => Events \UnAuthorized::class,
21+ 'updateauthorized ' => Events \UpdateAuthorized::class,
22+ ];
23+
24+ /**
25+ * Handle request and fire events.
26+ *
27+ * @return string
28+ */
29+ public function openPlatformServe ()
30+ {
31+ $ app = new Application (config ('wechat ' ));
32+
33+ $ server = $ app ->open_platform ->server ;
34+
35+ list ($ name , $ event ) = $ server ->listServe ();
36+
37+ if ($ class = Arr::get ($ this ->events , $ name )) {
38+ Event::fire (new $ class ($ event ));
39+ }
40+
41+ return 'success ' ;
42+ }
43+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Overtrue \LaravelWechat \Events \OpenPlatform ;
4+
5+ use EasyWeChat \Support \Collection ;
6+ use Illuminate \Queue \SerializesModels ;
7+
8+ class Authorized
9+ {
10+ use SerializesModels;
11+
12+ public $ message ;
13+
14+ /**
15+ * Create a new event instance.
16+ *
17+ * @param \EasyWeChat\Support\Collection $message
18+ */
19+ public function __construct (Collection $ message )
20+ {
21+ $ this ->message = $ message ;
22+ }
23+
24+ /**
25+ * Get the channels the event should be broadcast on.
26+ *
27+ * @return array
28+ */
29+ public function broadcastOn ()
30+ {
31+ return [];
32+ }
33+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Overtrue \LaravelWechat \Events \OpenPlatform ;
4+
5+ use EasyWeChat \Support \Collection ;
6+ use Illuminate \Queue \SerializesModels ;
7+
8+ class Unauthorized
9+ {
10+ use SerializesModels;
11+
12+ public $ message ;
13+
14+ /**
15+ * Create a new event instance.
16+ *
17+ * @param \EasyWeChat\Support\Collection $message
18+ */
19+ public function __construct (Collection $ message )
20+ {
21+ $ this ->message = $ message ;
22+ }
23+
24+ /**
25+ * Get the channels the event should be broadcast on.
26+ *
27+ * @return array
28+ */
29+ public function broadcastOn ()
30+ {
31+ return [];
32+ }
33+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Overtrue \LaravelWechat \Events \OpenPlatform ;
4+
5+ use EasyWeChat \Support \Collection ;
6+ use Illuminate \Queue \SerializesModels ;
7+
8+ class UpdateAuthorized
9+ {
10+ use SerializesModels;
11+
12+ public $ message ;
13+
14+ /**
15+ * Create a new event instance.
16+ *
17+ * @param \EasyWeChat\Support\Collection $message
18+ */
19+ public function __construct (Collection $ message )
20+ {
21+ $ this ->message = $ message ;
22+ }
23+
24+ /**
25+ * Get the channels the event should be broadcast on.
26+ *
27+ * @return array
28+ */
29+ public function broadcastOn ()
30+ {
31+ return [];
32+ }
33+ }
Original file line number Diff line number Diff line change 66use Illuminate \Foundation \Application as LaravelApplication ;
77use Illuminate \Support \ServiceProvider as LaravelServiceProvider ;
88use Laravel \Lumen \Application as LumenApplication ;
9+ use Overtrue \LaravelWechat \ServiceProviders \RouteServiceProvider ;
910use Overtrue \Socialite \User as SocialiteUser ;
1011
1112class ServiceProvider extends LaravelServiceProvider
@@ -25,6 +26,10 @@ class ServiceProvider extends LaravelServiceProvider
2526 public function boot ()
2627 {
2728 $ this ->setupConfig ();
29+
30+ if ($ this ->isEnableOpenPlatform ()) {
31+ $ this ->app ->register (RouteServiceProvider::class);
32+ }
2833 }
2934
3035 /**
@@ -101,4 +106,24 @@ protected function setUpMockAuthUser()
101106 session (['wechat.oauth_user ' => $ user ]);
102107 }
103108 }
109+
110+ /**
111+ * Check open platform is configured.
112+ *
113+ * @return bool
114+ */
115+ private function isEnableOpenPlatform ()
116+ {
117+ return $ this ->config ()->has ('wechat.open_platform ' );
118+ }
119+
120+ /**
121+ * Get config value by key
122+ *
123+ * @return \Illuminate\Config\Repository
124+ */
125+ private function config ()
126+ {
127+ return $ this ->app ['config ' ];
128+ }
104129}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Overtrue \LaravelWechat \ServiceProviders ;
4+
5+ use Illuminate \Contracts \Routing \Registrar as Router ;
6+ use Illuminate \Foundation \Support \Providers \RouteServiceProvider as LaravelRouteServiceProvider ;
7+
8+ class RouteServiceProvider extends LaravelRouteServiceProvider
9+ {
10+ /**
11+ * Define the routes for the application.
12+ *
13+ * @param \Illuminate\Contracts\Routing\Registrar $router
14+ */
15+ public function map (Router $ router )
16+ {
17+ $ router ->group ([
18+ 'namespace ' => 'Overtrue\LaravelWechat\Controllers '
19+ ], function (Router $ router ) {
20+ $ router ->post (config ('wechat.open_platform.serve_url ' ), 'EasyWeChatController@openPlatformServe ' );
21+ });
22+ }
23+ }
Original file line number Diff line number Diff line change 2121 'token ' => env ('WECHAT_TOKEN ' , 'your-token ' ), // Token
2222 'aes_key ' => env ('WECHAT_AES_KEY ' , '' ), // EncodingAESKey
2323
24+ /**
25+ * 开放平台第三方平台配置信息
26+ */
27+ 'open_platform ' => [
28+ /**
29+ * 事件推送URL
30+ */
31+ 'serve_url ' => env ('WECHAT_OPEN_PLATFORM_SERVE_URL ' , 'serve ' ),
32+ ],
33+
2434 /*
2535 * 日志配置
2636 *
You can’t perform that action at this time.
0 commit comments