Commit 744dd937 authored by 夏敏伟's avatar 夏敏伟

Merge branch 'master' of http://192.168.168.218/wcyuee/szpt

parents 698d67ae 14ea6406
...@@ -21,6 +21,7 @@ import org.springframework.web.servlet.NoHandlerFoundException; ...@@ -21,6 +21,7 @@ import org.springframework.web.servlet.NoHandlerFoundException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.validation.ConstraintViolationException; import javax.validation.ConstraintViolationException;
import java.sql.SQLIntegrityConstraintViolationException;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -133,6 +134,17 @@ public class GlobalExceptionHandler { ...@@ -133,6 +134,17 @@ public class GlobalExceptionHandler {
state.setMessage(e.getCause().getMessage()); state.setMessage(e.getCause().getMessage());
return new HttpResult<>(state); return new HttpResult<>(state);
} }
//违反唯一约束
@ResponseBody
@ExceptionHandler({SQLIntegrityConstraintViolationException.class})
public HttpResult<HttpResultState> DuplicateKeyExceptionHandler(SQLIntegrityConstraintViolationException e) {
logger.warn(e.getMessage());
HttpResultState state = HttpResultState.DUPLICATED_KEY;
state.setMessage(e.getCause().getMessage());
return new HttpResult<>(state);
}
//endregion //endregion
...@@ -143,4 +155,6 @@ public class GlobalExceptionHandler { ...@@ -143,4 +155,6 @@ public class GlobalExceptionHandler {
state.setMessage(e.getMessage()); state.setMessage(e.getMessage());
return new HttpResult<>(state); return new HttpResult<>(state);
} }
} }
...@@ -32,4 +32,10 @@ public class AppStoreController { ...@@ -32,4 +32,10 @@ public class AppStoreController {
public Integer insertAppStore(@RequestBody @Valid AppStoreDTO appStoreDTO) { public Integer insertAppStore(@RequestBody @Valid AppStoreDTO appStoreDTO) {
return appStoreService.insertAppStore(appStoreDTO); return appStoreService.insertAppStore(appStoreDTO);
} }
@ApiOperation(value = "更新appKey", notes = "更新appKey")
@PostMapping("/updateAppIdSecret")
public Integer updateAppStore(@RequestBody @Valid AppStoreDTO appStoreDTO) {
return appStoreService.updateAppStore(appStoreDTO);
}
} }
package com.zksy.szpt.controller; package com.zksy.szpt.controller;
import com.zksy.szpt.domain.dto.CommonDelDTO; import com.zksy.szpt.domain.dto.*;
import com.zksy.szpt.domain.dto.XxShxxyDTO;
import com.zksy.szpt.domain.dto.XxShxxyDwDTO;
import com.zksy.szpt.domain.dto.XxYjrwDTO;
import com.zksy.szpt.service.XxShxxyDwService;
import com.zksy.szpt.service.XxShxxyService; import com.zksy.szpt.service.XxShxxyService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -36,9 +32,9 @@ public class XxShxxyController { ...@@ -36,9 +32,9 @@ public class XxShxxyController {
return service.update(dto); return service.update(dto);
} }
@ApiOperation(value = "删除社会信息员数据") @ApiOperation(value = "根据社会信息员ID删除社会信息员数据")
@PostMapping("/delete") @PostMapping("/delete")
public Integer delete(@RequestBody @Validated CommonDelDTO dto) { public Integer delete(@RequestBody @Validated CommonDelParamDTO dto) {
return service.delete(dto); return service.delete(dto);
} }
......
package com.zksy.szpt.controller; package com.zksy.szpt.controller;
import com.zksy.szpt.domain.dto.CommonDelDTO; import com.zksy.szpt.domain.dto.CommonDelParamDTO;
import com.zksy.szpt.domain.dto.XxShxxyDwDTO; import com.zksy.szpt.domain.dto.XxShxxyDwDTO;
import com.zksy.szpt.service.XxShxxyDwService; import com.zksy.szpt.service.XxShxxyDwService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -32,9 +32,9 @@ public class XxShxxyDwController { ...@@ -32,9 +32,9 @@ public class XxShxxyDwController {
return service.update(dto); return service.update(dto);
} }
@ApiOperation(value = "删除社会信息员队伍数据") @ApiOperation(value = "根据信息员队伍ID删除社会信息员队伍数据")
@PostMapping("/delete") @PostMapping("/delete")
public Integer delete(@RequestBody @Validated CommonDelDTO dto) { public Integer delete(@RequestBody @Validated CommonDelParamDTO dto) {
return service.delete(dto); return service.delete(dto);
} }
......
package com.zksy.szpt.controller; package com.zksy.szpt.controller;
import com.zksy.szpt.domain.dto.CommonDelDTO; import com.zksy.szpt.domain.dto.CommonDelParamDTO;
import com.zksy.szpt.domain.dto.XxYjdwdmDTO; import com.zksy.szpt.domain.dto.XxYjdwdmDTO;
import com.zksy.szpt.service.XxYjdwdmService; import com.zksy.szpt.service.XxYjdwdmService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -31,9 +31,9 @@ public class XxYjdwdmController { ...@@ -31,9 +31,9 @@ public class XxYjdwdmController {
return service.update(dto); return service.update(dto);
} }
@ApiOperation(value = "删除义警队伍数据") @ApiOperation(value = "根据义警队伍代码ID删除义警队伍数据")
@PostMapping("/delete") @PostMapping("/delete")
public Integer delete(@RequestBody @Validated CommonDelDTO dto) { public Integer delete(@RequestBody @Validated CommonDelParamDTO dto) {
return service.delete(dto); return service.delete(dto);
} }
......
package com.zksy.szpt.controller; package com.zksy.szpt.controller;
import com.zksy.szpt.domain.dto.CommonDelDTO; import com.zksy.szpt.domain.dto.CommonDelParamDTO;
import com.zksy.szpt.domain.dto.XxYjrwDTO; import com.zksy.szpt.domain.dto.XxYjrwDTO;
import com.zksy.szpt.service.XxYjrwService; import com.zksy.szpt.service.XxYjrwService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -31,9 +31,9 @@ public class XxYjrwController { ...@@ -31,9 +31,9 @@ public class XxYjrwController {
return service.update(dto); return service.update(dto);
} }
@ApiOperation(value = "删除义警任务信息数据") @ApiOperation(value = "根据任务ID删除义警任务信息数据")
@PostMapping("/delete") @PostMapping("/delete")
public Integer delete(@RequestBody @Validated CommonDelDTO dto) { public Integer delete(@RequestBody @Validated CommonDelParamDTO dto) {
return service.delete(dto); return service.delete(dto);
} }
......
package com.zksy.szpt.controller; package com.zksy.szpt.controller;
import com.zksy.szpt.domain.dto.CommonDelDTO; import com.zksy.szpt.domain.dto.CommonDelParamDTO;
import com.zksy.szpt.domain.dto.XxZhjfbgDTO; import com.zksy.szpt.domain.dto.XxZhjfbgDTO;
import com.zksy.szpt.service.XxZhjfbgService; import com.zksy.szpt.service.XxZhjfbgService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -32,9 +32,9 @@ public class XxZhjfbgController { ...@@ -32,9 +32,9 @@ public class XxZhjfbgController {
} }
@ApiOperation(value = "删除账户积分变更数据") @ApiOperation(value = "根据兑换ID删除账户积分变更数据")
@PostMapping("/delete") @PostMapping("/delete")
public Integer delete(@RequestBody @Validated CommonDelDTO dto) { public Integer delete(@RequestBody @Validated CommonDelParamDTO dto) {
return service.delete(dto); return service.delete(dto);
} }
......
...@@ -31,9 +31,9 @@ public class XxZhxxController { ...@@ -31,9 +31,9 @@ public class XxZhxxController {
} }
@ApiOperation(value = "删除账号信息数据") @ApiOperation(value = "根据账户ID删除账号信息数据")
@PostMapping("/delete") @PostMapping("/delete")
public Integer delete(@RequestBody @Validated CommonDelDTO dto) { public Integer delete(@RequestBody @Validated CommonDelParamDTO dto) {
return service.delete(dto); return service.delete(dto);
} }
......
package com.zksy.szpt.domain.dto; package com.zksy.szpt.domain.dto;
import javax.validation.constraints.NotBlank;
public class AppStoreDTO { public class AppStoreDTO {
private Long id; private Long id;
@NotBlank
private String appKey; private String appKey;
@NotBlank
private String appSecret; private String appSecret;
private String deptCode;
public String getDeptCode() {
return deptCode;
}
public void setDeptCode(String deptCode) {
this.deptCode = deptCode;
}
public Long getId() { public Long getId() {
return id; return id;
......
package com.zksy.szpt.domain.dto;
import javax.validation.constraints.NotEmpty;
import java.util.List;
public class CommonDelParamDTO {
/**
* 账户ID
*/
@NotEmpty(message = "ID不能为空")
private List<String> ids;
public @NotEmpty(message = "ID不能为空") List<String> getIds() {
return ids;
}
public void setIds(@NotEmpty(message = "ID不能为空") List<String> ids) {
this.ids = ids;
}
}
\ No newline at end of file
...@@ -14,6 +14,16 @@ public class AppStore { ...@@ -14,6 +14,16 @@ public class AppStore {
@TableField(fill = FieldFill.INSERT) @TableField(fill = FieldFill.INSERT)
private Date createTime; private Date createTime;
private String deptCode; private String deptCode;
@TableField(fill = FieldFill.UPDATE)
private Date updateTime;
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public Long getId() { public Long getId() {
return id; return id;
......
...@@ -148,7 +148,7 @@ public class XxYjrw { ...@@ -148,7 +148,7 @@ public class XxYjrw {
* 更新时间 * 更新时间
*/ */
@TableField(fill = FieldFill.INSERT_UPDATE) @TableField(fill = FieldFill.UPDATE)
private Date gxsj; private Date gxsj;
/** /**
...@@ -379,4 +379,6 @@ public class XxYjrw { ...@@ -379,4 +379,6 @@ public class XxYjrw {
public void setPictureUrls(String pictureUrls) { public void setPictureUrls(String pictureUrls) {
this.pictureUrls = pictureUrls == null ? null : pictureUrls.trim(); this.pictureUrls = pictureUrls == null ? null : pictureUrls.trim();
} }
} }
\ No newline at end of file
...@@ -11,6 +11,7 @@ import com.zksy.szpt.domain.HttpResultState; ...@@ -11,6 +11,7 @@ import com.zksy.szpt.domain.HttpResultState;
import com.zksy.szpt.domain.po.AppStore; import com.zksy.szpt.domain.po.AppStore;
import com.zksy.szpt.service.AppStoreService; import com.zksy.szpt.service.AppStoreService;
import com.zksy.szpt.util.EncryptUtil; import com.zksy.szpt.util.EncryptUtil;
import com.zksy.szpt.util.RedisKeyValidator;
import com.zksy.szpt.util.SignatureUtil; import com.zksy.szpt.util.SignatureUtil;
import com.zksy.szpt.util.UserContextHolder; import com.zksy.szpt.util.UserContextHolder;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -83,6 +84,16 @@ public class SignatureVerificationFilter extends OncePerRequestFilter { ...@@ -83,6 +84,16 @@ public class SignatureVerificationFilter extends OncePerRequestFilter {
return false; return false;
} }
// 验证nonce和timestamp合法性
if (!RedisKeyValidator.isValidString(nonce)) {
this.write(response, "不是合法的由数字和字母以及下划线组成的nonce:" + nonce);
return false;
}
if (!RedisKeyValidator.isValidTimestamp(timestampStr)) {
this.write(response, "不是合法的十位秒级时间戳timestamp:" + timestampStr);
return false;
}
// timestamp 10分钟内有效 // timestamp 10分钟内有效
long timestamp = Long.parseLong(timestampStr); long timestamp = Long.parseLong(timestampStr);
long currentTimestamp = System.currentTimeMillis() / 1000; long currentTimestamp = System.currentTimeMillis() / 1000;
...@@ -111,7 +122,7 @@ public class SignatureVerificationFilter extends OncePerRequestFilter { ...@@ -111,7 +122,7 @@ public class SignatureVerificationFilter extends OncePerRequestFilter {
Map<String, Object> objectMap = objectMapper.readValue(body, Map.class); Map<String, Object> objectMap = objectMapper.readValue(body, Map.class);
//验证单位 //验证单位
if (objectMap.get("deptCode") != null && !objectMap.get("sjgsdwdm").toString().startsWith(appStore.getDeptCode().replaceAll("0+$", ""))) { if (objectMap.get("sjgsdwdm") != null && !objectMap.get("sjgsdwdm").toString().startsWith(appStore.getDeptCode().replaceAll("0+$", ""))) {
write(response, "AppId和传入的单位不匹配,appId:" + appId + ",deptCode:" + objectMap.get("deptCode")); write(response, "AppId和传入的单位不匹配,appId:" + appId + ",deptCode:" + objectMap.get("deptCode"));
return false; return false;
} }
......
...@@ -13,6 +13,7 @@ import java.util.List; ...@@ -13,6 +13,7 @@ import java.util.List;
/** /**
* 自动填充 create_time, update_time 字段 * 自动填充 create_time, update_time 字段
* 该类策略如下:有值则不填充,无值则填充写入值,
*/ */
@Component @Component
public class SzptMetaObjectHandler implements MetaObjectHandler { public class SzptMetaObjectHandler implements MetaObjectHandler {
...@@ -67,7 +68,7 @@ public class SzptMetaObjectHandler implements MetaObjectHandler { ...@@ -67,7 +68,7 @@ public class SzptMetaObjectHandler implements MetaObjectHandler {
StrictFill.of("update_ip", String.class, currentUserInfo.getIp()) StrictFill.of("update_ip", String.class, currentUserInfo.getIp())
// StrictFill.of("del_flag", Integer.class,0) // StrictFill.of("del_flag", Integer.class,0)
); );
this.strictInsertFill(findTableInfo(metaObject), metaObject, fields); this.strictUpdateFill(findTableInfo(metaObject), metaObject, fields);
// this.strictInsertFill(metaObject, "updateTime", Date.class, new Date()); // this.strictInsertFill(metaObject, "updateTime", Date.class, new Date());
} }
} }
...@@ -41,4 +41,9 @@ public class AppStoreService { ...@@ -41,4 +41,9 @@ public class AppStoreService {
} }
return null; return null;
} }
public Integer updateAppStore(AppStoreDTO appStoreDTO) {
AppStore appStore = BeanMapperUtil.map(appStoreDTO, AppStore.class);
return appStoreMapper.update(appStore, new LambdaQueryWrapper<AppStore>().eq(AppStore::getAppKey, appStore.getAppKey()));
}
} }
...@@ -2,7 +2,7 @@ package com.zksy.szpt.service; ...@@ -2,7 +2,7 @@ package com.zksy.szpt.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.zksy.szpt.domain.dto.CommonDelDTO; import com.zksy.szpt.domain.dto.CommonDelParamDTO;
import com.zksy.szpt.domain.dto.XxShxxyDwDTO; import com.zksy.szpt.domain.dto.XxShxxyDwDTO;
import com.zksy.szpt.domain.po.XxShxxyDw; import com.zksy.szpt.domain.po.XxShxxyDw;
import com.zksy.szpt.mapper.XxShxxyDwMapper; import com.zksy.szpt.mapper.XxShxxyDwMapper;
...@@ -31,7 +31,7 @@ public class XxShxxyDwService { ...@@ -31,7 +31,7 @@ public class XxShxxyDwService {
} }
public Integer delete(CommonDelDTO dto) { public Integer delete(CommonDelParamDTO dto) {
LambdaQueryWrapper<XxShxxyDw> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<XxShxxyDw> wrapper = new LambdaQueryWrapper<>();
wrapper.in(XxShxxyDw::getId, dto.getIds()); wrapper.in(XxShxxyDw::getId, dto.getIds());
return xxShxxyDwMapper.delete(wrapper); return xxShxxyDwMapper.delete(wrapper);
......
...@@ -2,7 +2,7 @@ package com.zksy.szpt.service; ...@@ -2,7 +2,7 @@ package com.zksy.szpt.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.zksy.szpt.domain.dto.CommonDelDTO; import com.zksy.szpt.domain.dto.CommonDelParamDTO;
import com.zksy.szpt.domain.dto.XxShxxyDTO; import com.zksy.szpt.domain.dto.XxShxxyDTO;
import com.zksy.szpt.domain.po.XxShxxy; import com.zksy.szpt.domain.po.XxShxxy;
import com.zksy.szpt.mapper.XxShxxyMapper; import com.zksy.szpt.mapper.XxShxxyMapper;
...@@ -31,7 +31,7 @@ public class XxShxxyService { ...@@ -31,7 +31,7 @@ public class XxShxxyService {
} }
public Integer delete(CommonDelDTO dto ) { public Integer delete(CommonDelParamDTO dto ) {
LambdaQueryWrapper<XxShxxy> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<XxShxxy> wrapper = new LambdaQueryWrapper<>();
wrapper.in(XxShxxy::getXxyid, dto.getIds()); wrapper.in(XxShxxy::getXxyid, dto.getIds());
return xxShxxyMapper.delete(wrapper); return xxShxxyMapper.delete(wrapper);
......
...@@ -2,7 +2,7 @@ package com.zksy.szpt.service; ...@@ -2,7 +2,7 @@ package com.zksy.szpt.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.zksy.szpt.domain.dto.CommonDelDTO; import com.zksy.szpt.domain.dto.CommonDelParamDTO;
import com.zksy.szpt.domain.dto.XxYjdwdmDTO; import com.zksy.szpt.domain.dto.XxYjdwdmDTO;
import com.zksy.szpt.domain.po.XxYjdwdm; import com.zksy.szpt.domain.po.XxYjdwdm;
import com.zksy.szpt.mapper.XxYjdwdmMapper; import com.zksy.szpt.mapper.XxYjdwdmMapper;
...@@ -30,7 +30,7 @@ public class XxYjdwdmService { ...@@ -30,7 +30,7 @@ public class XxYjdwdmService {
} }
public Integer delete(CommonDelDTO dto) { public Integer delete(CommonDelParamDTO dto) {
LambdaQueryWrapper<XxYjdwdm> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<XxYjdwdm> wrapper = new LambdaQueryWrapper<>();
wrapper.in(XxYjdwdm::getId, dto.getIds()); wrapper.in(XxYjdwdm::getId, dto.getIds());
return xxYjdwdmMapper.delete(wrapper); return xxYjdwdmMapper.delete(wrapper);
......
...@@ -3,6 +3,7 @@ package com.zksy.szpt.service; ...@@ -3,6 +3,7 @@ package com.zksy.szpt.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.zksy.szpt.domain.dto.CommonDelDTO; import com.zksy.szpt.domain.dto.CommonDelDTO;
import com.zksy.szpt.domain.dto.CommonDelParamDTO;
import com.zksy.szpt.domain.dto.XxYjrwDTO; import com.zksy.szpt.domain.dto.XxYjrwDTO;
import com.zksy.szpt.domain.po.XxYjrw; import com.zksy.szpt.domain.po.XxYjrw;
import com.zksy.szpt.mapper.XxYjrwMapper; import com.zksy.szpt.mapper.XxYjrwMapper;
...@@ -30,7 +31,7 @@ public class XxYjrwService { ...@@ -30,7 +31,7 @@ public class XxYjrwService {
} }
public Integer delete(CommonDelDTO dto) { public Integer delete(CommonDelParamDTO dto) {
LambdaQueryWrapper<XxYjrw> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<XxYjrw> wrapper = new LambdaQueryWrapper<>();
wrapper.in(XxYjrw::getRwid, dto.getIds()); wrapper.in(XxYjrw::getRwid, dto.getIds());
return xxYjrwMapper.delete(wrapper); return xxYjrwMapper.delete(wrapper);
......
...@@ -2,13 +2,12 @@ package com.zksy.szpt.service; ...@@ -2,13 +2,12 @@ package com.zksy.szpt.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.zksy.szpt.domain.dto.CommonDelDTO; import com.zksy.szpt.domain.dto.CommonDelParamDTO;
import com.zksy.szpt.domain.dto.XxZhjfbgDTO; import com.zksy.szpt.domain.dto.XxZhjfbgDTO;
import com.zksy.szpt.domain.po.XxZhjfbg; import com.zksy.szpt.domain.po.XxZhjfbg;
import com.zksy.szpt.mapper.XxZhjfbgMapper; import com.zksy.szpt.mapper.XxZhjfbgMapper;
import com.zksy.szpt.util.BeanMapperUtil; import com.zksy.szpt.util.BeanMapperUtil;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -31,7 +30,7 @@ public class XxZhjfbgService { ...@@ -31,7 +30,7 @@ public class XxZhjfbgService {
} }
public Integer delete(CommonDelDTO dto) { public Integer delete(CommonDelParamDTO dto) {
LambdaQueryWrapper<XxZhjfbg> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<XxZhjfbg> wrapper = new LambdaQueryWrapper<>();
wrapper.in(XxZhjfbg::getDhid, dto.getIds()); wrapper.in(XxZhjfbg::getDhid, dto.getIds());
return xxZhjfbgMapper.delete(wrapper); return xxZhjfbgMapper.delete(wrapper);
......
...@@ -28,7 +28,7 @@ public class XxZhxxService { ...@@ -28,7 +28,7 @@ public class XxZhxxService {
} }
public Integer delete(CommonDelDTO dto) { public Integer delete(CommonDelParamDTO dto) {
LambdaQueryWrapper<XxZhxx> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<XxZhxx> wrapper = new LambdaQueryWrapper<>();
wrapper.in(XxZhxx::getZhid, dto.getIds()); wrapper.in(XxZhxx::getZhid, dto.getIds());
return xxZhxxMapper.delete(wrapper); return xxZhxxMapper.delete(wrapper);
......
package com.zksy.szpt.util;
import java.util.regex.Pattern;
public class RedisKeyValidator {
private static final String INVALID_CHARACTERS = "[\\x00\\x20\\x0A\\x0D\\x09]"; // 常见的无效字符
public static boolean isValidKey(String key) {
if (key == null || key.isEmpty()) {
return false;
}
return !key.matches(INVALID_CHARACTERS);
}
/**
*
* @param str
* @return
*/
public static boolean isValidString(String str) {
// 定义正则表达式,匹配字母、数字和下划线
String regex = "\\w+";
return Pattern.matches(regex, str);
}
/**
* 检查是否为有效的秒级时间戳
* @param timestamp
* @return
*/
public static boolean isValidTimestamp(String timestamp) {
// 检查是否为数字
if (!timestamp.matches("\\d+")) {
return false;
}
// 检查长度是否为10位(秒)
return timestamp.length() == 10;
}
}
...@@ -29,7 +29,7 @@ public class MainTest { ...@@ -29,7 +29,7 @@ public class MainTest {
String nonce = "2"; String nonce = "2";
String timestampStr = "21"; String timestampStr = "21";
String appId = "1872576325743943682"; String appId = "1872576325743943682";
String appSecret = "21"; String appSecret = "2";
@Resource @Resource
...@@ -41,19 +41,19 @@ public class MainTest { ...@@ -41,19 +41,19 @@ public class MainTest {
/** /**
* 任务完成情况 * 任务完成情况
*/ */
@Test // @Test
@DisplayName("任务完成情况") @DisplayName("任务完成情况")
public void xxRwwcqkTest() { public void xxRwwcqkTest() {
timestampStr = String.valueOf(System.currentTimeMillis() / 1000); timestampStr = String.valueOf(System.currentTimeMillis() / 1000);
nonce = String.valueOf(System.currentTimeMillis() / 1000); nonce = UUID.randomUUID().toString();
// String secretKey = this.appStoreService.getAppSecretByAppKey(appId); // String secretKey = this.appStoreService.getAppSecretByAppKey(appId);
appSecret = DigestUtil.md5Hex(appSecret); appSecret = DigestUtil.md5Hex(appSecret);
Assertions.assertNotNull(appId, "appId不存在");//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率 Assertions.assertNotNull(appId, "appId不存在");//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率
//请求参数 //请求参数
XxRwwcqkDTO xxRwwcqkDTO = new XxRwwcqkDTO(); XxRwwcqkDTO xxRwwcqkDTO = new XxRwwcqkDTO();
xxRwwcqkDTO.setRwid("123456"); xxRwwcqkDTO.setRwid("1234");
xxRwwcqkDTO.setXxyid("123456"); xxRwwcqkDTO.setXxyid("12345");
xxRwwcqkDTO.setShrid("123456"); xxRwwcqkDTO.setShrid("12345");
xxRwwcqkDTO.setWczt("1"); xxRwwcqkDTO.setWczt("1");
xxRwwcqkDTO.setBmzt("1"); xxRwwcqkDTO.setBmzt("1");
String json = null; String json = null;
...@@ -91,13 +91,13 @@ public class MainTest { ...@@ -91,13 +91,13 @@ public class MainTest {
@DisplayName("账户信息") @DisplayName("账户信息")
public void zhxxtest() { public void zhxxtest() {
timestampStr = String.valueOf(System.currentTimeMillis() / 1000); timestampStr = String.valueOf(System.currentTimeMillis() / 1000);
nonce = String.valueOf(System.currentTimeMillis() / 1000); nonce = UUID.randomUUID().toString();
String secretKey = this.appStoreService.getAppSecretByAppKey(appId); String secretKey = this.appStoreService.getAppSecretByAppKey(appId);
Assertions.assertNotNull(secretKey, "appId不存在");//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率 Assertions.assertNotNull(secretKey, "appId不存在");//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率
// Assertions.fail(secretKey); // Assertions.fail(secretKey);
//请求参数 //请求参数
XxZhxxDTO dto = new XxZhxxDTO(); XxZhxxDTO dto = new XxZhxxDTO();
dto.setZhid("123456"); dto.setZhid("1234");
dto.setXxyid("11"); dto.setXxyid("11");
dto.setZt("2"); dto.setZt("2");
dto.setClbz("2"); dto.setClbz("2");
...@@ -117,7 +117,7 @@ public class MainTest { ...@@ -117,7 +117,7 @@ public class MainTest {
.baseUrl("http://localhost:8086") .baseUrl("http://localhost:8086")
.defaultHeader("Content-Type", "application/json") .defaultHeader("Content-Type", "application/json")
.build(); .build();
String response = webClient.post().uri("/rest/xxZhxx/update") String response = webClient.post().uri("/rest/xxZhxx/add")
.header(SignatureUtil.APPID, appId) .header(SignatureUtil.APPID, appId)
.header(SignatureUtil.NONCE, nonce) .header(SignatureUtil.NONCE, nonce)
.header(SignatureUtil.TIMESTAMP, timestampStr) .header(SignatureUtil.TIMESTAMP, timestampStr)
...@@ -136,14 +136,14 @@ public class MainTest { ...@@ -136,14 +136,14 @@ public class MainTest {
@DisplayName("账户积分变更") @DisplayName("账户积分变更")
public void test1() { public void test1() {
timestampStr = String.valueOf(System.currentTimeMillis() / 1000); timestampStr = String.valueOf(System.currentTimeMillis() / 1000);
nonce = String.valueOf(System.currentTimeMillis() / 1000); nonce = UUID.randomUUID().toString();
String secretKey = this.appStoreService.getAppSecretByAppKey(appId); String secretKey = this.appStoreService.getAppSecretByAppKey(appId);
Assertions.assertNotNull(secretKey, "appId不存在");//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率 Assertions.assertNotNull(secretKey, "appId不存在");//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率
// Assertions.fail(secretKey); // Assertions.fail(secretKey);
//请求参数 //请求参数
XxZhjfbgDTO dto = new XxZhjfbgDTO(); XxZhjfbgDTO dto = new XxZhjfbgDTO();
// dto.setZhid("123456"); // dto.setZhid("1234");
dto.setDhid("123456"); dto.setDhid("1234");
dto.setQbid("2"); dto.setQbid("2");
dto.setBgsj(new Date()); dto.setBgsj(new Date());
String json = null; String json = null;
...@@ -162,7 +162,7 @@ public class MainTest { ...@@ -162,7 +162,7 @@ public class MainTest {
.baseUrl("http://localhost:8086") .baseUrl("http://localhost:8086")
.defaultHeader("Content-Type", "application/json") .defaultHeader("Content-Type", "application/json")
.build(); .build();
String response = webClient.post().uri("/rest/xxZhjfbg/update") String response = webClient.post().uri("/rest/xxZhjfbg/add")
.header(SignatureUtil.APPID, appId) .header(SignatureUtil.APPID, appId)
.header(SignatureUtil.NONCE, nonce) .header(SignatureUtil.NONCE, nonce)
.header(SignatureUtil.TIMESTAMP, timestampStr) .header(SignatureUtil.TIMESTAMP, timestampStr)
...@@ -225,13 +225,13 @@ public class MainTest { ...@@ -225,13 +225,13 @@ public class MainTest {
@DisplayName("义警任务") @DisplayName("义警任务")
public void test4() { public void test4() {
timestampStr = String.valueOf(System.currentTimeMillis() / 1000); timestampStr = String.valueOf(System.currentTimeMillis() / 1000);
nonce = String.valueOf(System.currentTimeMillis() / 1000); nonce = UUID.randomUUID().toString();
String secretKey = this.appStoreService.getAppSecretByAppKey(appId); String secretKey = this.appStoreService.getAppSecretByAppKey(appId);
Assertions.assertNotNull(secretKey, "appId不存在");//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率 Assertions.assertNotNull(secretKey, "appId不存在");//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率
// Assertions.fail(secretKey); // Assertions.fail(secretKey);
//请求参数 //请求参数
XxYjrwDTO dto = new XxYjrwDTO(); XxYjrwDTO dto = new XxYjrwDTO();
// dto.setZhid("123456"); // dto.setZhid("1234");
dto.setRwid("123456"); dto.setRwid("123456");
dto.setRwbt("1"); dto.setRwbt("1");
dto.setRwnr("11111"); dto.setRwnr("11111");
...@@ -273,15 +273,15 @@ public class MainTest { ...@@ -273,15 +273,15 @@ public class MainTest {
@DisplayName("义警队伍代码") @DisplayName("义警队伍代码")
public void test5() { public void test5() {
timestampStr = String.valueOf(System.currentTimeMillis() / 1000); timestampStr = String.valueOf(System.currentTimeMillis() / 1000);
nonce = String.valueOf(System.currentTimeMillis() / 1000); nonce = UUID.randomUUID().toString();
String secretKey = this.appStoreService.getAppSecretByAppKey(appId); String secretKey = this.appStoreService.getAppSecretByAppKey(appId);
Assertions.assertNotNull(secretKey, "appId不存在");//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率 Assertions.assertNotNull(secretKey, "appId不存在");//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率
// Assertions.fail(secretKey); // Assertions.fail(secretKey);
//请求参数 //请求参数
XxYjdwdmDTO dto = new XxYjdwdmDTO(); XxYjdwdmDTO dto = new XxYjdwdmDTO();
// dto.setZhid("123456"); // dto.setZhid("1234");
dto.setDwlx(Integer.valueOf(1)); dto.setDwlx(Integer.valueOf(1));
dto.setId("1"); dto.setId("1234");
dto.setMchid("11111"); dto.setMchid("11111");
dto.setZt("1"); dto.setZt("1");
dto.setYjdwmc("test"); dto.setYjdwmc("test");
...@@ -301,7 +301,7 @@ public class MainTest { ...@@ -301,7 +301,7 @@ public class MainTest {
.baseUrl("http://localhost:8086") .baseUrl("http://localhost:8086")
.defaultHeader("Content-Type", "application/json") .defaultHeader("Content-Type", "application/json")
.build(); .build();
String response = webClient.post().uri("/rest/xxYjdwdm/update") String response = webClient.post().uri("/rest/xxYjdwdm/add")
.header(SignatureUtil.APPID, appId) .header(SignatureUtil.APPID, appId)
.header(SignatureUtil.NONCE, nonce) .header(SignatureUtil.NONCE, nonce)
.header(SignatureUtil.TIMESTAMP, timestampStr) .header(SignatureUtil.TIMESTAMP, timestampStr)
...@@ -317,14 +317,14 @@ public class MainTest { ...@@ -317,14 +317,14 @@ public class MainTest {
@DisplayName("社会信息员队伍") @DisplayName("社会信息员队伍")
public void test6() { public void test6() {
timestampStr = String.valueOf(System.currentTimeMillis() / 1000); timestampStr = String.valueOf(System.currentTimeMillis() / 1000);
nonce = String.valueOf(System.currentTimeMillis() / 1000); nonce = UUID.randomUUID().toString();
String secretKey = this.appStoreService.getAppSecretByAppKey(appId); String secretKey = this.appStoreService.getAppSecretByAppKey(appId);
Assertions.assertNotNull(secretKey, "appId不存在");//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率 Assertions.assertNotNull(secretKey, "appId不存在");//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率
//请求参数 //请求参数
XxShxxyDwDTO dto = new XxShxxyDwDTO(); XxShxxyDwDTO dto = new XxShxxyDwDTO();
dto.setId("123456"); dto.setId("1234");
dto.setDwdm("123456"); dto.setDwdm("1234");
dto.setShxxyid("123456"); dto.setShxxyid("1234");
String json = null; String json = null;
try { try {
json = objectMapper.writeValueAsString(dto); json = objectMapper.writeValueAsString(dto);
...@@ -341,7 +341,7 @@ public class MainTest { ...@@ -341,7 +341,7 @@ public class MainTest {
.baseUrl("http://localhost:8086") .baseUrl("http://localhost:8086")
.defaultHeader("Content-Type", "application/json") .defaultHeader("Content-Type", "application/json")
.build(); .build();
String response = webClient.post().uri("/rest/xxShxxyDw/update") String response = webClient.post().uri("/rest/xxShxxyDw/add")
.header(SignatureUtil.APPID, appId) .header(SignatureUtil.APPID, appId)
.header(SignatureUtil.NONCE, nonce) .header(SignatureUtil.NONCE, nonce)
.header(SignatureUtil.TIMESTAMP, timestampStr) .header(SignatureUtil.TIMESTAMP, timestampStr)
...@@ -357,12 +357,12 @@ public class MainTest { ...@@ -357,12 +357,12 @@ public class MainTest {
@DisplayName("社会信息员") @DisplayName("社会信息员")
public void test7() { public void test7() {
timestampStr = String.valueOf(System.currentTimeMillis() / 1000); timestampStr = String.valueOf(System.currentTimeMillis() / 1000);
nonce = String.valueOf(System.currentTimeMillis() / 1000); nonce = UUID.randomUUID().toString();
String secretKey = this.appStoreService.getAppSecretByAppKey(appId); String secretKey = this.appStoreService.getAppSecretByAppKey(appId);
Assertions.assertNotNull(secretKey, "appId不存在");//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率 Assertions.assertNotNull(secretKey, "appId不存在");//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率
//请求参数 //请求参数
XxShxxyDTO dto = new XxShxxyDTO(); XxShxxyDTO dto = new XxShxxyDTO();
dto.setXxyid("123456"); dto.setXxyid("1234");
dto.setZt("1"); dto.setZt("1");
dto.setSbfszt("1"); dto.setSbfszt("1");
dto.setShrid("1"); dto.setShrid("1");
...@@ -382,7 +382,7 @@ public class MainTest { ...@@ -382,7 +382,7 @@ public class MainTest {
.baseUrl("http://localhost:8086") .baseUrl("http://localhost:8086")
.defaultHeader("Content-Type", "application/json") .defaultHeader("Content-Type", "application/json")
.build(); .build();
String response = webClient.post().uri("/rest/xxShxxy/update") String response = webClient.post().uri("/rest/xxShxxy/add")
.header(SignatureUtil.APPID, appId) .header(SignatureUtil.APPID, appId)
.header(SignatureUtil.NONCE, nonce) .header(SignatureUtil.NONCE, nonce)
.header(SignatureUtil.TIMESTAMP, timestampStr) .header(SignatureUtil.TIMESTAMP, timestampStr)
...@@ -399,15 +399,15 @@ public class MainTest { ...@@ -399,15 +399,15 @@ public class MainTest {
@DisplayName("删除服务") @DisplayName("删除服务")
public void testdelete() { public void testdelete() {
timestampStr = String.valueOf(System.currentTimeMillis() / 1000); timestampStr = String.valueOf(System.currentTimeMillis() / 1000);
nonce = String.valueOf(System.currentTimeMillis() / 1000); nonce = UUID.randomUUID().toString();
String secretKey = this.appStoreService.getAppSecretByAppKey(appId); String secretKey = this.appStoreService.getAppSecretByAppKey(appId);
Assertions.assertNotNull(secretKey, "appId不存在");//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率 Assertions.assertNotNull(secretKey, "appId不存在");//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率
//请求参数 //请求参数
String json = null; String json = null;
List<String> ids = new ArrayList<>(); List<String> ids = new ArrayList<>();
ids.add("1"); ids.add("1234");
ids.add("12345");
CommonDelDTO dto=new CommonDelDTO(); CommonDelParamDTO dto=new CommonDelParamDTO();
dto.setIds(ids); dto.setIds(ids);
try { try {
...@@ -430,10 +430,10 @@ public class MainTest { ...@@ -430,10 +430,10 @@ public class MainTest {
// String url="xxYjdwdm/delete"; // String url="xxYjdwdm/delete";
// String url="xxYjrw/delete"; // String url="xxYjrw/delete";
// //
String url="xxZhjfbg/delete"; // String url="xxZhjfbg/delete";
// //
// String url = "xxZhxx/delete"; String url = "xxZhxx/delete";
String response = webClient.post().uri("/rest/" + url) String response = webClient.post().uri("/rest/" + url)
.header(SignatureUtil.APPID, appId) .header(SignatureUtil.APPID, appId)
......
package com.zksy.szpt;
import cn.hutool.crypto.digest.DigestUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zksy.szpt.domain.dto.*;
import com.zksy.szpt.util.EncryptUtil;
import com.zksy.szpt.util.SignatureUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import javax.annotation.Resource;
@SpringBootTest()
public class TestAppStore {
String nonce = "2";
String timestampStr = "21";
String appId = "1872576325743943682";
String appSecret = "2";
@Resource
private ObjectMapper objectMapper;
/**
* 新增AppId
*/
@Test
@DisplayName("新增AppId")
public void addAppId() {
timestampStr = String.valueOf(System.currentTimeMillis() / 1000);
nonce = String.valueOf(System.currentTimeMillis() / 1000);
appSecret = DigestUtil.md5Hex(appSecret);
Assertions.assertNotNull(appId, "appId不存在");//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率
//请求参数
AppStoreDTO appStoreDTO = new AppStoreDTO();
appStoreDTO.setAppKey("us");
appStoreDTO.setAppSecret(DigestUtil.md5Hex("us"));
appStoreDTO.setDeptCode("123456");
String json = null;
try {
json = objectMapper.writeValueAsString(appStoreDTO);
} catch (JsonProcessingException e) {
Assertions.fail("json序列化失败");
}
//请求体加密
json = EncryptUtil.getInstance().AESEncode(json, appSecret);
//签名appId+nonce+timestampStr+aes(body)
String data = String.format("%s%s%s%s", appId, nonce, timestampStr, json);
String generatedSignature = DigestUtil.md5Hex(data);
//请求
WebClient webClient = WebClient.builder()
.baseUrl("http://localhost:8086")
.defaultHeader("Content-Type", "application/json")
.build();
String response = webClient.post().uri("/rest/appStore/insertAppStore")
.header(SignatureUtil.APPID, appId)
.header(SignatureUtil.NONCE, nonce)
.header(SignatureUtil.TIMESTAMP, timestampStr)
.header(SignatureUtil.SIGNATURE, generatedSignature)
.body(Mono.just(appStoreDTO), XxRwwcqkDTO.class)
.retrieve()
.bodyToMono(String.class)
.block();
System.out.println(response);
}
@Test
@DisplayName("更新AppId的密钥")
public void updateAppIdSecret() {
timestampStr = String.valueOf(System.currentTimeMillis() / 1000);
nonce = String.valueOf(System.currentTimeMillis() / 1000);
appSecret = DigestUtil.md5Hex(appSecret);
Assertions.assertNotNull(appId, "appId不存在");//断言appId存在,为空直接抛出异常不进行下一步测试,提高测试效率
//请求参数
AppStoreDTO appStoreDTO = new AppStoreDTO();
appStoreDTO.setAppKey("us");
appStoreDTO.setAppSecret(DigestUtil.md5Hex("us11"));
String json = null;
try {
json = objectMapper.writeValueAsString(appStoreDTO);
} catch (JsonProcessingException e) {
Assertions.fail("json序列化失败");
}
//请求体加密
json = EncryptUtil.getInstance().AESEncode(json, appSecret);
//签名appId+nonce+timestampStr+aes(body)
String data = String.format("%s%s%s%s", appId, nonce, timestampStr, json);
String generatedSignature = DigestUtil.md5Hex(data);
//请求
WebClient webClient = WebClient.builder()
.baseUrl("http://localhost:8086")
.defaultHeader("Content-Type", "application/json")
.build();
String response = webClient.post().uri("/rest/appStore/updateAppIdSecret")
.header(SignatureUtil.APPID, appId)
.header(SignatureUtil.NONCE, nonce)
.header(SignatureUtil.TIMESTAMP, timestampStr)
.header(SignatureUtil.SIGNATURE, generatedSignature)
.body(Mono.just(appStoreDTO), XxRwwcqkDTO.class)
.retrieve()
.bodyToMono(String.class)
.block();
System.out.println(response);
}
}
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