批改状态:合格
老师批语:
作业标题:0831作业
作业内容:1、使用easywechat完成微信接入,并且实现对接收不同消息的回复。 2、选作:根据项目提供数据字典,对应建库建表,练习SQL语句。
<?phpinclude './vendor/autoload.php';use EasyWeChat\Factory;use EasyWeChat\Kernel\Messages\News;use EasyWeChat\Kernel\Messages\NewsItem;$config = ['app_id' => 'wx46d15e45a95d17e7','secret' => 'b43d2a11e9790003d902448769065a0d','token' => 'phplove','response_type' => 'array',//...];//接收用户的消息类型$app = Factory::officialAccount($config);$app->server->push(function ($message) {switch($message['MsgType']) {case 'text':if(preg_match('/你/S',$message['Content'])){return '你去哪里了,我找到你了';}else{return '你好1111';}case 'event'://事件 关注事件if(($message['Event']=='subscribe')){return '感谢关注';}case 'image':$items = [new NewsItem(['title' => '有你的故事','description' => '有你真好','url' => 'http://www.php.cn','image' => 'https://www.php.cn/static/images/index_yunv.jpg',// ...]),];$news = new News($items);return $news;}});$response = $app->server->serve();// 将响应输出$response->send();exit; // Laravel 里请使用:return $response;
发送图片回复图片消息
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号