mirror of
https://gitee.com/hotlcc/wechat4j.git
synced 2025-06-07 19:14:08 +08:00
更新 README.md
This commit is contained in:
parent
c95cca27d5
commit
bb4e7e2da2
58
README.md
58
README.md
@ -1,7 +1,59 @@
|
|||||||
# wechat4j
|
# wechat4j
|
||||||
|
|
||||||
## 项目介绍
|
> 一个基于Web微信API的Java版微信客户端
|
||||||
一个通过web微信api封装而来的java版微信客户端。
|
|
||||||
|
作者:Allen
|
||||||
|
|
||||||
|
码云主页:[https://gitee.com/hotlcc](https://gitee.com/hotlcc)
|
||||||
|
|
||||||
|
[](https://gitee.com/hotlcc)
|
||||||
|
[](https://www.toutiao.com/c/user/3341863552/#mid=51655113888)
|
||||||
|
[](https://weibo.com/hotloveu?is_hot=1)
|
||||||
|
[](http://www.apache.org/licenses/LICENSE-2.0.html)
|
||||||
|
|
||||||
## Web微信API文档
|
## Web微信API文档
|
||||||
[Web微信API文档](doc/web-weixin-api.md)
|
|
||||||
|
详见:[Web微信API文档](doc/web-weixin-api.md)
|
||||||
|
|
||||||
|
## 简单使用
|
||||||
|
|
||||||
|
```java
|
||||||
|
WebWeixinApi api = new WebWeixinApi();
|
||||||
|
// 实例化微信客户端
|
||||||
|
Wechat wechat = new Wechat();
|
||||||
|
wechat.setWebWeixinApi(api);
|
||||||
|
// 自动登录
|
||||||
|
wechat.autoLogin();
|
||||||
|
```
|
||||||
|
|
||||||
|
## 发送消息
|
||||||
|
|
||||||
|
### 文本消息
|
||||||
|
|
||||||
|
```java
|
||||||
|
// 通过userName发送文本消息
|
||||||
|
public JSONObject sendText(String content, String userName);
|
||||||
|
// 通过昵称发送消息
|
||||||
|
public JSONObject sendTextToNickName(String content, String nickName);
|
||||||
|
// 通过备注名发送消息
|
||||||
|
public JSONObject sendTextToRemarkName(String content, String remarkName);
|
||||||
|
```
|
||||||
|
|
||||||
|
> 目前仅支持发送文本消息,更多消息类型支持尽请期待。
|
||||||
|
|
||||||
|
## 消息处理器
|
||||||
|
|
||||||
|
> 通过在实例化时添加消息处理器来处理接收到的消息<br>
|
||||||
|
> 消息处理器需要实现`ReceivedMsgHandler`接口
|
||||||
|
|
||||||
|
```java
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user