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

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

项目链接

github.com/xbot-org/demo_keyword_r...

使用

先配置好 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

效果图

1662022320_1_.png

代码

代码很简单,这里贴一下

<?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 文档

www.apifox.cn/apidoc/shared-71b985...

本作品采用《CC 协议》,转载必须注明作者和本文链接
❤️ 微信生态自动智能化方案加微信:hansonskr ❤️ 备注:vbot
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
讨论数量: 5

个微?

1年前 评论
Hanson (楼主) 1年前

我记得你以前的那个微信机器人不能用了么- - 需要web微信支持才可以? 现在也是么。。

1年前 评论
Hanson (楼主) 1年前

这个是怎么收费的?容易被封号嘛?

1年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!