初始化

This commit is contained in:
谢洪龙
2017-08-23 12:20:15 +08:00
commit 491d430741
471 changed files with 16355 additions and 0 deletions
@@ -0,0 +1,187 @@
package com.ifish.jpush.push.model.notification;
import java.util.Map;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.ifish.jpush.common.ServiceHelper;
/**
* APNs 通知类
* <p>
* 支持 APNs 默认的几个参数:
* <li>alert: 继承自父类 PlatformNotification 的 alert 属性;本类设置则覆盖。</li>
* <li>badge: 支持 setBadge(int) 方法来设置;支持 incrBadge(int) 方法来增加。</li>
* <li>sound: 支持 setSound(string) 方法来设置声音文件。</li>
* <li>content-available: 用来支持后台推送。如果该值赋值为 1,表示开启后台推送。</li>
* <li>extras: JSON object. 支持更多的自定义字段信息。</li>
* </p>
* <p>
* 需要特别留意的是,JPush SDK 会对以下几个值有特别的默认设置考虑:
* <li>badge: 默认为 "+1"。如果需要取消 badge 值,需要显式地调用 disableBadge().</li>
* <li>sound: 默认为 "",即默认的声音提示。如果需要取消 sound 值,即不要声音,需要显式地调用 disableSound(). </li>
* </p>
*/
public class IosNotification extends PlatformNotification {
public static final String NOTIFICATION_IOS = "ios";
private static final String DEFAULT_SOUND = "";
private static final String DEFAULT_BADGE = "+1";
private static final String BADGE = "badge";
private static final String SOUND = "sound";
private static final String CONTENT_AVAILABLE = "content-available";
private static final String CATEGORY = "category";
private static final String ALERT_VALID_BADGE = "Badge number should be 0~99999, "
+ "and can be prefixed with + to add, - to minus";
private final boolean soundDisabled;
private final boolean badgeDisabled;
private final String sound;
private final String badge;
private final boolean contentAvailable;
private final String category;
private IosNotification(Object alert, String sound, String badge,
boolean contentAvailable, boolean soundDisabled, boolean badgeDisabled,
String category,
Map<String, String> extras,
Map<String, Number> numberExtras,
Map<String, Boolean> booleanExtras,
Map<String, JsonObject> jsonExtras) {
super(alert, extras, numberExtras, booleanExtras, jsonExtras);
this.sound = sound;
this.badge = badge;
this.contentAvailable = contentAvailable;
this.soundDisabled = soundDisabled;
this.badgeDisabled = badgeDisabled;
this.category = category;
}
public static Builder newBuilder() {
return new Builder();
}
public static IosNotification alert(String alert) {
return newBuilder().setAlert(alert).build();
}
@Override
public String getPlatform() {
return NOTIFICATION_IOS;
}
@Override
public JsonElement toJSON() {
JsonObject json = super.toJSON().getAsJsonObject();
if (!badgeDisabled) {
if (null != badge) {
json.add(BADGE, new JsonPrimitive(this.badge));
} else {
json.add(BADGE, new JsonPrimitive(DEFAULT_BADGE));
}
}
if (!soundDisabled) {
if (null != sound) {
json.add(SOUND, new JsonPrimitive(sound));
} else {
json.add(SOUND, new JsonPrimitive(DEFAULT_SOUND));
}
}
if (contentAvailable) {
json.add(CONTENT_AVAILABLE, new JsonPrimitive(1));
}
if (null != category) {
json.add(CATEGORY, new JsonPrimitive(category));
}
return json;
}
public static class Builder extends PlatformNotification.Builder<IosNotification, Builder> {
private String sound;
private String badge;
private boolean contentAvailable = false;
private boolean soundDisabled = false;
private boolean badgeDisabled = false;
private String category;
protected Builder getThis() {
return this;
}
public Builder setSound(String sound) {
this.sound = sound;
return this;
}
public Builder disableSound() {
this.soundDisabled = true;
return this;
}
public Builder incrBadge(int badge) {
if (!ServiceHelper.isValidIntBadge(Math.abs(badge))) {
LOG.warn(ALERT_VALID_BADGE);
return this;
}
if (badge >= 0) {
this.badge = "+" + badge;
} else {
this.badge = "" + badge;
}
return this;
}
public Builder setBadge(int badge) {
if (!ServiceHelper.isValidIntBadge(badge)) {
LOG.warn(ALERT_VALID_BADGE);
return this;
}
this.badge = "" + badge;
return this;
}
/**
* equals to: +1
*/
public Builder autoBadge() {
return incrBadge(1);
}
public Builder disableBadge() {
this.badgeDisabled = true;
return this;
}
public Builder setContentAvailable(boolean contentAvailable) {
this.contentAvailable = contentAvailable;
return this;
}
public Builder setCategory(String category) {
this.category = category;
return this;
}
public Builder setAlert(Object alert) {
this.alert = alert;
return this;
}
public IosNotification build() {
return new IosNotification(alert, sound, badge, contentAvailable,
soundDisabled, badgeDisabled, category,
extrasBuilder, numberExtrasBuilder, booleanExtrasBuilder, jsonExtrasBuilder);
}
}
}
@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd"
default-lazy-init="true">
<!-- 启动触发器的配置开始 -->
<bean name="startQuertz" lazy-init="false" autowire="no"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="myJobTrigger" />
</list>
</property>
<property name="quartzProperties">
<props>
<prop key="org.quartz.scheduler.skipUpdateCheck">true</prop>
</props>
</property>
</bean>
<!-- 启动触发器的配置结束 -->
<!-- quartz-2.x的配置 -->
<bean id="myJobTrigger"
class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail">
<ref bean="myJobDetail" />
</property>
<property name="cronExpression">
<!--每天10点开始推送 -->
<value>0 0 10 * * ?</value>
</property>
</bean>
<!-- 调度的配置结束 -->
<!-- job的配置开始 -->
<bean id="myJobDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="myJob" />
</property>
<property name="targetMethod">
<value>pushRemind</value>
</property>
</bean>
<!-- job的配置结束 -->
<!-- 工作的bean -->
<bean id="myJob" class=" com.ifish.job.job" />
<!-- 注册识别注解 -->
<context:annotation-config />
<!-- 导入外部的properties文件-->
<context:property-placeholder location="classpath*:jPpush.properties" ignore-unresolvable="true"/>
<!-- 极光推送 -->
<bean id="jPushNotification" class="com.ifish.jpush.JPushNotification">
<constructor-arg index="0">
<!-- appKey -->
<value>${jpush.android.appKey}</value>
</constructor-arg>
<constructor-arg index="1">
<!-- secret -->
<value>${jpush.android.secret}</value>
</constructor-arg>
<constructor-arg index="2">
<!-- production -->
<value>${jpush.android.productionMode}</value>
</constructor-arg>
</bean>
<!-- 极光推送 -->
<bean id="jPushNotification2" class="com.ifish.jpush.JPushNotification">
<constructor-arg index="0">
<!-- appKey -->
<value>${jpush.ios.appKey}</value>
</constructor-arg>
<constructor-arg index="1">
<!-- secret -->
<value>${jpush.ios.secret}</value>
</constructor-arg>
<constructor-arg index="2">
<!-- production -->
<value>${jpush.ios.productionMode}</value>
</constructor-arg>
</bean>
<!-- 云信 -->
<bean id="neteaseIM" class="com.ifish.netease.NeteaseIM">
<constructor-arg index="0">
<!-- appKey -->
<value>${netease.appKey}</value>
</constructor-arg>
<constructor-arg index="1">
<!-- appSecret -->
<value>${netease.appSecret}</value>
</constructor-arg>
</bean>
</beans>