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

1.签名信息配置

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