2
0
mirror of https://gitee.com/hotlcc/wechat4j.git synced 2025-06-06 10:34:07 +08:00
2018-08-17 22:28:14 +08:00
2018-08-17 21:05:09 +08:00
2018-08-17 21:47:32 +08:00
2018-07-22 19:00:30 +08:00
2018-08-15 16:25:55 +08:00
2018-08-17 22:28:14 +08:00

wechat4j

一个基于Web微信API的Java版微信客户端

作者Allen

码云主页:https://gitee.com/hotlcc

gitee toutiao @Allen on weibo License

Web微信API文档

详见:Web微信API文档

简单使用

WebWeixinApi api = new WebWeixinApi();
// 实例化微信客户端
Wechat wechat = new Wechat();
wechat.setWebWeixinApi(api);
// 自动登录
wechat.autoLogin();

发送消息

文本消息

// 通过userName发送文本消息
public JSONObject sendText(String content, String userName);
// 通过昵称发送消息
public JSONObject sendTextToNickName(String content, String nickName);
// 通过备注名发送消息
public JSONObject sendTextToRemarkName(String content, String remarkName);

目前仅支持发送文本消息,更多消息类型支持尽请期待。

消息处理器

通过在实例化时添加消息处理器来处理接收到的消息
消息处理器需要实现ReceivedMsgHandler接口

wechat.addReceivedMsgHandler(new ReceivedMsgHandler() {
    @Override
    public void handleAllType(Wechat wechat, ReceivedMsg msg) {
        UserInfo contact = wechat.getContactByUserName(false, msg.getFromUserName());
        String name = StringUtil.isEmpty(contact.getRemarkName()) ? contact.getNickName() : contact.getRemarkName();
        System.out.println(name + ": " + msg.getContent());
        }
    });
Description
No description provided
Readme 199 KiB
Languages
Java 100%