Commit 95873b51 authored by renandong's avatar renandong 🇨🇳

1.签名信息配置

parent 8540a781
...@@ -3,7 +3,6 @@ package com.weface.common.validator; ...@@ -3,7 +3,6 @@ package com.weface.common.validator;
import com.weface.code.CommonResult; import com.weface.code.CommonResult;
import com.weface.code.ResultCode; import com.weface.code.ResultCode;
import com.weface.dto.InformForm; import com.weface.dto.InformForm;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
/** /**
...@@ -23,10 +22,10 @@ public class ValidatorParam { ...@@ -23,10 +22,10 @@ public class ValidatorParam {
return CommonResult.failed(ResultCode.PARAMS_ERROR); return CommonResult.failed(ResultCode.PARAMS_ERROR);
} }
} }
String[] cid = informForm.getCid(); String cid = informForm.getCid();
String phone = informForm.getPhone(); String phone = informForm.getPhone();
Integer messageTemplate = informForm.getMessageTemplate(); Integer messageTemplate = informForm.getMessageTemplate();
if (ArrayUtils.isEmpty(cid) || StringUtils.isEmpty(phone) || messageTemplate == null) { if (StringUtils.isEmpty(cid) || StringUtils.isEmpty(phone) || messageTemplate == null) {
return CommonResult.failed(ResultCode.PARAMS_ERROR); return CommonResult.failed(ResultCode.PARAMS_ERROR);
} }
return null; return null;
......
...@@ -33,11 +33,9 @@ public class ValidatorUtils { ...@@ -33,11 +33,9 @@ public class ValidatorUtils {
throws RRException { throws RRException {
Set<ConstraintViolation<Object>> constraintViolations = validator.validate(object, groups); Set<ConstraintViolation<Object>> constraintViolations = validator.validate(object, groups);
if (!constraintViolations.isEmpty()) { if (!constraintViolations.isEmpty()) {
StringBuilder msg = new StringBuilder();
for (ConstraintViolation<Object> constraint : constraintViolations) { for (ConstraintViolation<Object> constraint : constraintViolations) {
msg.append(constraint.getMessage()).append("\n"); throw new RRException(constraint.getMessage(), 10001);
} }
throw new RRException(msg.toString());
} }
} }
} }
...@@ -340,7 +340,6 @@ public class GeTuiService { ...@@ -340,7 +340,6 @@ public class GeTuiService {
*/ */
public CommonResult pushSingleAlias(InformForm informForm) { public CommonResult pushSingleAlias(InformForm informForm) {
try { try {
log.error("单推参数:{}", informForm);
String type = informForm.getEquipmentType(); String type = informForm.getEquipmentType();
String appId = getAppId(type); String appId = getAppId(type);
String pushToken = getPushToken(type); String pushToken = getPushToken(type);
...@@ -348,7 +347,14 @@ public class GeTuiService { ...@@ -348,7 +347,14 @@ public class GeTuiService {
return CommonResult.failed(); return CommonResult.failed();
} }
MessageTemplate template = getTemplate(informForm); MessageTemplate template = getTemplate(informForm);
template.setAudience(new MessageTemplate.Audience(informForm.getCid())); String[] split;
String cid = informForm.getCid();
if (cid.contains(",")) {
split = cid.split(",");
} else {
split = new String[]{cid};
}
template.setAudience(new MessageTemplate.Audience(split));
template.setGroup_name("toSingleAlias"); template.setGroup_name("toSingleAlias");
Map<String, Object> map = convertBeanToMap(informForm.getDevice(), false, 1, template); Map<String, Object> map = convertBeanToMap(informForm.getDevice(), false, 1, template);
//请求url //请求url
...@@ -391,7 +397,14 @@ public class GeTuiService { ...@@ -391,7 +397,14 @@ public class GeTuiService {
return CommonResult.failed(); return CommonResult.failed();
} }
MessageTemplate template = getTemplate(informForm); MessageTemplate template = getTemplate(informForm);
template.setAudience(new MessageTemplate.Audience(informForm.getCid())); String[] split;
String cid = informForm.getCid();
if (cid.contains(",")) {
split = cid.split(",");
} else {
split = new String[]{cid};
}
template.setAudience(new MessageTemplate.Audience(split));
template.setGroup_name("toSingleCid"); template.setGroup_name("toSingleCid");
Map<String, Object> map = convertBeanToMap(informForm.getDevice(), false, 0, template); Map<String, Object> map = convertBeanToMap(informForm.getDevice(), false, 0, template);
//请求url //请求url
......
...@@ -2,20 +2,18 @@ package com.weface.controller; ...@@ -2,20 +2,18 @@ package com.weface.controller;
import com.weface.code.CommonResult; import com.weface.code.CommonResult;
import com.weface.common.validator.ValidatorParam; import com.weface.common.validator.ValidatorParam;
import com.weface.common.validator.ValidatorUtils;
import com.weface.component.GeTuiService; import com.weface.component.GeTuiService;
import com.weface.dto.InformForm; import com.weface.dto.InformForm;
import com.weface.dto.MsgDTO; import com.weface.dto.MsgDTO;
import com.weface.dto.PushDTO; import com.weface.dto.PushDTO;
import com.weface.service.PushService; import com.weface.service.PushService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.validation.groups.Default;
/** /**
* @author Administrator * @author Administrator
*/ */
...@@ -40,12 +38,14 @@ public class PushController { ...@@ -40,12 +38,14 @@ public class PushController {
} }
@PostMapping("/all") @PostMapping("/all")
public CommonResult pushAll(@Validated({Default.class}) InformForm informForm) { public CommonResult pushAll(InformForm informForm) {
ValidatorUtils.validateEntity(informForm, InformForm.PushValid.class);
return geTuiService.listPush(informForm); return geTuiService.listPush(informForm);
} }
@PostMapping("/single/alias") @PostMapping("/single/alias")
public CommonResult pushSingleAlias(@Validated({Default.class}) InformForm informForm) { public CommonResult pushSingleAlias(@RequestBody InformForm informForm) {
ValidatorUtils.validateEntity(informForm, InformForm.PushValid.class);
CommonResult commonResult = ValidatorParam.validPushSingleAlias(informForm); CommonResult commonResult = ValidatorParam.validPushSingleAlias(informForm);
if (commonResult != null) { if (commonResult != null) {
return commonResult; return commonResult;
...@@ -54,7 +54,8 @@ public class PushController { ...@@ -54,7 +54,8 @@ public class PushController {
} }
@PostMapping("/single/cid") @PostMapping("/single/cid")
public CommonResult pushSingleCid(@Validated({Default.class}) InformForm informForm) { public CommonResult pushSingleCid(@RequestBody InformForm informForm) {
ValidatorUtils.validateEntity(informForm, InformForm.PushValid.class);
CommonResult commonResult = ValidatorParam.validPushSingleAlias(informForm); CommonResult commonResult = ValidatorParam.validPushSingleAlias(informForm);
if (commonResult != null) { if (commonResult != null) {
return commonResult; return commonResult;
......
...@@ -10,13 +10,13 @@ import javax.validation.constraints.NotBlank; ...@@ -10,13 +10,13 @@ import javax.validation.constraints.NotBlank;
@Data @Data
public class InformForm { public class InformForm {
//标题 //标题
@NotBlank @NotBlank(message = "标题不能为空",groups = {PushValid.class})
private String title; private String title;
//内容 //内容
@NotBlank @NotBlank(message = "内容不能为空",groups = {PushValid.class})
private String body; private String body;
//跳转url //跳转url
@NotBlank @NotBlank(message = "url不能为空",groups = {PushValid.class})
private String url; private String url;
//推送类型 0:h5 1:原生 //推送类型 0:h5 1:原生
private Integer pushType; private Integer pushType;
...@@ -27,17 +27,21 @@ public class InformForm { ...@@ -27,17 +27,21 @@ public class InformForm {
//是否需要登录 //是否需要登录
private String needLogin; private String needLogin;
//请求应用名称首字母小写 例:看看生活->kksh //请求应用名称首字母小写 例:看看生活->kksh
@NotBlank @NotBlank(message = "应用名称不能为空",groups = {PushValid.class})
private String equipmentType; private String equipmentType;
//推送设备 4 android 1: ios //推送设备 4 android 1: ios
private Integer device; private Integer device;
//定速推送,例如100,个推控制下发速度在100条/秒左右,0表示不限速 //定速推送,例如100,个推控制下发速度在100条/秒左右,0表示不限速
private Integer speed; private Integer speed;
//推送目标 //推送目标
private String[] cid; private String cid;
//推送手机号 //推送手机号
private String phone; private String phone;
//推送模板 //推送模板
private Integer messageTemplate; private Integer messageTemplate;
public interface PushValid{
}
} }
...@@ -41,11 +41,7 @@ public class PushLogServiceImpl extends ServiceImpl<PushLogDao, PushLogEntity> i ...@@ -41,11 +41,7 @@ public class PushLogServiceImpl extends ServiceImpl<PushLogDao, PushLogEntity> i
DES des = DES.getInstanceDes(); DES des = DES.getInstanceDes();
pushLogEntity.setPhone(des.encrypt(informForm.getPhone())); pushLogEntity.setPhone(des.encrypt(informForm.getPhone()));
pushLogEntity.setMessageTemplate(informForm.getMessageTemplate()); pushLogEntity.setMessageTemplate(informForm.getMessageTemplate());
StringBuilder sb = new StringBuilder(); pushLogEntity.setPushTarget(informForm.getCid());
for (String target : informForm.getCid()) {
sb.append(target).append(",");
}
pushLogEntity.setPushTarget(sb.toString());
pushLogEntity.setPushContent(informForm.getBody()); pushLogEntity.setPushContent(informForm.getBody());
pushLogEntity.setArriveStatus(1001); pushLogEntity.setArriveStatus(1001);
pushLogEntity.setUpdateTime(new Date()); pushLogEntity.setUpdateTime(new Date());
......
...@@ -104,20 +104,27 @@ public class UserTagsTask { ...@@ -104,20 +104,27 @@ public class UserTagsTask {
*/ */
@Scheduled(cron = "0 0 3 * * ?") @Scheduled(cron = "0 0 3 * * ?")
public void updateRedisHashKey() { public void updateRedisHashKey() {
HashSet<Object> hashSet = new HashSet<>(); try {
Set<Object> keys = RedisUtil.HashOps.hKeys(Constant.PUSH_TASK_INFO); log.error("开始更新任务缓存");
for (Object key : keys) { HashSet<Object> hashSet = new HashSet<>();
Object hashValue = RedisUtil.HashOps.hGet(Constant.PUSH_TASK_INFO, key.toString()); Set<Object> keys = RedisUtil.HashOps.hKeys(Constant.PUSH_TASK_INFO);
if (hashValue != null) { for (Object key : keys) {
RedisExpireData redisData = JSONUtil.toBean(hashValue.toString(), RedisExpireData.class); Object hashValue = RedisUtil.HashOps.hGet(Constant.PUSH_TASK_INFO, key.toString());
Object obj = redisData.getStoreData(); log.error("缓存任务信息:{}", hashValue);
if (obj == null) { if (hashValue != null) {
hashSet.add(key); RedisExpireData redisData = JSONUtil.toBean(hashValue.toString(), RedisExpireData.class);
Object obj = redisData.getStoreData();
if (obj == null) {
hashSet.add(key);
}
} }
} }
} if (!hashSet.isEmpty()) {
if (!hashSet.isEmpty()) { RedisUtil.HashOps.hDelete(Constant.PUSH_TASK_INFO, hashSet.toArray());
RedisUtil.HashOps.hDelete(Constant.PUSH_TASK_INFO, hashSet.toArray()); }
} catch (Exception e) {
log.error("更新任务缓存失败:{}", e.getMessage());
e.printStackTrace();
} }
} }
......
...@@ -6,10 +6,12 @@ import cn.hutool.json.JSONObject; ...@@ -6,10 +6,12 @@ import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.weface.code.CommonResult; import com.weface.code.CommonResult;
import com.weface.common.utils.CommonUtil;
import com.weface.common.utils.RedisUtil; import com.weface.common.utils.RedisUtil;
import com.weface.common.utils.SnowIdUtil; import com.weface.common.utils.SnowIdUtil;
import com.weface.component.GeTuiService; import com.weface.component.GeTuiService;
import com.weface.component.MenuService; import com.weface.component.MenuService;
import com.weface.config.SignValidateFilter;
import com.weface.dto.InformForm; import com.weface.dto.InformForm;
import com.weface.entity.MenuTagsEntity; import com.weface.entity.MenuTagsEntity;
import com.weface.entity.UserMenusEntity; import com.weface.entity.UserMenusEntity;
...@@ -347,8 +349,7 @@ class PushMessageApplicationTests { ...@@ -347,8 +349,7 @@ class PushMessageApplicationTests {
informForm.setClassTitle("我的金币"); informForm.setClassTitle("我的金币");
informForm.setNeedLogin("1"); informForm.setNeedLogin("1");
informForm.setEquipmentType("kksh"); informForm.setEquipmentType("kksh");
String[] strings = {"kksh_59354"}; informForm.setCid("kksh_59354");
informForm.setCid(strings);
CommonResult commonResult = geTuiService.pushSingleAlias(informForm); CommonResult commonResult = geTuiService.pushSingleAlias(informForm);
System.out.println(commonResult); System.out.println(commonResult);
} }
...@@ -367,4 +368,24 @@ class PushMessageApplicationTests { ...@@ -367,4 +368,24 @@ class PushMessageApplicationTests {
CommonResult commonResult = geTuiService.listPush(informForm); CommonResult commonResult = geTuiService.listPush(informForm);
System.out.println(commonResult); System.out.println(commonResult);
} }
@Test
public void testSign() {
// d9c57eada1389691d86ff4d62787d3cc
Map<String, Object> map = new HashMap<>();
map.put("title", "花费充值");
map.put("body", "尊敬的用户您好,您的户");
map.put("url", "https://docs.getui.com/getui/mobile/vendor/report/");
map.put("pushType", "0");
map.put("equipmentType", "kksh");
map.put("cid", "kksh_59354");
map.put("messageTemplate", "1");
map.put("phone", "15538250098");
long l = System.currentTimeMillis();
System.out.println(l);
map.put("timestamp", l);
String s = CommonUtil.apiParamSign(map, SignValidateFilter.SECRET_KEY);
System.out.println(s);
}
} }
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