2
0
mirror of https://gitee.com/hotlcc/wechat4j.git synced 2025-07-18 22:59:34 +08:00
wechat4j/src/test/java/TestClass2.java
2018-07-25 16:13:07 +08:00

27 lines
1.1 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import com.alibaba.fastjson.JSONObject;
import com.hotlcc.wechat4j.Wechat;
import com.hotlcc.wechat4j.api.WebWeixinApi;
import com.hotlcc.wechat4j.handler.ReceivedMsgHandler;
import com.hotlcc.wechat4j.model.ReceivedMsg;
import com.hotlcc.wechat4j.model.UserInfo;
public class TestClass2 {
public static void main(String[] args) {
WebWeixinApi api = new WebWeixinApi();
Wechat wechat = new Wechat();
wechat.setWebWeixinApi(api);
wechat.addReceivedMsgHandler(new ReceivedMsgHandler() {
@Override
public void handleAllType(Wechat wechat, ReceivedMsg msg) {
UserInfo contact = wechat.getContactByUserName(false, msg.getFromUserName());
System.out.println(contact.getRemarkName() + "" + msg.getContent());
if ("李国栋".equals(contact.getRemarkName())) {
JSONObject result = wechat.sendText("你的消息收到了", contact.getUserName());
System.out.println(result);
}
}
});
wechat.autoLogin();
}
}