Blogger Information
Blog 20
fans 0
comment 0
visits 10792
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
easywechat实现微信接入并不同消息回复+根据项目提供数据字典,对应建库建表,练习SQL语句。
麦兜的故事
Original
951 people have browsed it

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

  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' => 'wx705529471efe4bf8',
  9. 'secret' => '211da643597922a04ff9e1fca224af1d',
  10. 'token' => 'phplove111',
  11. 'response_type' => 'array',
  12. //...
  13. ];
  14. $app = Factory::officialAccount($config);
  15. // $app->auto_reply->current();
  16. $app->server->push(function ($message) {
  17. switch ($message['MsgType']) {
  18. case 'text':
  19. if (preg_match('/您好/S', $message['Content'])) {
  20. return new Text('客服在线时间08:00~18:00');
  21. } else {
  22. $items = [
  23. new NewsItem([
  24. 'title' => '【普洱茶】降糖,居然让我们越喝越胖!',
  25. 'description' => '你们去年磕的cp,今年已经凉透了,但是无糖饮料却从去年火到了今年,降糖你还相信吗?',
  26. 'url' => 'https://baidu.com',
  27. 'image' => 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Finews.gtimg.com%2Fnewsapp_bt%2F0%2F13906082969%2F1000&refer=http%3A%2F%2Finews.gtimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1633314966&t=10e1a37b4f41e20ded0b5278d7a04e7e',
  28. // ...
  29. ]),
  30. ];
  31. return new News($items);
  32. }
  33. case 'event':
  34. if ($message['Event'] == 'subscribe') {
  35. return '你这么好看,关注我不迷路!';
  36. }
  37. case 'image':
  38. return '什么图片,放大我看看';
  39. }
  40. });
  41. // $text = new Text('您好!overtrue。');
  42. $response = $app->server->serve();
  43. // 将响应输出
  44. $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