Commit 6066a5d3 by hewei

Merge branch 'feature-1.4-pushParam' into '1.4'

Feature 1.4 push param

See merge request !12
parents 6fdcff36 78ffad7a
...@@ -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
...@@ -25,7 +26,7 @@ public class PushModel implements Serializable { ...@@ -25,7 +26,7 @@ public class PushModel implements Serializable {
/** /**
* 自定义系统推送内容 * 自定义系统推送内容
*/ */
private String data; 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;
...@@ -73,6 +75,7 @@ public class PushTask { ...@@ -73,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));
} }
// 校验参数 // 校验参数
...@@ -102,22 +105,36 @@ public class PushTask { ...@@ -102,22 +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));
pushModel.setData(pushMap.get(DATA));
}
this.push(pushModel, imClientReceiver, imApplication); // 自定义推送内容
// try {
HashMap hashMap = (HashMap) pushMap.get(DATA);
pushModel.setData(hashMap);
// } catch (JsonProcessingException e) {
// log.error("pushModel.setData(hashMap)", e);
// pushModel.setData(new HashMap<>(1));
// }
}
return pushModel;
} }
private void android(PushModel pushModel, ImClient imClientReceiver, ImApplication imApplication) { private void android(PushModel pushModel, ImClient imClientReceiver, ImApplication imApplication) {
...@@ -221,9 +238,9 @@ public class PushTask { ...@@ -221,9 +238,9 @@ public class PushTask {
info.put("body", pushModel.getSubTitle()); info.put("body", pushModel.getSubTitle());
// 自定义推送字段 // 自定义推送字段
Map<String, String> dataMap = new HashMap<>(); // Map<String, String> dataMap = new HashMap<>();
dataMap.put("data", pushModel.getData()); // dataMap.put("data", JSON_MAPPER.writeValueAsString());
info.put("data", dataMap); json.put("data", pushModel.getData());
//数据消息data 通知消息 notification //数据消息data 通知消息 notification
json.put("notification", info); json.put("notification", info);
...@@ -232,6 +249,9 @@ public class PushTask { ...@@ -232,6 +249,9 @@ public class PushTask {
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();
......
...@@ -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);
} }
......
...@@ -147,18 +147,33 @@ ...@@ -147,18 +147,33 @@
<!-- 解决SpringBootAdmin错误日志问题 --> <!-- 解决SpringBootAdmin错误日志问题 -->
<logger name="org.apache.catalina.connector.CoyoteAdapter" level="OFF"/> <logger name="org.apache.catalina.connector.CoyoteAdapter" level="OFF"/>
<springProfile name="dev">
<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="test">
<root level="INFO"> <root level="INFO">
<appender-ref ref="ELASTIC"/> <appender-ref ref="ELASTIC"/>
<appender-ref ref="CONSOLE"/> <appender-ref ref="CONSOLE"/>
<appender-ref ref="ASYNC_FILE"/> <appender-ref ref="ASYNC_FILE"/>
<appender-ref ref="ASYNC_ERROR_FILE"/> <appender-ref ref="ASYNC_ERROR_FILE"/>
</root> </root>
</springProfile>
<!-- <springProfile name="eslog">--> <springProfile name="prod">
<!-- <root level="INFO">--> <root level="INFO">
<!-- <appender-ref ref="ELASTIC"/>--> <appender-ref ref="ELASTIC"/>
<!-- </root>--> <appender-ref ref="CONSOLE"/>
<!-- </springProfile>--> <appender-ref ref="ASYNC_FILE"/>
<appender-ref ref="ASYNC_ERROR_FILE"/>
</root>
</springProfile>
</configuration> </configuration>
\ No newline at end of file
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