Blogger Information
Blog 43
fans 0
comment 0
visits 30337
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
easywechat的使用
橙絮圆
Original
3419 people have browsed it

easywechat的使用

作业标题:0831作业
作业内容:1、使用easywechat完成微信接入,并且实现对接收不同消息的回复。 2、选作:根据项目提供数据字典,对应建库建表,练习SQL语句。


  1. <?php
  2. include './vendor/autoload.php';
  3. use EasyWeChat\Factory;
  4. use EasyWeChat\Kernel\Messages\News;
  5. use EasyWeChat\Kernel\Messages\NewsItem;
  6. $config = [
  7. 'app_id' => 'wx46d15e45a95d17e7',
  8. 'secret' => 'b43d2a11e9790003d902448769065a0d',
  9. 'token' => 'phplove',
  10. 'response_type' => 'array',
  11. //...
  12. ];
  13. //接收用户的消息类型
  14. $app = Factory::officialAccount($config);
  15. $app->server->push(function ($message) {
  16. switch($message['MsgType']) {
  17. case 'text':
  18. if(preg_match('/你/S',$message['Content'])){
  19. return '你去哪里了,我找到你了';
  20. }else{
  21. return '你好1111';
  22. }
  23. case 'event':
  24. //事件 关注事件
  25. if(($message['Event']=='subscribe')){
  26. return '感谢关注';
  27. }
  28. case 'image':
  29. $items = [
  30. new NewsItem([
  31. 'title' => '有你的故事',
  32. 'description' => '有你真好',
  33. 'url' => 'http://www.php.cn',
  34. 'image' => 'https://www.php.cn/static/images/index_yunv.jpg',
  35. // ...
  36. ]),
  37. ];
  38. $news = new News($items);
  39. return $news;
  40. }
  41. });
  42. $response = $app->server->serve();
  43. // 将响应输出
  44. $response->send();exit; // Laravel 里请使用:return $response;

发送图片回复图片消息
发送图片

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post