androidpn消息下推2

来源:互联网 发布:流体热力学软件 编辑:程序博客网 时间:2024/04/30 14:30

打开指定html页面,openInfoUtils.js:

function openInfoPage(isPush){var notificationId = "";var title = "";var message= "";var uri = "";var msgId = "";if(isPush){window.plugins.pushNotificationPlugin.startService("getsharedata", function(r){notificationId = r.notificationId;title = r.title;message = r.message;uri = r.uri;msgId = r.messageId;if(uri=="taskFormRead4Push"){wellApp.openWellWindow("threePage",{contentId     : uri,contentIntent : {                headerTitle   : '待办任务',        unid         : msgId,        rwmc       : title,            }});}else if(uri=="taskhomeRead4Push"){wellApp.openWellWindow("threePage",{contentId     : uri,contentIntent : {                headerTitle   : '待办事件',        unid         : msgId,        sjmc       : title,            }});}else if(uri=="tzggForPush"){wellApp.openWellWindow('articleInfo', {unid      :    msgId,index     :    "1",});}        },null, []);}}

应用服务端下推功能的代码:

PushBean.java:

package com.linewell.qzgrid.phone.push;/** * 推送Bean对象 * @author zzhan@linewell.com * @since 2014-5-7 * */public class PushBean {/** * 推送目的方 */private String username;/** * 标题 */private String title;/** * 推送消息 */private String message;/** * 推送uri */private String uri;public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getTitle() {return title;}public void setTitle(String title) {this.title = title;}public String getMessage() {return message;}public void setMessage(String message) {this.message = message;}public String getUri() {return uri;}public void setUri(String uri) {this.uri = uri;}}

PushUtils.java:

package com.linewell.qzgrid.phone.push;import java.io.BufferedInputStream;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;import java.util.Properties;import javax.xml.namespace.QName;import org.apache.axis2.addressing.EndpointReference;import org.apache.axis2.client.Options;import org.apache.axis2.rpc.client.RPCServiceClient;//import org.apache.cxf.endpoint.Client;//import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;/** * 推送工具类,提供群推和单推的api *  * @author zzhan@linewell.com * @since 2014-05-08 */public class PushUtils {public static final String SEND_ALL = "sendAll";public static final String SEND_SINGLE = "sendSingle";//public static String PUSH_URL = "http://192.168.16.38:7070/Androidpn/service/notification";//public static String TARGET_NAMESPACE = "http://webservice.linewell.com/";static RPCServiceClient rpcServiceClient ;public static RPCServiceClient getRpcServiceClient() throws Exception{if(rpcServiceClient==null){rpcServiceClient = new RPCServiceClient();}return rpcServiceClient;}/** * 群推 *  * @param bean *            推送的bean对象 * @throws Exception */public static void sendAll(PushBean bean) throws Exception {if (null == RDUrl.PUSH_URL)throw new RuntimeException("服务地址不能为空!请配置服务地址");String title = bean.getTitle();String message = bean.getMessage();String uri = bean.getUri();// 1 使用RPC方式调用webServiceRPCServiceClient rpcServiceClient = getRpcServiceClient();Options options = rpcServiceClient.getOptions();// 指定调用webService的URLEndpointReference targetEPR = new EndpointReference(RDUrl.PUSH_URL);options.setTo(targetEPR);// 设置参数Object[] opAddEntryArgs = new Object[] { title, message, uri};// 方法的返回对象类型Class[] classes = new Class[] { String.class };// wsdl的命名空间及调用的方法QName opAddEntry = new QName(RDUrl.TARGET_NAMESPACE, SEND_ALL);// 方法调用String result = (String) rpcServiceClient.invokeBlocking(opAddEntry,opAddEntryArgs, classes)[0];rpcServiceClient.cleanupTransport(); // 为了防止连接超时// RPC end}/** * 单推 *  * @param bean *            推送的Bean对象,其中username属性不能为空 * @throws Exception */public static void sendSingle(PushBean bean) throws Exception {if (null == RDUrl.PUSH_URL)throw new RuntimeException("服务地址不能为空!请配置服务地址");String title = bean.getTitle();String message = bean.getMessage();String uri = bean.getUri();String username = bean.getUsername();if (null == username)throw new RuntimeException("请设置PushBean的username属性");// 1 使用RPC方式调用webServiceRPCServiceClient rpcServiceClient = getRpcServiceClient();Options options = rpcServiceClient.getOptions();// 指定调用webService的URLEndpointReference targetEPR = new EndpointReference(RDUrl.PUSH_URL);options.setTo(targetEPR);// 设置参数Object[] opAddEntryArgs = new Object[] { title, message, uri, username };// 方法的返回对象类型Class[] classes = new Class[] { String.class };// wsdl的命名空间及调用的方法QName opAddEntry = new QName(RDUrl.TARGET_NAMESPACE, SEND_SINGLE);// 方法调用String result = (String) rpcServiceClient.invokeBlocking(opAddEntry,opAddEntryArgs, classes)[0];rpcServiceClient.cleanupTransport(); // 为了防止连接超时// RPC end}}

RDUrl.java:

package com.linewell.qzgrid.phone.push;import java.io.IOException;import java.io.InputStream;import java.util.Properties;import com.linewell.qzgrid.util.ReadProperties;/** * 系统用到的URL路径配置 * @author cjianquan@linewell.com * * @since 2014-8-11 */public class RDUrl {/** * 推送服务的URL配置 */public static String PUSH_URL = "";/** * service的命名空间名称 */public static final String TARGET_NAMESPACE = "http://webservice.linewell.com/";static {Properties prop = new Properties();InputStream in = ReadProperties.class.getResourceAsStream("/androidpnUrl.properties");// System.out.println(in);try {prop.load(in);PUSH_URL = prop.getProperty("pushUrl").trim();} catch (IOException e) {e.printStackTrace();}}}

androidpnUrl.properties:

pushUrl=http://192.168.16.38:7070/Androidpn/service/notification


0 0