Giter Site home page Giter Site logo

wechat-api's Introduction

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

wechat-api's People

Contributors

hellokaton avatar avrilmaomao avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.