Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:
<?php
include './vendor/autoload.php';
use EasyWeChat\Factory;
use EasyWeChat\Kernel\Messages\News;
use EasyWeChat\Kernel\Messages\NewsItem;
use EasyWeChat\Kernel\Messages\Video;
$config = [
'app_id' => 'wxbfb89aceed40db90',
'secret' => '0d67ecaf8d3f1f8d560e80384d2f793a',
'token' => 'myphp',
'response_type' => 'array',
//...
];
$app = Factory::officialAccount($config);
$app->server->push(function ($message) {
switch ($message['MsgType']) {
case 'event':
return '感谢你的关注!!';
break;
case 'text':
return '收到文字消息';
break;
case 'image':
$items = [
new NewsItem([
'title' => '想念灭绝的第一天',
'description' => '想的抓狂,睡不着。。。',
'url' => 'https://php.cn',
'image' => 'https://img.php.cn/upload/course/000/000/001/60b5cd439a6b7169.png',
// ...
]),
];
return new News($items);
break;
case 'voice':
return '收到语音消息';
break;
case 'video':
return '收到视频消息';
break;
case 'location':
return '收到坐标消息';
break;
case 'link':
return '收到链接消息';
break;
case 'file':
return '收到文件消息';
// ... 其它消息
default:
return '收到其它消息';
break;
}
// ...
});
$response = $app->server->serve();
// 将响应输出
$response->send();exit; // Laravel 里请使用:return $response;