Commit 105d154b by hewei

Merge branch '1.4' into 'master'

1.4

See merge request !13
parents c7cc42a7 6066a5d3
...@@ -3,6 +3,7 @@ package com.wecloud.im.ws.model.request; ...@@ -3,6 +3,7 @@ package com.wecloud.im.ws.model.request;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap;
/** /**
* @Description 推送model * @Description 推送model
...@@ -22,4 +23,10 @@ public class PushModel implements Serializable { ...@@ -22,4 +23,10 @@ public class PushModel implements Serializable {
*/ */
private String subTitle; private String subTitle;
/**
* 自定义系统推送内容
*/
private HashMap data;
} }
package com.wecloud.im.ws.sender; package com.wecloud.im.ws.sender;
import cn.hutool.core.codec.Base64; import cn.hutool.core.codec.Base64;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.turo.pushy.apns.DeliveryPriority; import com.turo.pushy.apns.DeliveryPriority;
import com.turo.pushy.apns.PushType; import com.turo.pushy.apns.PushType;
import com.wecloud.im.entity.ImApplication; import com.wecloud.im.entity.ImApplication;
...@@ -32,6 +33,7 @@ import java.util.Map; ...@@ -32,6 +33,7 @@ import java.util.Map;
@Component @Component
@Slf4j @Slf4j
public class PushTask { public class PushTask {
private static final JsonMapper JSON_MAPPER = new JsonMapper();
@Autowired @Autowired
private ImIosApnsService imIosApnsService; private ImIosApnsService imIosApnsService;
...@@ -57,6 +59,7 @@ public class PushTask { ...@@ -57,6 +59,7 @@ public class PushTask {
private static final String title = "title"; private static final String title = "title";
private static final String subTitle = "subTitle"; private static final String subTitle = "subTitle";
private static final String DATA = "data";
/** /**
...@@ -72,6 +75,7 @@ public class PushTask { ...@@ -72,6 +75,7 @@ public class PushTask {
pushModel = new PushModel(); pushModel = new PushModel();
pushModel.setTitle(PUSH_TITLE); pushModel.setTitle(PUSH_TITLE);
pushModel.setSubTitle(PUSH_BODY); pushModel.setSubTitle(PUSH_BODY);
pushModel.setData(new HashMap<>(1));
} }
// 校验参数 // 校验参数
...@@ -101,21 +105,36 @@ public class PushTask { ...@@ -101,21 +105,36 @@ public class PushTask {
* @param imClientReceiver * @param imClientReceiver
*/ */
@Async @Async
public void push(HashMap<String, String> pushMap, ImClient imClientReceiver, ImApplication imApplication) { public void push(HashMap<String, Object> pushMap, ImClient imClientReceiver, ImApplication imApplication) {
log.info("push:" + imClientReceiver.getClientId()); log.info("push:" + imClientReceiver.getClientId());
PushModel pushModel = new PushModel(); PushModel pushModel = getPushModel(pushMap);
this.push(pushModel, imClientReceiver, imApplication);
}
private PushModel getPushModel(HashMap<String, Object> pushMap) {
PushModel pushModel = new PushModel();
if (pushMap == null || pushMap.isEmpty()) { if (pushMap == null || pushMap.isEmpty()) {
pushModel.setTitle(PUSH_TITLE); pushModel.setTitle(PUSH_TITLE);
pushModel.setSubTitle(PUSH_BODY); pushModel.setSubTitle(PUSH_BODY);
pushModel.setData(new HashMap<>(1));
} else { } else {
pushModel.setTitle(pushMap.get(title)); pushModel.setTitle((String) pushMap.get(title));
pushModel.setSubTitle(pushMap.get(subTitle)); pushModel.setSubTitle((String) pushMap.get(subTitle));
// 自定义推送内容
// try {
HashMap hashMap = (HashMap) pushMap.get(DATA);
pushModel.setData(hashMap);
// } catch (JsonProcessingException e) {
// log.error("pushModel.setData(hashMap)", e);
// pushModel.setData(new HashMap<>(1));
// }
} }
this.push(pushModel, imClientReceiver, imApplication); return pushModel;
} }
private void android(PushModel pushModel, ImClient imClientReceiver, ImApplication imApplication) { private void android(PushModel pushModel, ImClient imClientReceiver, ImApplication imApplication) {
...@@ -212,16 +231,27 @@ public class PushTask { ...@@ -212,16 +231,27 @@ public class PushTask {
conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Authorization", "key=" + imApplication.getFirebaseSecret()); conn.setRequestProperty("Authorization", "key=" + imApplication.getFirebaseSecret());
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
//推送到哪台客户端机器 //推送到哪台客户端机器 设备token
json.put("to", imClientReceiver.getDeviceToken()); json.put("to", imClientReceiver.getDeviceToken());
JSONObject info = new JSONObject(); JSONObject info = new JSONObject();
info.put("title", pushModel.getTitle()); info.put("title", pushModel.getTitle());
info.put("body", pushModel.getSubTitle()); info.put("body", pushModel.getSubTitle());
// 自定义推送字段
// Map<String, String> dataMap = new HashMap<>();
// dataMap.put("data", JSON_MAPPER.writeValueAsString());
json.put("data", pushModel.getData());
//数据消息data 通知消息 notification //数据消息data 通知消息 notification
json.put("notification", info); json.put("notification", info);
// 自定义推送内容
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
jsonStr = json.toString(); jsonStr = json.toString();
log.info("FCM push data {}", jsonStr);
wr.write(jsonStr); wr.write(jsonStr);
wr.flush(); wr.flush();
InputStream inputStream = conn.getInputStream(); InputStream inputStream = conn.getInputStream();
...@@ -242,7 +272,9 @@ public class PushTask { ...@@ -242,7 +272,9 @@ public class PushTask {
private void apnsPush(PushModel pushModel, ImClient imClientReceiver, ImApplication imApplication) { private void apnsPush(PushModel pushModel, ImClient imClientReceiver, ImApplication imApplication) {
// 查询apns证书 // 查询apns证书
ImIosApns apns = imIosApnsService.getImIosApnsByAppId(imApplication.getId()); ImIosApns apns = imIosApnsService.getImIosApnsByAppId(imApplication.getId());
Map<String, Object> customProperty = new HashMap<String, Object>(1); Map<String, Object> customProperty = new HashMap<String, Object>(3);
// 自定义推送内容
customProperty.put("data", pushModel.getData());
String deviceToken = imClientReceiver.getDeviceToken(); String deviceToken = imClientReceiver.getDeviceToken();
String alertTitle = pushModel.getTitle(); String alertTitle = pushModel.getTitle();
String alertBody = pushModel.getSubTitle(); String alertBody = pushModel.getSubTitle();
......
...@@ -112,9 +112,9 @@ public class ImChatConcrete extends ImCmdAbstract { ...@@ -112,9 +112,9 @@ public class ImChatConcrete extends ImCmdAbstract {
receiveModel.getData().remove(TO_CONVERSATION_KEY); receiveModel.getData().remove(TO_CONVERSATION_KEY);
// 获取自定义推送字段 // 获取自定义推送字段
HashMap<String, String> pushMap = null; HashMap<String, Object> pushMap = null;
if (receiveModel.getData().get(PUSH_KEY) != null) { if (receiveModel.getData().get(PUSH_KEY) != null) {
pushMap = (HashMap<String, String>) receiveModel.getData().get(PUSH_KEY); pushMap = (HashMap<String, Object>) receiveModel.getData().get(PUSH_KEY);
receiveModel.getData().remove(PUSH_KEY); receiveModel.getData().remove(PUSH_KEY);
} }
......
...@@ -76,6 +76,69 @@ ...@@ -76,6 +76,69 @@
<appender-ref ref="ERROR_FILE"/> <appender-ref ref="ERROR_FILE"/>
</appender> </appender>
<!-- <appender name="LOGSTASH"-->
<!-- class="net.logstash.logback.appender.LogstashTcpSocketAppender">-->
<!-- <destination>139.9.6.183:5044</destination>-->
<!-- &lt;!&ndash; encoder必须配置,有多种可选 &ndash;&gt;-->
<!-- <encoder charset="UTF-8"-->
<!-- class="net.logstash.logback.encoder.LogstashEncoder">-->
<!-- &lt;!&ndash; "appname":"xxx" 的作用是指定创建索引的名字时用,并且在生成的文档中会多了这个字段 &ndash;&gt;-->
<!-- <customFields>{"appname":"wc_im"}</customFields>-->
<!-- </encoder>-->
<!-- </appender>-->
<appender name="ELASTIC" class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
<url>http://elastic:ZwnEAr3arDtmc8R5aFdH@139.9.6.183:9200/_bulk</url>
<index>wc-im-%date{yyyy-MM-dd}</index>
<!-- <type>test</type>-->
<loggerName>wc-im-logger</loggerName> <!-- optional -->
<errorLoggerName>wc-im-error-logger</errorLoggerName> <!-- optional -->
<connectTimeout>30000</connectTimeout> <!-- optional (in ms, default 30000) -->
<errorsToStderr>false</errorsToStderr> <!-- optional (default false) -->
<includeCallerData>false</includeCallerData> <!-- optional (default false) -->
<logsToStderr>false</logsToStderr> <!-- optional (default false) -->
<maxQueueSize>104857600</maxQueueSize> <!-- optional (default 104857600) -->
<maxRetries>3</maxRetries> <!-- optional (default 3) -->
<readTimeout>30000</readTimeout> <!-- optional (in ms, default 30000) -->
<sleepTime>250</sleepTime> <!-- optional (in ms, default 250) -->
<rawJsonMessage>false</rawJsonMessage> <!-- optional (default false) -->
<includeMdc>false</includeMdc> <!-- optional (default false) -->
<maxMessageSize>-1</maxMessageSize> <!-- optional (default -1 -->
<authentication class="com.internetitem.logback.elasticsearch.config.BasicAuthentication"/> <!-- optional -->
<properties>
<property>
<name>host</name>
<value>${HOSTNAME}</value>
<allowEmpty>false</allowEmpty>
</property>
<property>
<name>level</name>
<value>%level</value>
</property>
<property>
<name>thread</name>
<value>%thread</value>
</property>
<property>
<name>stacktrace</name>
<value>%ex</value>
</property>
<property>
<name>package</name>
<value>%logger</value>
</property>
</properties>
<headers>
<header>
<name>Content-Type</name>
<value>application/json</value>
</header>
</headers>
</appender>
<!-- 不同环境的日志级别配置 --> <!-- 不同环境的日志级别配置 -->
<springProfile name="dev"> <springProfile name="dev">
<logger name="io.geekidea.springbootplus" level="DEBUG"/> <logger name="io.geekidea.springbootplus" level="DEBUG"/>
...@@ -84,10 +147,33 @@ ...@@ -84,10 +147,33 @@
<!-- 解决SpringBootAdmin错误日志问题 --> <!-- 解决SpringBootAdmin错误日志问题 -->
<logger name="org.apache.catalina.connector.CoyoteAdapter" level="OFF"/> <logger name="org.apache.catalina.connector.CoyoteAdapter" level="OFF"/>
<root level="INFO">
<appender-ref ref="CONSOLE"/> <springProfile name="dev">
<appender-ref ref="ASYNC_FILE"/> <root level="INFO">
<appender-ref ref="ASYNC_ERROR_FILE"/> <!-- <appender-ref ref="ELASTIC"/>-->
</root> <appender-ref ref="CONSOLE"/>
<appender-ref ref="ASYNC_FILE"/>
<appender-ref ref="ASYNC_ERROR_FILE"/>
</root>
</springProfile>
<springProfile name="test">
<root level="INFO">
<appender-ref ref="ELASTIC"/>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="ASYNC_FILE"/>
<appender-ref ref="ASYNC_ERROR_FILE"/>
</root>
</springProfile>
<springProfile name="prod">
<root level="INFO">
<appender-ref ref="ELASTIC"/>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="ASYNC_FILE"/>
<appender-ref ref="ASYNC_ERROR_FILE"/>
</root>
</springProfile>
</configuration> </configuration>
\ No newline at end of file
...@@ -327,6 +327,18 @@ ...@@ -327,6 +327,18 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>5.3</version>
</dependency>
<dependency>
<groupId>com.internetitem</groupId>
<artifactId>logback-elasticsearch-appender</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
......
...@@ -44,6 +44,7 @@ aaaaa3 ...@@ -44,6 +44,7 @@ aaaaa3
"push":{ "push":{
"title":"收到一条新消息", "title":"收到一条新消息",
"subTitle":"发给12312123213这是一123个纯文本消息,发给12312123213这是一123个纯文本消息发给12312123213这是一123个纯文本消息" "subTitle":"发给12312123213这是一123个纯文本消息,发给12312123213这是一123个纯文本消息发给12312123213这是一123个纯文本消息"
"data":""
}, },
"diyAbcd":"aaaa自已定义字段的值", "diyAbcd":"aaaa自已定义字段的值",
"toConversation":1427910060675305472, "toConversation":1427910060675305472,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment