浏览 2745 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2013-01-08
代码: private boolean pushXmpp(JSONObject obj) throws Exception { boolean result = true; log.info("pushXmpp start"); try { connect(); if (this.mConnected) { String title = obj.getString("title"); int pushtype = obj.getInt("pushtype"); String paramid = obj.getString("paramid"); String paramid2 = obj.getString("paramid2"); String deviceid = obj.getString("deviceid"); // String to = deviceid + "@" + PropertiesUtils.XMPP_SERVICE_NAME; Message msg = new Message(); obj.remove("deviceid"); // msg.setFrom(PropertiesUtils.USER_NAME + "@" + PropertiesUtils.XMPP_SERVICE_NAME); // msg.setTo(to); msg.setFrom(PropertiesUtils.XMPP_SERVICE_NAME); msg.setTo(deviceid); JSONObject messages = new JSONObject(); messages.put("title", title); messages.put("pushtype",pushtype); messages.put("paramid", paramid); messages.put("paramid2", paramid2); msg.setBody(messages.toString()); this.mConn.sendPacket(msg); Thread.sleep(2000); //log.info("pushXmpp sendTo:"+to +" success"); this.mConn.disconnect(); log.info("pushXmpp disconnect"); } else { //throw new Exception("failed to connect Xmpp Server"); result = false; } } catch (Exception e) { result = false; //如果推送出现错误,跳过这个推送,保存日记记录 StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); log.info(sw.toString()); //throw new JSONException(e.getMessage()); } finally { this.mConn = null; log.info("connect end"); } return result; } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2013-01-15
XMPP协议复杂了, MQTT最合适
|
|
返回顶楼 | |