Blogger Information
Blog 34
fans 0
comment 0
visits 20661
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
EasyWeChat的简单使用
小庄
Original
1056 people have browsed it

  1. <?php
  2. include './vendor/autoload.php';
  3. use EasyWeChat\Factory;
  4. use EasyWeChat\Kernel\Messages\News;
  5. use EasyWeChat\Kernel\Messages\NewsItem;
  6. use EasyWeChat\Kernel\Messages\Video;
  7. $config = [
  8. 'app_id' => 'wxbfb89aceed40db90',
  9. 'secret' => '0d67ecaf8d3f1f8d560e80384d2f793a',
  10. 'token' => 'myphp',
  11. 'response_type' => 'array',
  12. //...
  13. ];
  14. $app = Factory::officialAccount($config);
  15. $app->server->push(function ($message) {
  16. switch ($message['MsgType']) {
  17. case 'event':
  18. return '感谢你的关注!!';
  19. break;
  20. case 'text':
  21. return '收到文字消息';
  22. break;
  23. case 'image':
  24. $items = [
  25. new NewsItem([
  26. 'title' => '想念灭绝的第一天',
  27. 'description' => '想的抓狂,睡不着。。。',
  28. 'url' => 'https://php.cn',
  29. 'image' => 'https://img.php.cn/upload/course/000/000/001/60b5cd439a6b7169.png',
  30. // ...
  31. ]),
  32. ];
  33. return new News($items);
  34. break;
  35. case 'voice':
  36. return '收到语音消息';
  37. break;
  38. case 'video':
  39. return '收到视频消息';
  40. break;
  41. case 'location':
  42. return '收到坐标消息';
  43. break;
  44. case 'link':
  45. return '收到链接消息';
  46. break;
  47. case 'file':
  48. return '收到文件消息';
  49. // ... 其它消息
  50. default:
  51. return '收到其它消息';
  52. break;
  53. }
  54. // ...
  55. });
  56. $response = $app->server->serve();
  57. // 将响应输出
  58. $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