作者 杨育虎

同步

1 -<?php  
2 -// +----------------------------------------------------------------------  
3 -// | bronet [ 以客户为中心 以奋斗者为本 ]  
4 -// +----------------------------------------------------------------------  
5 -// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.  
6 -// +----------------------------------------------------------------------  
7 -// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )  
8 -// +----------------------------------------------------------------------  
9 -// | Author: Powerless < wzxaini9@gmail.com>  
10 -// +----------------------------------------------------------------------  
11 -namespace app\portal\controller;  
12 -  
13 -  
14 -use EasyWeChat\Foundation\Application;  
15 -  
16 -class WechatController  
17 -{  
18 - public function index()  
19 - {  
20 - $app=new Application(config('wechat_config'));  
21 - $server = $app->server;  
22 -  
23 - $server->setMessageHandler(function ($message) {  
24 - switch ($message->MsgType) {  
25 - case 'event':  
26 - switch ($message->Event) {  
27 - case 'subscribe':  
28 - return '欢迎关注';  
29 - break;  
30 - case 'CLICK':  
31 - return 'CLICKCLICK';  
32 - break;  
33 - default:  
34 - return '收到event消息111'.$message->Event;  
35 - break;  
36 - }  
37 - break;  
38 - case 'text':  
39 - return '收到文字消息';  
40 - break;  
41 - default:  
42 - return '收到其它消息';  
43 - break;  
44 - }  
45 - });  
46 -  
47 - $response = $server->serve();  
48 -  
49 - $response->send();  
50 - }  
51 -  
52 -}