Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:
首先从composer中下载easywechat,引入自动加载器
备注(app_id和开发者密码用11111替换掉了,以免暴露)
<?php
require __DIR__.'/vendor/autoload.php';
use EasyWeChat\Factory;
$config = [
'app_id' => '111111111111111',
'secret' => '11111111111111111111111111111',
'token' => 'yuanyiruciphp',
'response_type' => 'array',
//...
];
$app = Factory::officialAccount( $config );
$response = $app->server->serve();
$app->server->push(function ($message) {
switch ($message['MsgType']) {
case 'event':
return '收到事件消息';
break;
case 'text':
return '收到文字消息';
break;
case 'image':
return '收到图片消息';
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();