easywechat实现微信接入并不同消息回复+根据项目提供数据字典,对应建库建表,练习SQL语句。
16lz
2021-09-05
1、使用easywechat完成微信接入,并且实现对接收不同消息的回复。
<?php
include './vendor/autoload.php';
use EasyWeChat\Factory;
use EasyWeChat\Kernel\Messages\Text;
use EasyWeChat\Kernel\Messages\News;
use EasyWeChat\Kernel\Messages\NewsItem;
$config = [
'app_id' => 'wx705529471efe4bf8',
'secret' => '211da643597922a04ff9e1fca224af1d',
'token' => 'phplove111',
'response_type' => 'array',
//...
];
$app = Factory::officialAccount($config);
// $app->auto_reply->current();
$app->server->push(function ($message) {
switch ($message['MsgType']) {
case 'text':
if (preg_match('/您好/S', $message['Content'])) {
return new Text('客服在线时间08:00~18:00');
} else {
$items = [
new NewsItem([
'title' => '【普洱茶】降糖,居然让我们越喝越胖!',
'description' => '你们去年磕的cp,今年已经凉透了,但是无糖饮料却从去年火到了今年,降糖你还相信吗?',
'url' => 'https://baidu.com',
'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',
// ...
]),
];
return new News($items);
}
case 'event':
if ($message['Event'] == 'subscribe') {
return '你这么好看,关注我不迷路!';
}
case 'image':
return '什么图片,放大我看看';
}
});
// $text = new Text('您好!overtrue。');
$response = $app->server->serve();
// 将响应输出
$response->send();
更多相关文章
- 实战原生微信接入和消息回复
- 实现原生微信接入 当用户关注/发送消息时对应内容回应
- 使用easywechat完成微信接入,并且实现对接收不同消息的回复
- python全国快递查询接口和电子面单打印接口,一次接入全国快递公
- php快递查询接口,一次接入顺丰、京东、申通、圆通、韵达、中通、
- php电子面单接口,可一次性接入全国45家主流快递~顺丰、京东、邮
- PHP全国快递寄件接口,1天接入四通一达,极兔,宅急送,德邦,京东,天
- 一次性接入顺丰,京东,申通,圆通,中通,韵达,天天,百世,德邦快递接
- 京东,顺丰,,百世,天天,德邦,四通一达快递接口java-demo,一次性接