1 Star 0 Fork 205

OWES / wechat-robot

forked from hellokaton / wechat-robot 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

wechat-api

wechat-api 是微信个人号的Java版本API,让个人号具备更多能力,提供方便的接口调用。

在线文档

@biezhi on zhihu

特性

  • 使用简单,引入依赖即可
  • 支持本地图片和终端输出二维码
  • 本地自动登录
  • 支持文本、图片、视频、撤回消息等
  • 支持发送文本、图片、附件
  • 注解绑定消息监听
  • 群聊、单聊支持
  • 添加好友验证
  • 撤回消息获取
  • JDK7+

使用

本地开发的同学请先安装 lombok 插件并确保你的JDK环境是1.7+

引入 maven 依赖

<dependency>
    <groupId>io.github.biezhi</groupId>
    <artifactId>wechat-api</artifactId>
    <version>1.0.6</version>
</dependency>

构建自己的小机器人

public class HelloBot extends WeChatBot {
    
    public HelloBot(Config config) {
        super(config);
    }
    
    @Bind(msgType = MsgType.TEXT)
    public void handleText(WeChatMessage message) {
        if (StringUtils.isNotEmpty(message.getName())) {
            log.info("接收到 [{}] 的消息: {}", message.getName(), message.getText());
            this.sendMsg(message.getFromUserName(), "自动回复: " + message.getText());
        }
    }
    
    public static void main(String[] args) {
        new HelloBot(Config.me().autoLogin(true).showTerminal(true)).start();
    }
    
}

Bot API

/**
 * 给文件助手发送消息
 *
 * @param msg 消息内容
 * @return 发送是否成功
 */
boolean sendMsgToFileHelper(String msg);

/**
 * 给某个用户发送消息
 *
 * @param name 用户UserName
 * @param msg  消息内容
 * @return 发送是否成功
 */
boolean sendMsg(String name, String msg);

/**
 * 根据名称发送消息
 *
 * @param name 备注或昵称,精确匹配
 * @param msg  消息内容
 * @return 发送是否成功
 */
boolean sendMsgByName(String name, String msg);

/**
 * 给某个用户发送图片消息
 *
 * @param name    用户UserName
 * @param imgPath 图片路径
 * @return 发送是否成功
 */
boolean sendImg(String name, String imgPath);

/**
 * 根据名称发送图片消息
 *
 * @param name    备注或昵称,精确匹配
 * @param imgPath 图片路径
 * @return 发送是否成功
 */
boolean sendImgName(String name, String imgPath);

/**
 * 给用户发送文件
 *
 * @param name     用户UserName
 * @param filePath 文件路径
 * @return 发送是否成功
 */
boolean sendFile(String name, String filePath);

/**
 * 根据名称发送文件消息
 *
 * @param name     备注或昵称,精确匹配
 * @param filePath 文件路径
 * @return 发送是否成功
 */
boolean sendFileName(String name, String filePath);

更多API见文档

TODO

  1. 接收位置
  2. 撤回消息查看
  3. 发送文件消息
  4. 多线程处理消息

开源协议

MIT

MIT License Copyright (c) 2018 王爵nice (biezhi) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Java版微信普通号机器人 展开 收起
Java
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/h5app/wechat-robot.git
git@gitee.com:h5app/wechat-robot.git
h5app
wechat-robot
wechat-robot
master

搜索帮助