<iq id="***" type="set"from="***">
<query xmlns="***">
<username>111</username>
<method>store</method>
<token>sdsdsd</token>
<type>1</type>
<language>zh</language>
</query>
</iq>
删除iq
<iq id="***" type="set" from="***">
<query xmlns="***">
<username>111</username>
<method>del</method>
</query>
</iq>
(2)在处理离线消息位置插入自定义iq发送 public void sendPushIQ(String username,String body){
PacketRouter packetRouter = XMPPServer.getInstance().getPacketRouter();
IQ reply = new IQ();
reply.setType(Type.set);
Element probeResult = DocumentHelper.createElement(QName.get("query", "******")) ;
probeResult.addElement("username").setText(username);
probeResult.addElement("body").setText(body);
reply.setChildElement(probeResult);
packetRouter.route(reply);
}
(3)自定义插件接收自定义iq,进行处理:
public static void push( String deviceToken,String content){
try {
//被推送的iphone应用程序标示符
PayLoad payLoad = new PayLoad();
payLoad.addAlert(content);
payLoad.addBadge(1);
payLoad.addSound("default");
PushNotificationManager pushManager = PushNotificationManager.getInstance();
pushManager.addDevice("iphone", deviceToken);
//Device c = pushManager.getDevice("iphone");
String host= "gateway.sandbox.push.apple.com"; //测试用的苹果推送服务器
int port = 2195;
//注意在linux中插件路径问题
String certificatePath = "E:/***.p12";
String certificatePassword= "***";
pushManager.initializeConnection(host, port, certificatePath,certificatePassword, SSLConnectionHelper.KEYSTORE_TYPE_PKCS12);//初始化tcp连接
//Send Push
Device client = pushManager.getDevice("iphone");
pushManager.sendNotification(client, payLoad); //推送消息
pushManager.stopConnection();
pushManager.removeDevice("iphone");
}
catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
System.out.println("push succeed!");
}