Commit 72f05dd5 authored by 以墨为白's avatar 以墨为白 🎧

APPKEY

parent 2250347a
...@@ -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.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;
......
...@@ -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;
......
...@@ -122,7 +122,7 @@ public class SignatureVerificationFilter extends OncePerRequestFilter { ...@@ -122,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 {
......
...@@ -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()));
}
} }
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