正在显示
2 个修改的文件
包含
110 行增加
和
0 行删除
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 | +} |
app/portal/controller/WechatController.php
0 → 100644
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 | +/** | ||
17 | + * 微信服务器接口 | ||
18 | + * Class WechatController | ||
19 | + * @package app\portal\controller | ||
20 | + */ | ||
21 | +class WechatController | ||
22 | +{ | ||
23 | + | ||
24 | + public function index(){ | ||
25 | + $app=new Application(config('wechat_config')); | ||
26 | + $server = $app->server; | ||
27 | + | ||
28 | + $server->setMessageHandler(function ($message) { | ||
29 | + switch ($message->MsgType) { | ||
30 | + case 'event': | ||
31 | + switch ($message->Event) { | ||
32 | + case 'subscribe': | ||
33 | + return '欢迎关注'; | ||
34 | + break; | ||
35 | + case 'CLICK': | ||
36 | + $content = $message->EventKey; // 获取key | ||
37 | + return '收到CLICK事件:'.$content; | ||
38 | + break; | ||
39 | + default: | ||
40 | + return '收到event消息'; | ||
41 | + break; | ||
42 | + } | ||
43 | + break; | ||
44 | + case 'text': | ||
45 | + return '收到文字消息'; | ||
46 | + break; | ||
47 | + default: | ||
48 | + return '收到其它消息'; | ||
49 | + break; | ||
50 | + } | ||
51 | + }); | ||
52 | + | ||
53 | + $response = $server->serve(); | ||
54 | + | ||
55 | + $response->send(); | ||
56 | + } | ||
57 | + | ||
58 | +} |
-
请 注册 或 登录 后发表评论