基于 xbot 实现微信关键词自动回复

2022-09-01 17:22:23 +08:00
 HanSonJ

基于 xbot 实现微信关键词自动回复

项目链接

https://github.com/xbot-org/demo_keyword_reply

使用

先配置好 xbot 的配置如下,并运行

CALLBACK_URL=http://127.0.0.1:5678
SECRET=xxx
PORT=5557

clone 代码

git clone https://github.com/xbot-org/demo_keyword_reply.git
cd demo_keyword_reply

运行此服务 php -S localhost:5678

效果图

代码

代码很简单,这里贴一下

<?php

$jsonString = file_get_contents("php://input");

$msg = json_decode($jsonString, true);

switch ($msg['type']) {
    case 'MT_RECV_TEXT_MSG':
        if ($msg['data']['msg'] == 'ping') {
            sendText($msg['data']['from_wxid'], 'pong');
        } elseif ($msg['data']['msg'] == '123') {
            sendText($msg['data']['from_wxid'], '456');
        }
}

echo '{}';

function sendText($wxid, $content) {
    post(json_encode([
        'client_id' => 1,
        'is_sync' => 1,
        'data' => [
            'to_wxid' => $wxid,
            'content' => $content,
        ],
        'type' => 'MT_SEND_TEXTMSG',
    ]));
}

function post($data) {
    $opts = array('http' =>
        array(
            'method'  => 'POST',
            'header'  => 'Content-Type: application/json',
            'content' => $data
        )
    );

    $context  = stream_context_create($opts);

    file_get_contents('http://127.0.0.1:5557', false, $context);
}

xbot 文档

https://www.apifox.cn/apidoc/shared-71b9855b-693c-48fc-858b-cde2c5afe5a8

1998 次点击
所在节点    分享创造
8 条回复
prudence
2022-09-01 18:09:12 +08:00
这种都不敢上大号,谁知道会不会泄露什么数据信息,当然我也没啥见不得人
HanSonJ
2022-09-01 18:11:38 +08:00
@prudence #1 不是登录云服务的,是在你自己电脑上使用的
Yzh361
2022-09-01 21:43:31 +08:00
我还实现了机器人自动对话…
yhtbiy
2022-09-02 09:38:51 +08:00
直接说怎么卖
avenger
2022-09-02 12:24:38 +08:00
vbot 都有 api 了,赞
chenzhe
2022-09-02 14:07:01 +08:00
@avenger 活捉一只也成陈老板
codingBug
2022-09-02 22:17:48 +08:00
不开源不敢用啊
mumu
2022-09-04 02:16:53 +08:00
看着是广告啊

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/877057

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX