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;
import lombok.Data;
import java.io.Serializable;
import java.util.HashMap;
/**
* @Description 推送model
......@@ -25,7 +26,7 @@ public class PushModel implements Serializable {
/**
* 自定义系统推送内容
*/
private String data;
private HashMap data;
}
package com.wecloud.im.ws.sender;
import cn.hutool.core.codec.Base64;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.turo.pushy.apns.DeliveryPriority;
import com.turo.pushy.apns.PushType;
import com.wecloud.im.entity.ImApplication;
......@@ -32,6 +33,7 @@ import java.util.Map;
@Component
@Slf4j
public class PushTask {
private static final JsonMapper JSON_MAPPER = new JsonMapper();
@Autowired
private ImIosApnsService imIosApnsService;
......@@ -73,6 +75,7 @@ public class PushTask {
pushModel = new PushModel();
pushModel.setTitle(PUSH_TITLE);
pushModel.setSubTitle(PUSH_BODY);
pushModel.setData(new HashMap<>(1));
}
// 校验参数
......@@ -102,22 +105,36 @@ public class PushTask {
* @param imClientReceiver
*/
@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());
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()) {
pushModel.setTitle(PUSH_TITLE);
pushModel.setSubTitle(PUSH_BODY);
pushModel.setData(new HashMap<>(1));
} else {
pushModel.setTitle(pushMap.get(title));
pushModel.setSubTitle(pushMap.get(subTitle));
pushModel.setData(pushMap.get(DATA));
}
pushModel.setTitle((String) pushMap.get(title));
pushModel.setSubTitle((String) pushMap.get(subTitle));
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) {
......@@ -221,9 +238,9 @@ public class PushTask {
info.put("body", pushModel.getSubTitle());
// 自定义推送字段
Map<String, String> dataMap = new HashMap<>();
dataMap.put("data", pushModel.getData());
info.put("data", dataMap);
// Map<String, String> dataMap = new HashMap<>();
// dataMap.put("data", JSON_MAPPER.writeValueAsString());
json.put("data", pushModel.getData());
//数据消息data 通知消息 notification
json.put("notification", info);
......@@ -232,6 +249,9 @@ public class PushTask {
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
jsonStr = json.toString();
log.info("FCM push data {}", jsonStr);
wr.write(jsonStr);
wr.flush();
InputStream inputStream = conn.getInputStream();
......
......@@ -112,9 +112,9 @@ public class ImChatConcrete extends ImCmdAbstract {
receiveModel.getData().remove(TO_CONVERSATION_KEY);
// 获取自定义推送字段
HashMap<String, String> pushMap = null;
HashMap<String, Object> pushMap = 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);
}
......
......@@ -147,18 +147,33 @@
<!-- 解决SpringBootAdmin错误日志问题 -->
<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">
<appender-ref ref="ELASTIC"/>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="ASYNC_FILE"/>
<appender-ref ref="ASYNC_ERROR_FILE"/>
</root>
</springProfile>
<!-- <springProfile name="eslog">-->
<!-- <root level="INFO">-->
<!-- <appender-ref ref="ELASTIC"/>-->
<!-- </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>
\ 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