zoukankan      html  css  js  c++  java
  • java 极光推送

    Web.xml配置文件

    <context-param>

        <param-name>contextConfigLocation</param-name>

        <param-value>/WEB-INF/classes/applicationContext.xml,/WEB-INF/classes/applicationContext-everydaytuisong.xml</param-value>

      </context-param>

      <!-- 开启监听 -->

      <listener>

           <listener-class>

               org.springframework.web.context.ContextLoaderListener

           </listener-class>

       </listener>

    applicationContext-everydaytuisong.xml配置文件

    <!-- 配置极光推送定时任务 -->

    <bean id="SchedulerTask3" class="org.springframework.scheduling.quartz.JobDetailBean">

    <property name="jobClass">

    <value>JPush.Jdpush</value>

    </property>

    </bean>

    <!-- 配置定时时间 -->

    <bean id="SchedulerTaskTrigger3" class="org.springframework.scheduling.quartz.CronTriggerBean">

    <property name="jobDetail" ref="SchedulerTask3" />

    <property name="cronExpression">

    <value>0 50 11 * * ?</value>

    <!-- 0 0/30 0/1 * * ? 代表每天每30分钟运行一次

         0 0/3 0/1 * * ? 代表每天每3分钟运行一次

         0 11 23 * * ? 代表每天晚上23:11运行一次 -->

    </property>

    </bean>

    <!-- 开启定时任务 -->

    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">

    <property name="triggers">

    <list>

    <ref bean="SchedulerTaskTrigger3" />

    </list>

    </property>

    </bean>

    Java 类

    package JPush;

    import org.quartz.JobExecutionContext;

    import org.quartz.JobExecutionException;

    import org.springframework.beans.factory.BeanFactory;

    import org.springframework.context.support.ClassPathXmlApplicationContext;

    import org.springframework.scheduling.quartz.QuartzJobBean;

    import cn.jpush.api.JPushClient;

    import cn.jpush.api.common.resp.APIConnectionException;

    import cn.jpush.api.common.resp.APIRequestException;

    import cn.jpush.api.push.PushResult;

    import cn.jpush.api.push.model.Message;

    import cn.jpush.api.push.model.Options;

    import cn.jpush.api.push.model.Platform;

    import cn.jpush.api.push.model.PushPayload;

    import cn.jpush.api.push.model.audience.Audience;

    import cn.jpush.api.push.model.notification.IosNotification;

    import cn.jpush.api.push.model.notification.Notification;

    import com.opensymphony.xwork2.util.logging.Logger;

    import com.opensymphony.xwork2.util.logging.LoggerFactory;

    /**

     * @author Administrator

     *

     */

    /**

     * @author Administrator

     *

     */

    public class Jdpush extends QuartzJobBean{

    protected static final Logger LOG = LoggerFactory.getLogger(Jdpush.class);

    // demo App defined in resources/jpush-api.conf

    private static final String appKey = "c36a5a0b049f950ef8ba3bf6";

    private static final String masterSecret = "57d5d83288d7e6472ce811c7";

    public static final String TITLE = "Test from API example";

    public static final String ALERT = "每日新品九点五十开抢,不容错过哦!";

    public static final String MSG_CONTENT = "dsdsdsdsdsds";

    public static final String REGISTRATION_ID = "555666";

    public static final String TAG = "tag_api";

    private static String[] tag1 = { "shenz", "nanshan" };

    public static PushPayload buildPushObject_all_all_alert() {

    return PushPayload.alertAll(ALERT);

    }

     private static BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext.xml");

    @Override

    protected void executeInternal(JobExecutionContext arg0)

    throws JobExecutionException {

    // TODO Auto-generated method stub

    JPushClient jpushClient = new JPushClient(masterSecret, appKey, 3);

    // For push, all you need do is to build PushPayload object.

    PushPayload payload = buildPushObject_all_all_alert();

    PushResult result = null;

    try {

    result = jpushClient.sendPush(payload);

    } catch (APIConnectionException e) {

    // TODO Auto-generated catch block

    e.printStackTrace();

    } catch (APIRequestException e) {

    // TODO Auto-generated catch block

    e.printStackTrace();

    }

    System.out.println("Got result - " + result);

    }

    }

  • 相关阅读:
    redis单机主从搭建
    zabbix监控rds
    zabbix_server表面启动成功,但是没有进程
    sysbench压测mysql
    使用gnuplot对tpcc-mysql压测结果生成图表
    tpcc-mysql的使用
    tpcc-mysql安装
    鼠标点击烟花爆炸效果
    css3背景自动变色代码
    js实现文本输入框的特效
  • 原文地址:https://www.cnblogs.com/JOEH60/p/5794362.html
Copyright © 2011-2022 走看看