Commit 2acfaec5 authored by renandong's avatar renandong 🇨🇳

1,推送消息增加可推送长文本和大图

parent 24bda6f4
......@@ -5,13 +5,39 @@ import com.weface.code.ResultCode;
import com.weface.dto.InformForm;
import org.apache.commons.lang3.StringUtils;
import java.util.Objects;
/**
* @author : Administrator
* @date : 2022/4/21 14:28
*/
public class ValidatorParam {
/**
* 校验推送参数
*
* @param informForm 推送参数
* @return 核验结果
*/
public static CommonResult validPushParams(InformForm informForm) {
Integer style = informForm.getStyle();
if (Objects.nonNull(style)) {
if (style == 1 || style == 2) {
String content = informForm.getContent();
if (StringUtils.isEmpty(content)) {
return CommonResult.failed(ResultCode.PARAMS_ERROR);
}
}
}
return null;
}
/**
* 核验别名单推推送参数
*
* @param informForm 推送参数
* @return 核验结果
*/
public static CommonResult validPushSingleAlias(InformForm informForm) {
String body = informForm.getBody();
if (body.length() > 60) {
......
......@@ -15,6 +15,7 @@ import com.weface.common.utils.Model;
import com.weface.dto.InformForm;
import com.weface.service.PushLogService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -152,7 +153,12 @@ public class MobPushService {
return Model.error();
}
/**
* 通过 workId查询当前消息推送结果
*
* @param workId 推送id
* @return 是否收到
*/
public boolean getPushInfoById(String workId) {
String reqUrl = "http://api.push.mob.com/v3/stats/getByWorkId";
Map<String, Object> request = new HashMap<>();
......@@ -221,7 +227,7 @@ public class MobPushService {
//推送类型:1通知;2自定义
pushNotify.put("type", 1);
//android通知消息, type=1, android
Map<String, Object> androidNotify = getAndroidNotify();
Map<String, Object> androidNotify = getAndroidNotify(informForm);
if (!androidNotify.isEmpty()) {
pushNotify.put("androidNotify", androidNotify);
}
......@@ -236,7 +242,7 @@ public class MobPushService {
//推送时,不走厂商通道。1: 开启,不走厂商通道;其它,关闭 ,默认关闭。
pushNotify.put("skipFactory", 0);
//推送策略: * 1:先走tcp,再走厂商 * 2:先走厂商,再走tcp * 3:只走厂商 * 4:只走tcp (厂商透传policy只支持策略3或4)
pushNotify.put("policy", 2);
pushNotify.put("policy", 1);
//拓展参数
pushNotify.put("extrasMapList", getExtrasMapList(informForm));
return pushNotify;
......@@ -391,16 +397,43 @@ public class MobPushService {
/**
* 安卓通知细节配置
*
* @param informForm 推送消息内容
* @return 安卓细节
*/
private Map<String, Object> getAndroidNotify() {
private Map<String, Object> getAndroidNotify(InformForm informForm) {
Map<String, Object> androidNotify = new HashMap<>(1);
androidNotify.put("warn", "123");
//androidNotify.put("content", new String[]{"测试这是一条数据"});
//androidNotify.put("style", "3");
Integer style = informForm.getStyle();
if (Objects.isNull(style)) {
return androidNotify;
}
androidNotify.put("style", style);
String content = informForm.getContent();
if (style == 1 || style == 2) {
androidNotify.put("content", new String[]{content});
}
String image = informForm.getImage();
if (StringUtils.isNotEmpty(image)) {
androidNotify.put("image", image);
}
return androidNotify;
}
/**
* customStyle:安卓通知自定义样式
*
* @return 安卓细节
*/
private Map<String, Object> getCustomStyle() {
Map<String, Object> map = new HashMap<>();
map.put("styleNo", 1);
map.put("backgroundUrl", "https://socialsecurity.oss-cn-beijing.aliyuncs.com/userPhoto/ycfj.png");
map.put("smallIcons", "http://i.weface.com.cn/banners/tcformphoto/certificationOldSuucess01.gif");
map.put("buttonCopy", "测试文案");
map.put("buttonJumpUrl", "https://www.hutool.cn/");
return map;
}
/**
* ios通知细节配置
*
......
......@@ -51,6 +51,10 @@ public class PushController {
public CommonResult pushAll(InformForm informForm) {
log.error("群推内容:{}", JSONObject.toJSONString(informForm));
ValidatorUtils.validateEntity(informForm, InformForm.PushValid.class);
CommonResult result = ValidatorParam.validPushParams(informForm);
if (result != null) {
return result;
}
if (informForm.getEquipmentType().equals("kksh")) {
mobPushService.mobPush(informForm, Constant.PushTarget.RADIO);
}
......@@ -63,11 +67,15 @@ public class PushController {
@PostMapping("/single/alias")
public CommonResult pushSingleAlias(@RequestBody InformForm informForm) {
ValidatorUtils.validateEntity(informForm, InformForm.PushValid.class);
CommonResult commonResult = ValidatorParam.validPushSingleAlias(informForm);
if (commonResult != null) {
return commonResult;
CommonResult result = ValidatorParam.validPushParams(informForm);
if (result != null) {
return result;
}
result = ValidatorParam.validPushSingleAlias(informForm);
if (result != null) {
return result;
}
CommonResult result = mobPushService.mobPush(informForm, Constant.PushTarget.ALIAS);
result = mobPushService.mobPush(informForm, Constant.PushTarget.ALIAS);
if (result != null) {
return CommonResult.success();
}
......@@ -80,11 +88,15 @@ public class PushController {
@PostMapping("/single/cid")
public CommonResult pushSingleCid(@RequestBody InformForm informForm) {
ValidatorUtils.validateEntity(informForm, InformForm.PushValid.class);
CommonResult commonResult = ValidatorParam.validPushSingleAlias(informForm);
if (commonResult != null) {
return commonResult;
CommonResult result = ValidatorParam.validPushParams(informForm);
if (result != null) {
return result;
}
result = ValidatorParam.validPushSingleAlias(informForm);
if (result != null) {
return result;
}
CommonResult result = mobPushService.mobPush(informForm, Constant.PushTarget.RIDS);
result = mobPushService.mobPush(informForm, Constant.PushTarget.RIDS);
if (result != null) {
return CommonResult.success();
}
......
......@@ -39,8 +39,12 @@ public class InformForm {
private String phone;
//推送模板
private Integer messageTemplate;
//显示样式标识- 0:默认 - 1:长内容 - 2:大图 - 3:横幅 - 4:自定义样式
private Integer style;
//推送内容,配合style参数使用- style=0 不生效 - style=1 部分机型可以生效覆盖- style=2 传入图片链接,部分低版本手机不支持- style=3 对应传入文字内容默认: 0
private String content;
//推送大图标的url地址小米厂商对图片尺寸有严格要求
private String image;
public interface PushValid{
}
......
package com.weface.serviceimpl;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
......@@ -113,6 +114,11 @@ public class PushLogServiceImpl extends ServiceImpl<PushLogDao, PushLogEntity> i
}
pushLogEntity.setPushContent(body);
pushLogEntity.setArriveStatus(1001);
String jsonStr = JSONUtil.toJsonStr(informForm);
if (jsonStr.length() > 200) {
jsonStr = jsonStr.substring(0, 200);
}
pushLogEntity.setBas1(jsonStr);
pushLogEntity.setUpdateTime(new Date());
return pushLogEntity;
}
......
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