一、概要
本文主要介绍WhatsApp Java api的主要接口和使用方法。
二、基本流程。
1、设置全局IP,可以设置http代理,socks代理等
public static String buildHttpProxy(String ip,int port,String user,String pwd){
JSONObject json = new JSONObject();
("type",);
JSONObject data = new JSONObject();
("user",user);
("pwd",pwd);
("ip",ip);
("port",port);
("proxy",());
return ();
}
2、设置账号
账号格式:号码,公钥,私钥
3、创建Task对象,指定发送方式http,socket。调用Task对象的send方法
public void execByHttp(IApi api,ICallback callback,String ip){
if((ip)){
ip = globalIp;
}
String id = ().toString().replace("-","");
Cmd cmd = new TaskExecCmd(id,(),(),ip).bind();
final String pid = ().pid;
int error = sendCommandByHttp(cmd);
if(error!=0){
if(callback!=null){
(api,error,"");
}
}else{
synchronized (https){
(pid,(api,callback));
}
}
}
4、等待数据返回。解析结果
JSONObject json = (raw);
int code = ("code");
String msg = ("msg");
if(code!=0){
if(callback!=null){
int subCode = (api,code,msg);
(api,subCode,code+" "+msg);
}
}else{
JSONObject data = ("data");
if(callback!=null){
(api,data);
}
}
三、代理例子。
1、分析受众是否是whatsapp的有效账号
CheckFilter task = new CheckFilter(channel, ("6285852321611"));
List<> contacts = ();
2、分析受众的最近一次上线时间
List<> lasts = new CheckPresence(
channel,
("6285852321611")
).send();
3、分析受众的头像,判断性别和年龄
List<> faces = new CheckFace(
channel,
("6285852321611")
).send();
4、向受众发送消息
message = ().
setTarget("6285852321611").
setText("hi").
build();
SendMessage send = new SendMessage(channel, (message));
List<> acks=();
5、设置账号的基本信息
boolean success = new ModifyStatus(channel,"this is a test").send();
四、其他例子。
1、创建群组。
2、添加群成员
3、群组禁言
4、移除群成员
5、群消息监听
6、私信自动回复
7、扫码登录网页端
8、语音电话呼出