Blogger Information
Blog 20
fans 0
comment 0
visits 12324
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
使用easywechat完成微信接入,并且实现对接收不同消息的回复
缘亦
Original
969 people have browsed it

使用easywechat完成微信接入,并且实现对接收不同消息的回复

首先从composer中下载easywechat,引入自动加载器
备注(app_id和开发者密码用11111替换掉了,以免暴露)

  1. <?php
  2. require __DIR__.'/vendor/autoload.php';
  3. use EasyWeChat\Factory;
  4. $config = [
  5. 'app_id' => '111111111111111',
  6. 'secret' => '11111111111111111111111111111',
  7. 'token' => 'yuanyiruciphp',
  8. 'response_type' => 'array',
  9. //...
  10. ];
  11. $app = Factory::officialAccount( $config );
  12. $response = $app->server->serve();
  13. $app->server->push(function ($message) {
  14. switch ($message['MsgType']) {
  15. case 'event':
  16. return '收到事件消息';
  17. break;
  18. case 'text':
  19. return '收到文字消息';
  20. break;
  21. case 'image':
  22. return '收到图片消息';
  23. break;
  24. case 'voice':
  25. return '收到语音消息';
  26. break;
  27. case 'video':
  28. return '收到视频消息';
  29. break;
  30. case 'location':
  31. return '收到坐标消息';
  32. break;
  33. case 'link':
  34. return '收到链接消息';
  35. break;
  36. case 'file':
  37. return '收到文件消息';
  38. // ... 其它消息
  39. default:
  40. return '收到其它消息';
  41. break;
  42. }
  43. // ...
  44. });
  45. $response = $app->server->serve();
  46. $response->send();
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