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

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


不同消息的回复效果

" class="reference-link">

代码演示

  1. <?php
  2. include './vendor/autoload.php';
  3. use EasyWeChat\Factory;
  4. use EasyWeChat\Kernel\Messages\Text;
  5. use EasyWeChat\Kernel\Messages\News;
  6. use EasyWeChat\Kernel\Messages\NewsItem;
  7. $config = [
  8. 'app_id' => 'wxe0f19bf6cab1abec',
  9. 'secret' => 'eac7d4bf4b87933aca3c5ebcaba55578',
  10. 'token' => 'phpliqi',
  11. 'response_type' => 'array',
  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 new Text('欢迎来到我的订阅号');
  22. }
  23. case 'event':
  24. if($message['event'] == 'subscribe'){
  25. return '非常感谢您的关注';
  26. }
  27. case 'image':
  28. $items = [
  29. new NewsItem([
  30. 'title' => '琅琊榜',
  31. 'description' => '梅长苏(胡歌饰)本远在江湖,却名动帝辇。江湖传言:“江左梅郎
  32. ,麒麟之才,得之可得天下。
  33. ”作为天下第一大帮“江左盟”的首领,梅长苏“梅郎”之名响誉江湖。然而
  34. 有着江湖至尊地位的梅长苏,却是一个病弱青年、弱不禁风,背负着十多年
  35. 前巨大的冤案与血海深仇,就连身世背后也隐藏着巨大的秘密。',
  36. 'url' => 'https://baike.baidu.com/item/%E7%90%85%E7%90%8A%E6%A6%9C/12700172?fr=aladdin#1',
  37. 'image' => 'https://bkimg.cdn.bcebos.com/pic/c8177f3e6709c93de9322645973df8dcd00054bb?x-bce-process=image/resize,m_lfit,w_1280,limit_1/format,f_auto'
  38. // ...
  39. ]),
  40. ];
  41. return new News($items);
  42. }
  43. });
  44. $response = $app->server->serve();
  45. // 将响应输出
  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